Skip to content

Commit ff2ed15

Browse files
committed
[MC] evaluateAsAbsolute requires MCValue::RefKind==0
In `.equ a, 3; .if a@plt`, a@plt does not evaluate to an absolute value (MCExpr::evaluateAsRelocatableImpl disables evaluation when the Kind != 0 at parse time). Similarly, when using MCTargetValue, evaluateAsAbsolute should return false when MCValue::RefKind==0. This allows us to remove `if (!Asm)` check from MipsMCExpr.cpp (%hi(0xdeadbeef) is not evaluated to a constant without RefKind) and make targets less error-prone.
1 parent 5e65b40 commit ff2ed15

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

llvm/lib/MC/MCExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
286286
}
287287

288288
bool IsRelocatable = evaluateAsRelocatableImpl(Value, Asm, Addrs, InSet);
289-
290-
// Record the current value.
291289
Res = Value.getConstant();
292-
293-
return IsRelocatable && Value.isAbsolute();
290+
// Value with RefKind (e.g. %hi(0xdeadbeef) in MIPS) is not considered
291+
// absolute (the value is unknown at parse time), even if it might be resolved
292+
// by evaluateFixup.
293+
return IsRelocatable && Value.isAbsolute() && Value.getRefKind() == 0;
294294
}
295295

296296
/// Helper method for \see EvaluateSymbolAdd().

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
131131

132132
bool MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
133133
const MCFixup *Fixup) const {
134-
if (!Asm)
135-
return false;
136134
// Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X))) special cases.
137135
if (isGpOff()) {
138136
const MCExpr *SubExpr =

0 commit comments

Comments
 (0)