[clang] [llvm] [X86][AsmParser] Fix MS inline asm label mismatch with offset operator (PR #199552)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 25 09:42:50 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: sonyps5201314
<details>
<summary>Changes</summary>
When using the 'offset' operator to reference an inline asm label in MSVC-style inline assembly, the label reference was missing the PrivateLabelPrefix (e.g., 'L' on COFF targets). This caused a symbol name mismatch between the label definition and its reference:
- Label definition (via AOK_Label rewrite): L__MSASMLABEL_.0__name
- Offset reference (no rewrite): __MSASMLABEL_.0__name
This mismatch resulted in an 'undefined symbol' linker error when using lld-link on Windows.
The fix prepends PrivateLabelPrefix to the internal label name when parsing the offset operator, matching what AOK_Label does for label definitions and non-offset references.
for fix https://github.com/llvm/llvm-project/issues/132863
---
Full diff: https://github.com/llvm/llvm-project/pull/199552.diff
2 Files Affected:
- (modified) clang/test/CodeGen/ms-inline-asm.c (+14)
- (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+8-2)
``````````diff
diff --git a/clang/test/CodeGen/ms-inline-asm.c b/clang/test/CodeGen/ms-inline-asm.c
index c3eef9a23e166..2cf3cb3ce74a2 100644
--- a/clang/test/CodeGen/ms-inline-asm.c
+++ b/clang/test/CodeGen/ms-inline-asm.c
@@ -789,6 +789,20 @@ int test_indirect_field(LARGE_INTEGER LargeInteger) {
// CHECK-LABEL: define{{.*}} i32 @test_indirect_field(
// CHECK: call i32 asm sideeffect inteldialect "mov eax, $1",
+// Test that 'offset' references to inline asm labels use the same
+// PrivateLabelPrefix as the label definition.
+void label_offset(void) {
+ __asm {
+ label_offset_target:
+ mov eax, offset label_offset_target
+ }
+ // CHECK-LABEL: define{{.*}} void @label_offset(
+ // CHECK: call void asm sideeffect inteldialect
+ // CHECK-SAME: {{.*}}__MSASMLABEL_.${:uid}__label_offset_target:
+ // CHECK-SAME: mov eax, offset {{.*}}__MSASMLABEL_.${:uid}__label_offset_target
+ // CHECK-SAME: "~{eax},~{dirflag},~{fpsr},~{flags}"()
+}
+
// MS ASM containing labels must not be duplicated (PR23715).
// CHECK: attributes [[ATTR1]] = {
// CHECK-NOT: noduplicate
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 1741efac3a8c7..942ee6bb07d28 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2317,8 +2317,14 @@ bool X86AsmParser::ParseIntelInlineAsmIdentifier(
if (!IsParsingOffsetOperator)
InstInfo->AsmRewrites->emplace_back(AOK_Label, Loc, Identifier.size(),
InternalName);
- else
- Identifier = InternalName;
+ else {
+ // When parsing the offset operator, we need to prepend
+ // PrivateLabelPrefix to match the AOK_Label rewrite at label definition.
+ StringRef Prefix = getContext().getAsmInfo().getPrivateLabelPrefix();
+ SmallString<128> PrefixedName;
+ (Twine(Prefix) + InternalName).toVector(PrefixedName);
+ Identifier = getContext().allocateString(PrefixedName);
+ }
} else if (Info.isKind(InlineAsmIdentifierInfo::IK_EnumVal))
return false;
// Create the symbol reference.
``````````
</details>
https://github.com/llvm/llvm-project/pull/199552
More information about the cfe-commits
mailing list