Skip to content

Commit 777391a

Browse files
committed
MCFixup: Improve location accuracy and remove MCFixup::Loc
Remove the redundant MCFixup::Loc member and instead use MCExpr::Loc to determine the location for fixups. Previously, many target MCCodeEmitter would use the beginning of an instruction for fixup locations, which often resulted in inaccurate column information. ``` // RISCVMCCodeEmitter::getImmOpValue Fixups.push_back(MCFixup::create(0, Expr, FixupKind, MI.getLoc())); // X86MCCodeEmitter::emitImmediate Fixups.push_back(MCFixup::create(static_cast<uint32_t>(CB.size() - StartByte), Expr, FixupKind, Loc)); ``` While MCExpr::Loc generally provides more meaningful location data, tests should avoid over-relying on it. For instance, MCBinaryExpr's location refers to its operator, and for operands with sigils (like `$foo`), the location often omits the sigils. https://llvm-compile-time-tracker.com/compare.php?from=8740ff822d462844506134bb7c425e1778518b95&to=831a11f75d22d64982b13dba132d656ac8567612&stat=instructions%3Au I've also considered removing MCExpr::Loc (revert https://reviews.llvm.org/D28861), but we'd lose too much information. It's also difficult to carry location information to improve location tracking in target MCCodeEmitter. This change utilizes previous MCExpr::Loc improvement like 7e3e2e1 7b517cf
1 parent 833839b commit 777391a

37 files changed

+97
-94
lines changed

llvm/include/llvm/MC/MCFixup.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,13 @@ class MCFixup {
8181

8282
/// Consider bit fields if we need more flags.
8383

84-
/// The source location which gave rise to the fixup, if any.
85-
SMLoc Loc;
8684
public:
8785
static MCFixup create(uint32_t Offset, const MCExpr *Value,
8886
MCFixupKind Kind, SMLoc Loc = SMLoc()) {
8987
MCFixup FI;
9088
FI.Value = Value;
9189
FI.Offset = Offset;
9290
FI.Kind = Kind;
93-
FI.Loc = Loc;
9491
return FI;
9592
}
9693
static MCFixup create(uint32_t Offset, const MCExpr *Value, unsigned Kind,
@@ -128,7 +125,7 @@ class MCFixup {
128125
}
129126
}
130127

131-
SMLoc getLoc() const { return Loc; }
128+
SMLoc getLoc() const;
132129
};
133130

134131
namespace mc {

llvm/lib/MC/MCAssembler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,3 +1240,9 @@ LLVM_DUMP_METHOD void MCAssembler::dump() const{
12401240
OS << "\n]\n";
12411241
}
12421242
#endif
1243+
1244+
SMLoc MCFixup::getLoc() const {
1245+
if (auto *E = getValue())
1246+
return E->getLoc();
1247+
return {};
1248+
}

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6436,7 +6436,7 @@ bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
64366436
return true;
64376437

64386438
const auto *ExprVal =
6439-
MCSpecifierExpr::create(SubExprVal, Spec, getContext());
6439+
MCSpecifierExpr::create(SubExprVal, Spec, getContext(), S);
64406440
E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
64416441
Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E, *this));
64426442
return false;

llvm/test/MC/AArch64/coff-relocations-branch26.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ main:
6161
err:
6262
nop
6363
b .Lerr_target+4
64-
// ERR: [[#@LINE-1]]:5: error: cannot perform a PC-relative fixup with a non-zero symbol offset
64+
// ERR: [[#@LINE-1]]:19: error: cannot perform a PC-relative fixup with a non-zero symbol offset
6565

6666
.def .Lerr_target
6767
.scl 3

llvm/test/MC/AArch64/coff-relocations-diags.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// RUN: not llvm-mc -triple aarch64-win32 -filetype=obj %s -o /dev/null 2>&1 | FileCheck %s
22

33
adrp x0, :got:symbol
4-
// CHECK: [[#@LINE-1]]:3: error: relocation specifier :got: unsupported on COFF targets
4+
// CHECK: [[#@LINE-1]]:12: error: relocation specifier :got: unsupported on COFF targets
55
// CHECK-NEXT: adrp x0, :got:symbol
66
// CHECK-NEXT: ^
77

88
ldr x0, [x0, :got_lo12:symbol]
9-
// CHECK: [[#@LINE-1]]:3: error: relocation specifier :got_lo12: unsupported on COFF targets
9+
// CHECK: [[#@LINE-1]]:16: error: relocation specifier :got_lo12: unsupported on COFF targets
1010
// CHECK-NEXT: ldr x0, [x0, :got_lo12:symbol]
1111
// CHECK-NEXT: ^
1212

1313
adrp x0, :tlsdesc:symbol
14-
// CHECK: [[#@LINE-1]]:3: error: relocation specifier :tlsdesc: unsupported on COFF targets
14+
// CHECK: [[#@LINE-1]]:12: error: relocation specifier :tlsdesc: unsupported on COFF targets
1515
// CHECK-NEXT: adrp x0, :tlsdesc:symbol
1616
// CHECK-NEXT: ^
1717
add x0, x0, :tlsdesc_lo12:symbol

