Skip to content

[AsmPrinter] Don't check for inlineasm dialect on non-X86 platforms #98097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

dtellenbach
Copy link
Member

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.

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.
@dtellenbach dtellenbach requested a review from MaskRay July 8, 2024 23:13
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 8, 2024
@dtellenbach dtellenbach added llvm:asmparser inline-asm and removed clang Clang issues not falling into any other category labels Jul 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2024

@llvm/pr-subscribers-clang

Author: David Tellenbach (dtellenbach)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/98097.diff

2 Files Affected:

  • (added) clang/test/CodeGen/AArch64/inline-asm-ios.c (+23)
  • (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (+9-5)
diff --git a/clang/test/CodeGen/AArch64/inline-asm-ios.c b/clang/test/CodeGen/AArch64/inline-asm-ios.c
new file mode 100644
index 0000000000000..5e7328a15f69d
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/inline-asm-ios.c
@@ -0,0 +1,23 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple arm64-apple-ios -S -o - %s | FileCheck %s
+
+// CHECK:       _restartable_function:
+// CHECK-NEXT:  	ldr	x11, [x0]
+// CHECK-NEXT:  	add	x11, x11, #1
+// CHECK-NEXT:  	str	x11, [x0]
+// CHECK-NEXT:  Ltmp0:
+// CHECK-NEXT:  	b	Ltmp0
+// CHECK-NEXT:  LExit_restartable_function:
+// CHECK-NEXT:  	ret
+asm(".align 4\n"
+    "    .text\n"
+    "    .private_extern _restartable_function\n"
+    "_restartable_function:\n"
+    "    ldr    x11, [x0]\n"
+    "    add    x11, x11, #1\n"
+    "    str    x11, [x0]\n"
+    "1:\n"
+    "    b 1b\n"
+    "LExit_restartable_function:\n"
+    "    ret\n"
+);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 5a7013c964cb4..6fe8d0e0af995 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -113,12 +113,16 @@ void AsmPrinter::emitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
   if (!TAP)
     report_fatal_error("Inline asm not supported by this streamer because"
                        " we don't have an asm parser for this target\n");
-  Parser->setAssemblerDialect(Dialect);
+
+  // Respect inlineasm dialect on X86 targets only
+  if (TM.getTargetTriple().isX86()) {
+    Parser->setAssemblerDialect(Dialect);
+    // Enable lexing Masm binary and hex integer literals in intel inline
+    // assembly.
+    if (Dialect == InlineAsm::AD_Intel)
+      Parser->getLexer().setLexMasmIntegers(true);
+  }
   Parser->setTargetParser(*TAP);
-  // Enable lexing Masm binary and hex integer literals in intel inline
-  // assembly.
-  if (Dialect == InlineAsm::AD_Intel)
-    Parser->getLexer().setLexMasmIntegers(true);
 
   emitInlineAsmStart();
   // Don't implicitly switch to the text section before the asm.

@dtellenbach
Copy link
Member Author

@MaskRay the added test fails since your commit f4335f0. The commit itself is alright, just exposed the underlying problem.

@dtellenbach dtellenbach requested a review from jroelofs July 8, 2024 23:29
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 9, 2024
@dtellenbach
Copy link
Member Author

Linux test failure seems unrelated (fails to build some libcxx stuff). The new test passes:

PASS: Clang :: CodeGen/aarch64-inlineasm-ios.c (14316 of 95454)

@dtellenbach dtellenbach merged commit 8f15909 into llvm:main Jul 9, 2024
6 of 8 checks passed
@dtellenbach dtellenbach deleted the inline-asm-dialect branch July 9, 2024 19:44
@MaskRay
Copy link
Member

MaskRay commented Jul 10, 2024

LGTM

aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
…lvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category inline-asm llvm:asmparser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants