Skip to content

Commit f4335f0

Browse files
authored
[X86,AsmPrinter] Set assembler dialect for module inline asm
`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 because of https://reviews.llvm.org/D82862 for #34830: it tried to support AT&T syntax for clang-cl, but the forced AT&T syntax is not compatible with intended Intel syntax. Pull Request: #85367
1 parent f01a32f commit f4335f0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,10 @@ bool AsmPrinter::doInitialization(Module &M) {
538538
if (!M.getModuleInlineAsm().empty()) {
539539
OutStreamer->AddComment("Start of file scope inline assembly");
540540
OutStreamer->addBlankLine();
541-
emitInlineAsm(M.getModuleInlineAsm() + "\n", *TM.getMCSubtargetInfo(),
542-
TM.Options.MCOptions);
541+
emitInlineAsm(
542+
M.getModuleInlineAsm() + "\n", *TM.getMCSubtargetInfo(),
543+
TM.Options.MCOptions, nullptr,
544+
InlineAsm::AsmDialect(TM.getMCAsmInfo()->getAssemblerDialect()));
543545
OutStreamer->AddComment("End of file scope inline assembly");
544546
OutStreamer->addBlankLine();
545547
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
;; Test that we respect the assembler dialect when parsing module-level inline asm.
2+
; RUN: not llc < %s -mtriple=x86_64 2>&1 | FileCheck %s --check-prefix=ERR
3+
; RUN: llc < %s -mtriple=x86_64 -x86-asm-syntax=intel | FileCheck %s
4+
5+
; ERR: <inline asm>:1:1: error: unknown use of instruction mnemonic without a size suffix
6+
7+
; CHECK: .intel_syntax noprefix
8+
; CHECK: mov eax, eax
9+
10+
module asm "mov eax, eax"

0 commit comments

Comments
 (0)