Skip to content

Commit

Permalink
[BOLT][NFC] Resolved all clang-12 warnings for bolt
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jthamanfb authored and maksfb committed Jun 29, 2021
1 parent 1de0746 commit 4c12afc
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions bolt/src/BinaryContext.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions bolt/src/BinaryFunction.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions bolt/src/DWARFRewriter.cpp
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions bolt/src/DebugData.cpp
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions bolt/src/ParallelUtilities.cpp
Expand Up @@ -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);
Expand All @@ -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");
}

Expand Down
3 changes: 1 addition & 2 deletions bolt/src/Passes/ExtTSPReorderAlgorithm.cpp
Expand Up @@ -785,6 +785,7 @@ class ExtTSP {
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;
}
Expand Down Expand Up @@ -850,8 +851,6 @@ class ExtTSP {
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");
}
}

Expand Down
1 change: 1 addition & 0 deletions bolt/src/Passes/IndirectCallPromotion.cpp
Expand Up @@ -1550,6 +1550,7 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
std::max<uint64_t>(TotalIndexBasedCandidates, 1))
<< "%\n";

(void)verifyProfile;
#ifndef NDEBUG
verifyProfile(BFs);
#endif
Expand Down
2 changes: 2 additions & 0 deletions bolt/src/Passes/ShrinkWrapping.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
22 changes: 13 additions & 9 deletions bolt/src/RewriteInstance.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4c12afc

Please sign in to comment.