[clang] [llvm] [X86][AsmParser] Fix MS inline asm label mismatch with offset operator (PR #199552)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 3 04:41:35 PDT 2026


================
@@ -0,0 +1,32 @@
+; RUN: llc < %s -mtriple=i386-pc-windows-msvc | FileCheck %s
+
+; Verify that the 'offset' reference to an inline asm label uses the same
+; PrivateLabelPrefix as the label definition. On Windows COFF the prefix is "L".
+;
+; Previously, the label definition got the "L" prefix via AOK_Label rewrite,
+; but the offset reference skipped the rewrite and used the internal name
+; without the prefix, causing an undefined symbol error at link time.
+;
+; C source:
+; int main() {
+;   unsigned dwpXIP;
+;   __asm {
+;     XIP_label:
+;     mov dwpXIP, offset XIP_label
+;   }
+;   return 0;
+; }
+
+define dso_local i32 @label_offset() {
+entry:
+  %result = alloca i32, align 4
+  call void asm sideeffect inteldialect "L__MSASMLABEL_.${:uid}__XIP_label:\0A\09mov dword ptr $0, offset L__MSASMLABEL_.${:uid}__XIP_label", "=*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i32) %result)
+  %0 = load i32, ptr %result, align 4
+  ret i32 %0
+}
+
+; The key check: both the label definition and offset reference must use
+; the same "L__MSASMLABEL_.0__XIP_label" name with the "L" prefix.
----------------
sonyps5201314 wrote:

So how should I proceed now? Alternatively, I could just leave both unit tests in place, and you can take it from here to implement the fix. To be honest, I don't really care about getting the commit credit. My only concern is getting this bug resolved so that Clang achieves full feature parity with MSVC.

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


More information about the cfe-commits mailing list