Skip to content

Commit bd88444

Browse files
dtellenbachaaryanshukla
authored andcommitted
[AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms (llvm#98097)
AArch64 uses MCAsmInfo::AssemblerDialect to control the style of emitted Neon assembly. E.g. Apple platforms use AsmWriterVariantTy::Apple by default which collides with InlineAsm::AD_Intel (both value 1). Checking for inlineasm dialects on non-X86 platforms can thus lead to problems.
1 parent 1a94491 commit bd88444

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// REQUIRES: aarch64-registered-target
2+
// RUN: %clang_cc1 -triple arm64-apple-ios -S -o - %s | FileCheck %s
3+
4+
// CHECK: _restartable_function:
5+
// CHECK-NEXT: ldr x11, [x0]
6+
// CHECK-NEXT: add x11, x11, #1
7+
// CHECK-NEXT: str x11, [x0]
8+
// CHECK-NEXT: Ltmp0:
9+
// CHECK-NEXT: b Ltmp0
10+
// CHECK-NEXT: LExit_restartable_function:
11+
// CHECK-NEXT: ret
12+
asm(".align 4\n"
13+
" .text\n"
14+
" .private_extern _restartable_function\n"
15+
"_restartable_function:\n"
16+
" ldr x11, [x0]\n"
17+
" add x11, x11, #1\n"
18+
" str x11, [x0]\n"
19+
"1:\n"
20+
" b 1b\n"
21+
"LExit_restartable_function:\n"
22+
" ret\n"
23+
);

llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
113113
if (!TAP)
114114
report_fatal_error("Inline asm not supported by this streamer because"
115115
" we don't have an asm parser for this target\n");
116-
Parser->setAssemblerDialect(Dialect);
116+
117+
// Respect inlineasm dialect on X86 targets only
118+
if (TM.getTargetTriple().isX86()) {
119+
Parser->setAssemblerDialect(Dialect);
120+
// Enable lexing Masm binary and hex integer literals in intel inline
121+
// assembly.
122+
if (Dialect == InlineAsm::AD_Intel)
123+
Parser->getLexer().setLexMasmIntegers(true);
124+
}
117125
Parser->setTargetParser(*TAP);
118-
// Enable lexing Masm binary and hex integer literals in intel inline
119-
// assembly.
120-
if (Dialect == InlineAsm::AD_Intel)
121-
Parser->getLexer().setLexMasmIntegers(true);
122126

123127
emitInlineAsmStart();
124128
// Don't implicitly switch to the text section before the asm.

0 commit comments

Comments
 (0)