Fangrui Song 777391a216 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
7e3e2e1b8c6ff21e68782a56164139cca334fcf3
7b517cf743f112f980cf6a4d6e6190c2a5b3e451
2025-07-04 12:06:28 -07:00

30 lines
1.2 KiB
ArmAsm

# RUN: not llvm-mc -triple riscv32 -filetype obj %s -o /dev/null 2>&1 | FileCheck %s
.Ltmp1:
.quad tls
lui a0, %hi(tls+0-.Ltmp1)
# CHECK: :[[#@LINE-1]]:10: error: expected relocatable expression
lw a0, %lo(tls+0-.Ltmp1)(t0)
# CHECK: :[[#@LINE-1]]:9: error: expected relocatable expression
lui a0, %tprel_hi(tls+0-.Ltmp1)
# CHECK: :[[#@LINE-1]]:10: error: expected relocatable expression
add a0, a0, tp, %tprel_add(tls+0-.Ltmp1)
# CHECK: :[[#@LINE-1]]:18: error: expected relocatable expression
addi a0, a0, %tprel_lo(tls+0-.Ltmp1)
# CHECK: :[[#@LINE-1]]:15: error: expected relocatable expression
auipc a0, %tls_ie_pcrel_hi(tls+0-.Ltmp1)
# CHECK: :[[#@LINE-1]]:12: error: expected relocatable expression
auipc a0, %tls_gd_pcrel_hi(tls+0-.Ltmp1)
# CHECK: :[[#@LINE-1]]:12: error: expected relocatable expression
auipc a0, %pcrel_hi(tls-.Ltmp1)
# CHECK: :[[#@LINE-1]]:12: error: expected relocatable expression
auipc a0, %got_pcrel_hi(tls-.Ltmp1)
# CHECK: :[[#@LINE-1]]:12: error: expected relocatable expression
addi a0, a0, %pcrel_lo(tls-.Ltmp1)
# CHECK: :[[#@LINE-1]]:15: error: expected relocatable expression
# tail tls+32
# tail tls-tls
# _ :[[#@LINE-1]]:2: error: expected relocatable expression