[clang] [llvm] [AsmPrinter,X86] Hard code AT&T syntax input for module-level inline assembly for MSVC triples (PR #85668)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 18 10:23:42 PDT 2024


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/85668

clang-cl is conflating input assembly syntax with output assembly
syntax. It expects AT&T syntax input but Intel syntax output. This
conflicts with clang -c -masm=intel users that do expect -masm=intel to
control both input and output.

After #85367, we use AT&T dialect for module-level inline assembly
parsing, breaking assumptions by Chromium. Hard code MSVC to use
AT&T for now.


>From bdb04a11b5e62f3fe4bc9b03cff09653517bd274 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 18 Mar 2024 10:23:30 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/test/CodeGen/X86/inline-asm-cl.c     | 19 +++++++++++++++++++
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp |  4 +++-
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/X86/inline-asm-cl.c

diff --git a/clang/test/CodeGen/X86/inline-asm-cl.c b/clang/test/CodeGen/X86/inline-asm-cl.c
new file mode 100644
index 00000000000000..15be500521ff9f
--- /dev/null
+++ b/clang/test/CodeGen/X86/inline-asm-cl.c
@@ -0,0 +1,19 @@
+// REQUIRES: x86-registered-target
+/// Some clang-cl users expect AT&T syntax input even if -x86-asm-syntax=intel is set.
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -S -fms-extensions -mllvm -x86-asm-syntax=intel %s -o - | FileCheck %s
+
+// CHECK:         .intel_syntax noprefix
+// CHECK:         mov     rax, rax
+// CHECK-LABEL: foo:
+// CHECK:         mov     rdx, rdx
+// CHECK:         mov     rdx, rdx
+
+asm("movq %rax, %rax");
+
+void foo() {
+  asm("movq %rdx, %rdx");
+
+  __asm {
+    mov rdx, rdx
+  }
+}
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index a15538755d73b3..20b3967af057f1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -541,7 +541,9 @@ bool AsmPrinter::doInitialization(Module &M) {
     emitInlineAsm(
         M.getModuleInlineAsm() + "\n", *TM.getMCSubtargetInfo(),
         TM.Options.MCOptions, nullptr,
-        InlineAsm::AsmDialect(TM.getMCAsmInfo()->getAssemblerDialect()));
+        TM.getTargetTriple().isWindowsMSVCEnvironment()
+            ? InlineAsm::AD_ATT
+            : InlineAsm::AsmDialect(TM.getMCAsmInfo()->getAssemblerDialect()));
     OutStreamer->AddComment("End of file scope inline assembly");
     OutStreamer->addBlankLine();
   }



More information about the cfe-commits mailing list