Skip to content

Conversation

@tambry
Copy link
Contributor

@tambry tambry commented Nov 9, 2025

asm() on function declarations is used for specifying the mangling. But that specific spelling is a GNU extension unlike __asm().

Found by building with -std=c2y in Clang's C frontend's config file.

@tambry tambry requested a review from Michael137 November 9, 2025 13:32
@tambry tambry self-assigned this Nov 9, 2025
@tambry tambry requested a review from JDevlieghere as a code owner November 9, 2025 13:32
@llvmbot llvmbot added the lldb label Nov 9, 2025
`asm()` on function declarations is used for specifying the mangling.
But that specific spelling is a GNU extension unlike `__asm()`.

Found by building with `-std=c2y` in Clang's C frontend's config file.
@llvmbot
Copy link
Member

llvmbot commented Nov 9, 2025

@llvm/pr-subscribers-lldb

Author: Raul Tambre (tambry)

Changes

asm() on function declarations is used for specifying the mangling. But that specific spelling is a GNU extension unlike __asm().

Found by building with -std=c2y in Clang's C frontend's config file.


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

1 Files Affected:

  • (modified) lldb/test/Shell/Unwind/Inputs/call-asm.c (+2-2)
diff --git a/lldb/test/Shell/Unwind/Inputs/call-asm.c b/lldb/test/Shell/Unwind/Inputs/call-asm.c
index b154c1ac1385d..778c16b36a761 100644
--- a/lldb/test/Shell/Unwind/Inputs/call-asm.c
+++ b/lldb/test/Shell/Unwind/Inputs/call-asm.c
@@ -1,3 +1,3 @@
-int asm_main() asm("asm_main");
-
+// Explicit mangling is necessary as on Darwin an underscore is prepended to the symbol.
+int asm_main() __asm("asm_main");
 int main() { return asm_main(); }

@tambry tambry force-pushed the lldb_gnu_asm_call branch from 0b1ddaf to 20ed954 Compare November 9, 2025 13:33
@tambry tambry changed the title [NFCI][lldb][test] Avoid unnecessary GNU extension for assembly call [NFCI][lldb][test] Avoid GNU extension for specifying mangling Nov 9, 2025
@Michael137
Copy link
Member

Michael137 commented Nov 9, 2025

What's the specific error/warning you're getting? This seems like a perfectly supported Clang attribute: https://clang.llvm.org/docs/AttributeReference.html#asm

and the spelling you're changing it to is not listed in "Supported Syntaxes".

@tambry
Copy link
Contributor Author

tambry commented Nov 9, 2025

@Michael137 The error:

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 7
/home/tambre/dev/llvm/build/bin/clang --target=specify-a-target-or-use-a-_host-substitution --target=x86_64-pc-linux-gnu -pthread -fmodules-cache-path=/home/tambre/dev/llvm/build/lldb-test-build.noindex/module-cache-clang/lldb-shell /home/tambre/dev/llvm/lldb/test/Shell/Unwind/Inputs/call-asm.c -x assembler-with-cpp /home/tambre/dev/llvm/lldb/test/Shell/Unwind/Inputs/thread-step-out-ret-addr-check.s -o /home/tambre/dev/llvm/build/tools/lldb/test/Shell/Unwind/Output/thread-step-out-ret-addr-check.test.tmp
# executed command: /home/tambre/dev/llvm/build/bin/clang --target=specify-a-target-or-use-a-_host-substitution --target=x86_64-pc-linux-gnu -pthread -fmodules-cache-path=/home/tambre/dev/llvm/build/lldb-test-build.noindex/module-cache-clang/lldb-shell /home/tambre/dev/llvm/lldb/test/Shell/Unwind/Inputs/call-asm.c -x assembler-with-cpp /home/tambre/dev/llvm/lldb/test/Shell/Unwind/Inputs/thread-step-out-ret-addr-check.s -o /home/tambre/dev/llvm/build/tools/lldb/test/Shell/Unwind/Output/thread-step-out-ret-addr-check.test.tmp
# .---command stderr------------
# | clang: warning: argument unused during compilation: '-fmodules-cache-path=/home/tambre/dev/llvm/build/lldb-test-build.noindex/module-cache-clang/lldb-shell' [-Wunused-command-line-argument]
# | /home/tambre/dev/llvm/lldb/test/Shell/Unwind/Inputs/call-asm.c:2:16: error: expected function body after function declarator
# |     2 | int asm_main() asm("asm_main");
# |       |                ^
# | /home/tambre/dev/llvm/lldb/test/Shell/Unwind/Inputs/call-asm.c:3:21: error: use of undeclared identifier 'asm_main'
# |     3 | int main() { return asm_main(); }
# |       |                     ^~~~~~~~
# | 2 errors generated.
# `-----------------------------
# error: command failed with exit status: 1

The asm() syntax is C++/GNU-only (or with -fgnu-keywords). I'll add the __asm syntax to documentation (#167226).
No strong from my side between __asm and __asm__ as both work the same (unlike asm being GNU-only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants