[llvm] [X86,AsmPrinter] Set assembler dialect for module inline asm (PR #85367)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 00:10:41 PDT 2024
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/85367
`clang -c -masm=intel` compiling a source file with file scope basic asm
incorrectly uses the AT&T dialect.
```
% cat a.c
asm("mov rax, rax");
% clang a.c -c -masm=intel
<inline asm>:1:1: error: unknown use of instruction mnemonic without a size suffix
mov rax, rax
^
```
Fix this by setting the assembler dialect from the MCAsmInfo object.
Note: `clang -c -flto -masm=intel a.c` still fails due to a known LTO
problem of ModuleSymbolTable::CollectAsmSymbols not using sufficient
target information.
>From f73354b419bdf92fd21231459b6220a77c79be76 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 15 Mar 2024 00:10:33 -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
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 6 ++++--
llvm/test/CodeGen/X86/asm-dialect-module.ll | 10 ++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/asm-dialect-module.ll
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 0efe7a0e733672..a15538755d73b3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -538,8 +538,10 @@ bool AsmPrinter::doInitialization(Module &M) {
if (!M.getModuleInlineAsm().empty()) {
OutStreamer->AddComment("Start of file scope inline assembly");
OutStreamer->addBlankLine();
- emitInlineAsm(M.getModuleInlineAsm() + "\n", *TM.getMCSubtargetInfo(),
- TM.Options.MCOptions);
+ emitInlineAsm(
+ M.getModuleInlineAsm() + "\n", *TM.getMCSubtargetInfo(),
+ TM.Options.MCOptions, nullptr,
+ InlineAsm::AsmDialect(TM.getMCAsmInfo()->getAssemblerDialect()));
OutStreamer->AddComment("End of file scope inline assembly");
OutStreamer->addBlankLine();
}
diff --git a/llvm/test/CodeGen/X86/asm-dialect-module.ll b/llvm/test/CodeGen/X86/asm-dialect-module.ll
new file mode 100644
index 00000000000000..2c00a44424c2c3
--- /dev/null
+++ b/llvm/test/CodeGen/X86/asm-dialect-module.ll
@@ -0,0 +1,10 @@
+;; Test that we respect the assembler dialect when parsing module-level inline asm.
+; RUN: not llc < %s -mtriple=x86_64 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: llc < %s -mtriple=x86_64 -x86-asm-syntax=intel | FileCheck %s
+
+; ERR: <inline asm>:1:1: error: unknown use of instruction mnemonic without a size suffix
+
+; CHECK: .intel_syntax noprefix
+; CHECK: mov eax, eax
+
+module asm "mov eax, eax"
More information about the llvm-commits
mailing list