Skip to content

Commit f239490

Browse files
authored
[BOLT][NFC] Define getExprValue helper (#91663)
Move out common code extracting the address of a MCExpr. To be reused in #91667. Test Plan: NFC
1 parent 8e3be5c commit f239490

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,19 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
851851
return IndirectBranchType::UNKNOWN;
852852
}
853853

854-
// RIP-relative addressing should be converted to symbol form by now
855-
// in processed instructions (but not in jump).
856-
if (DispExpr) {
854+
auto getExprValue = [&](const MCExpr *Expr) {
857855
const MCSymbol *TargetSym;
858856
uint64_t TargetOffset;
859-
std::tie(TargetSym, TargetOffset) = BC.MIB->getTargetSymbolInfo(DispExpr);
857+
std::tie(TargetSym, TargetOffset) = BC.MIB->getTargetSymbolInfo(Expr);
860858
ErrorOr<uint64_t> SymValueOrError = BC.getSymbolValue(*TargetSym);
861-
assert(SymValueOrError && "global symbol needs a value");
862-
ArrayStart = *SymValueOrError + TargetOffset;
859+
assert(SymValueOrError && "Global symbol needs a value");
860+
return *SymValueOrError + TargetOffset;
861+
};
862+
863+
// RIP-relative addressing should be converted to symbol form by now
864+
// in processed instructions (but not in jump).
865+
if (DispExpr) {
866+
ArrayStart = getExprValue(DispExpr);
863867
BaseRegNum = BC.MIB->getNoRegister();
864868
if (BC.isAArch64()) {
865869
ArrayStart &= ~0xFFFULL;

0 commit comments

Comments
 (0)