Skip to content

Commit 27b6ba4

Browse files
committed
MC: Improve error reporting for equated symbols and undefined labels
Currently, the code path is likely only reachable with super edge-case scenario, but will be more reachable with the upcoming parseAssignmentExpression improvement to address a pile of hacks.
1 parent 73c4929 commit 27b6ba4

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

llvm/lib/MC/MCAssembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S,
415415
bool ReportError, uint64_t &Val) {
416416
if (!S.getFragment()) {
417417
if (ReportError)
418-
report_fatal_error("unable to evaluate offset to undefined symbol '" +
419-
S.getName() + "'");
418+
reportFatalUsageError("cannot evaluate undefined symbol '" + S.getName() +
419+
"'");
420420
return false;
421421
}
422422
Val = Asm.getFragmentOffset(*S.getFragment()) + S.getOffset();
@@ -431,8 +431,8 @@ static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S,
431431
// If SD is a variable, evaluate it.
432432
MCValue Target;
433433
if (!S.getVariableValue()->evaluateAsValue(Target, Asm))
434-
report_fatal_error("unable to evaluate offset for variable '" +
435-
S.getName() + "'");
434+
reportFatalUsageError("cannot evaluate equated symbol '" + S.getName() +
435+
"'");
436436

437437
uint64_t Offset = Target.getConstant();
438438

llvm/lib/MC/MCExpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
538538
// Allows aliases with zero offset.
539539
if (Res.getConstant() == 0 && (!A || !B))
540540
return true;
541+
} else {
542+
return false;
541543
}
542544
}
543545

llvm/test/MC/MachO/variable-errors.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: not --crash llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o %t.o 2> %t.err
1+
// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o %t.o 2> %t.err
22
// RUN: FileCheck < %t.err %s
33

44
.data
55
t0_a:
66
t0_x = t0_a - t0_b
7-
// CHECK: unable to evaluate offset to undefined symbol 't0_b'
7+
// CHECK: cannot evaluate undefined symbol 't0_b'
88
.long t0_x

0 commit comments

Comments
 (0)