[llvm] [MC] Diagnose applying a specifier to an already-specified expression (PR #219710)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 29 11:07:28 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Guy David (guy-david)

<details>
<summary>Changes</summary>

MCAsmParser::applySpecifier() hit llvm_unreachable() when asked to apply a relocation specifier to an expression that already carries one, which caused a crash.

Assisted-by: Opus 5.0

---
Full diff: https://github.com/llvm/llvm-project/pull/219710.diff


2 Files Affected:

- (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+3-1) 
- (added) llvm/test/MC/AArch64/nested-specifier-error.s (+10) 


``````````diff
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index c4c5b1da9aa91..94082684e13ea 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1360,7 +1360,9 @@ const MCExpr *MCAsmParser::applySpecifier(const MCExpr *E, uint32_t Spec) {
   // if there is exactly one symbol.
   switch (E->getKind()) {
   case MCExpr::Specifier:
-    llvm_unreachable("cannot apply another specifier to MCSpecifierExpr");
+    TokError("invalid variant on expression '" + getTok().getIdentifier() +
+             "' (already modified)");
+    return E;
   case MCExpr::Target:
   case MCExpr::Constant:
     return nullptr;
diff --git a/llvm/test/MC/AArch64/nested-specifier-error.s b/llvm/test/MC/AArch64/nested-specifier-error.s
new file mode 100644
index 0000000000000..0eea84989772a
--- /dev/null
+++ b/llvm/test/MC/AArch64/nested-specifier-error.s
@@ -0,0 +1,10 @@
+// RUN: not llvm-mc -triple arm64e-apple-macosx -filetype obj %s -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: [[@LINE+1]]:26: error: invalid variant on expression 'PAGEOFF' (already modified)
+  ldr q4, [x8, :lo12:sym at PAGEOFF]
+
+// CHECK: [[@LINE+1]]:25: error: invalid variant on expression 'PAGEOFF' (already modified)
+  add x8, x8, :lo12:sym at PAGEOFF
+
+// CHECK: [[@LINE+1]]:25: error: invalid variant on expression 'PAGEOFF' (already modified)
+  add x8, x8, :lo12:sym at PAGEOFF + 4

``````````

</details>


https://github.com/llvm/llvm-project/pull/219710


More information about the llvm-commits mailing list