[BOLT][NFC] Resolved all clang-12 warnings for bolt

Summary:
clang-12 now compiles bolt without warnings.
Some warnings were fixed if possible while others were suppressed by
doing (void)variable for unused variable warnings or moving code inside
assert statements of LLVM_DEBUG blocks.

(cherry picked from FBD29469054)
This commit is contained in:
Joey Thaman 2021-06-29 12:11:56 -07:00 committed by Maksim Panchenko
parent 1de0746790
commit 4c12afc1f4
9 changed files with 25 additions and 11 deletions

View File

@ -1750,6 +1750,7 @@ BinaryContext::getSectionNameForAddress(uint64_t Address) const {
BinarySection &BinaryContext::registerSection(BinarySection *Section) {
auto Res = Sections.insert(Section);
(void)Res;
assert(Res.second && "can't register the same section twice.");
// Only register allocatable sections in the AddressToSection map.
@ -1787,6 +1788,7 @@ BinarySection &BinaryContext::registerOrUpdateSection(StringRef Name,
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: updating " << *Section << " -> ");
const bool Flag = Section->isAllocatable();
(void)Flag;
Section->update(Data, Size, Alignment, ELFType, ELFFlags);
LLVM_DEBUG(dbgs() << *Section << "\n");
// FIXME: Fix section flags/attributes for MachO.

View File

@ -3926,6 +3926,7 @@ bool BinaryFunction::replaceJumpTableEntryIn(BinaryBasicBlock *BB,
assert(JT && "No jump table structure for this indirect branch");
bool Patched = JT->replaceDestination(JTAddress, OldDest->getLabel(),
NewDest->getLabel());
(void)Patched;
assert(Patched && "Invalid entry to be replaced in jump table");
return true;
}

View File

@ -168,6 +168,7 @@ void DWARFRewriter::updateDebugInfo() {
uint64_t AttrOffset = 0;
Optional<DWARFFormValue> ValDwoName =
DIE.find(dwarf::DW_AT_GNU_dwo_name, &AttrOffset);
(void)ValDwoName;
assert(ValDwoName && "Skeleton CU doesn't have dwo_name.");
std::string ObjectName = getDWOName(Unit, &NameToIndexMap, DWOIdToName);
@ -176,6 +177,7 @@ void DWARFRewriter::updateDebugInfo() {
Optional<DWARFFormValue> ValCompDir =
DIE.find(dwarf::DW_AT_comp_dir, &AttrOffset);
(void)ValCompDir;
assert(ValCompDir && "DW_AT_comp_dir is not in Skeleton CU.");
if (!opts::DwoOutputPath.empty()) {
uint32_t NewOffset = StrWriter->addString(opts::DwoOutputPath.c_str());

View File

@ -228,6 +228,7 @@ AddressSectionBuffer DebugAddrWriter::finalize() {
switch (AddrSize) {
default:
assert(false && "Address Size is invalid.");
break;
case 4:
support::endian::write(AddressStream, static_cast<uint32_t>(Address),
support::little);

View File

@ -212,6 +212,7 @@ void runOnEachFunctionWithUniqueAllocId(
if (!BC.MIB->checkAllocatorExists(AllocId)) {
MCPlusBuilder::AllocatorIdTy Id =
BC.MIB->initializeNewAnnotationAllocator();
(void)Id;
assert(AllocId == Id && "unexpected allocator id created");
}
Pool.async(runBlock, BlockBegin, std::next(It), AllocId);
@ -224,6 +225,7 @@ void runOnEachFunctionWithUniqueAllocId(
if (!BC.MIB->checkAllocatorExists(AllocId)) {
MCPlusBuilder::AllocatorIdTy Id =
BC.MIB->initializeNewAnnotationAllocator();
(void)Id;
assert(AllocId == Id && "unexpected allocator id created");
}

View File

@ -785,6 +785,7 @@ private:
Block *BB2 = ChainPred->blocks()[Offset];
// Does the splitting break FT successors?
if (BB1->FallthroughSucc != nullptr) {
(void)BB2;
assert(BB1->FallthroughSucc == BB2 && "Fallthrough not preserved");
continue;
}
@ -850,8 +851,6 @@ private:
return MergedChain(BeginY, EndY, BeginX2, EndX2, BeginX1, EndX1);
case MergeTypeTy::X2_X1_Y:
return MergedChain(BeginX2, EndX2, BeginX1, EndX1, BeginY, EndY);
default:
llvm_unreachable("unexpected merge type");
}
}

View File

@ -1550,6 +1550,7 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
std::max<uint64_t>(TotalIndexBasedCandidates, 1))
<< "%\n";
(void)verifyProfile;
#ifndef NDEBUG
verifyProfile(BFs);
#endif

View File

@ -1303,6 +1303,7 @@ void ShrinkWrapping::moveSaveRestores() {
const FrameIndexEntry *FIESave = CSA.SaveFIEByReg[I];
const FrameIndexEntry *FIELoad = CSA.LoadFIEByReg[I];
(void)FIELoad;
assert(FIESave && FIELoad);
StackPointerTracking &SPT = Info.getStackPointerTracking();
const std::pair<int, int> SPFP = *SPT.getStateBefore(*BestPosSave);
@ -2003,6 +2004,7 @@ bool ShrinkWrapping::perform() {
processDeletions();
if (foldIdenticalSplitEdges()) {
const std::pair<unsigned, uint64_t> Stats = BF.eraseInvalidBBs();
(void)Stats;
LLVM_DEBUG(dbgs() << "Deleted " << Stats.first
<< " redundant split edge BBs (" << Stats.second
<< " bytes) for " << BF.getPrintName() << "\n");

View File

@ -1944,6 +1944,7 @@ bool RewriteInstance::analyzeRelocation(const RelocationRef &Rel,
truncateToSize(SymbolAddress + Addend - PCRelOffset, RelSize);
};
(void)verifyExtractedValue;
assert(verifyExtractedValue() && "mismatched extracted relocation value");
return true;
@ -2164,9 +2165,8 @@ void RewriteInstance::processLKBugTable() {
"Reading valid PC-relative offset for a __bug_table entry");
const int32_t SignedOffset = *Offset;
const uint64_t RefAddress = EntryAddress + SignedOffset;
BinaryFunction *ContainingBF =
BC->getBinaryFunctionContainingAddress(RefAddress);
assert(ContainingBF && "__bug_table entries should point to a function");
assert(BC->getBinaryFunctionContainingAddress(RefAddress) &&
"__bug_table entries should point to a function");
insertLKMarker(RefAddress, I, SignedOffset, true, "__bug_table");
}
@ -2205,9 +2205,11 @@ void RewriteInstance::processLKSMPLocks() {
void RewriteInstance::readDynamicRelocations(const SectionRef &Section) {
assert(BinarySection(*BC, Section).isAllocatable() && "allocatable expected");
StringRef SectionName = cantFail(Section.getName());
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: reading relocations for section "
<< SectionName << ":\n");
LLVM_DEBUG({
StringRef SectionName = cantFail(Section.getName());
dbgs() << "BOLT-DEBUG: reading relocations for section " << SectionName
<< ":\n";
});
for (const RelocationRef &Rel : Section.relocations()) {
uint64_t RType = Rel.getType();
@ -2243,9 +2245,11 @@ void RewriteInstance::readDynamicRelocations(const SectionRef &Section) {
}
void RewriteInstance::readRelocations(const SectionRef &Section) {
StringRef SectionName = cantFail(Section.getName());
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: reading relocations for section "
<< SectionName << ":\n");
LLVM_DEBUG({
StringRef SectionName = cantFail(Section.getName());
dbgs() << "BOLT-DEBUG: reading relocations for section " << SectionName
<< ":\n";
});
if (BinarySection(*BC, Section).isAllocatable()) {
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring runtime relocations\n");
return;