llvm/test/MC/AArch64/ilp32-diagnostics.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: FileCheck --check-prefix=ERROR %s --implicit-check-not=error: < %t2
44

55
.xword sym-.
6-
// ERROR: [[#@LINE-1]]:8: error: 8 byte PC relative data relocation is not supported in ILP32
6+
// ERROR: [[#@LINE-1]]:11: error: 8 byte PC relative data relocation is not supported in ILP32
77

88
.xword sym+16
99
// ERROR: [[#@LINE-1]]:[[#]]: error: 8 byte absolute data relocation is not supported in ILP32
@@ -15,7 +15,7 @@
1515
// ERROR: [[#@LINE-1]]:[[#]]: error: 8 byte absolute data relocation is not supported in ILP32
1616

1717
movz x7, #:abs_g3:some_label
18-
// ERROR: [[#@LINE-1]]:1: error: absolute MOV relocation is not supported in ILP32
18+
// ERROR: [[#@LINE-1]]:11: error: absolute MOV relocation is not supported in ILP32
1919
// ERROR: movz x7, #:abs_g3:some_label
2020

2121
movz x3, #:abs_g2:some_label
@@ -89,7 +89,7 @@ ldr x24, [x23, :gottprel_lo12:sym]
8989
// ERROR: [[#@LINE-1]]:[[#]]: error: 64-bit load/store relocation is not supported in ILP32
9090

9191
ldr x24, :got_auth:sym
92-
// ERROR: [[#@LINE-1]]:1: error: LDR AUTH relocation is not supported in ILP32
92+
// ERROR: [[#@LINE-1]]:10: error: LDR AUTH relocation is not supported in ILP32
9393

9494
adr x24, :got_auth:sym
9595
// ERROR: [[#@LINE-1]]:[[#]]: error: ADR AUTH relocation is not supported in ILP32

llvm/test/MC/AMDGPU/max-branch-distance.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: not llvm-mc -triple=amdgcn -filetype=obj -o /dev/null %s 2>&1 | FileCheck -check-prefix=ERROR %s
2-
// ERROR: max-branch-distance.s:7:3: error: branch size exceeds simm16
2+
// ERROR: max-branch-distance.s:7:12: error: branch size exceeds simm16
33

44
// fill v_nop
55
LBB0_0:

llvm/test/MC/ARM/Windows/branch-reloc-offset.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ err:
6565
// Test errors, if referencing a symbol with an offset
6666

6767
b .Lerr_target+4
68-
// ERR: [[#@LINE-1]]:5: error: cannot perform a PC-relative fixup with a non-zero symbol offset
68+
// ERR: [[#@LINE-1]]:19: error: cannot perform a PC-relative fixup with a non-zero symbol offset
6969
bl .Lerr_target+4
70-
// ERR: [[#@LINE-1]]:5: error: cannot perform a PC-relative fixup with a non-zero symbol offset
70+
// ERR: [[#@LINE-1]]:20: error: cannot perform a PC-relative fixup with a non-zero symbol offset
7171
blx .Lerr_target+4
72-
// ERR: [[#@LINE-1]]:5: error: cannot perform a PC-relative fixup with a non-zero symbol offset
72+
// ERR: [[#@LINE-1]]:21: error: cannot perform a PC-relative fixup with a non-zero symbol offset
7373

7474
// Test errors, if referencing a private label which lacks .def/.scl/.type/.endef, in another
7575
// section, without an offset. Such symbols are omitted from the output symbol table, so the
7676
// relocation can't reference them. Such relocations usually are made towards the base of the
7777
// section plus an offset, but such an offset is not supported with this relocation.
7878

7979
b .Lerr_target2
80-
// ERR: [[#@LINE-1]]:5: error: cannot perform a PC-relative fixup with a non-zero symbol offset
80+
// ERR: [[#@LINE-1]]:7: error: cannot perform a PC-relative fixup with a non-zero symbol offset
8181

8282
.def .Lerr_target
8383
.scl 3

llvm/test/MC/ARM/Windows/invalid-relocation.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
.thumb_func
1010
adr r0, invalid_relocation+1
1111

12-
# CHECK: 10:2: error: unsupported relocation type
12+
# CHECK: 10:28: error: unsupported relocation type

llvm/test/MC/ARM/arm-memory-instructions-immediate.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ foo:
2121
// CHECK-NEXT: strb r0, [r1, #1024]
2222
.ifdef ERR
2323
str r0, [r1, 1b]
24-
// ERR:[[#@LINE-1]]:5: error: unsupported relocation type
24+
// ERR:[[#@LINE-1]]:18: error: unsupported relocation type
2525
.endif

0 commit comments

Comments
 (0)