[clang] [Clang] Honor asm labels on library functions for compiler-emitted calls (PR #244853)
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 16:07:29 PST 2026
================
@@ -53,3 +54,41 @@ double sin(double x) asm("real_sin");
double test_sin(double d) { return __builtin_sin(d); }
// CHECK-LABEL: @test_sin(
// LINUX: call double @llvm.sin.f64(
+
+/// A call through the __builtin_ alias of a library function uses the asm
+/// label of the library function, as a direct call does.
+extern char *stpcpy(char *__restrict, const char *__restrict);
+extern __typeof(stpcpy) stpcpy asm("__GI_stpcpy");
----------------
brad0 wrote:
1. Clang already rejects the direct call case with "cannot apply asm label to function after its first use". This patch doesn't change that. The label has to come before the use, so I don't think we need to allow it here.
2. GCC calls `__GI_strcpy` here because it turns `__builtin_stpcpy(x, y)` into `strcpy(x, y)` when the result is not used, even at -O0, and the call then uses the asm label on `strcpy`. In Clang that is done in LLVM (SimplifyLibCalls), which doesn't know about asm labels. It is the same problem as `memcpy` calls from the backend, so I think it is out of scope. If `stpcpy` is labeled too, we call `__GI_stpcpy`, so there is no PLT call.
https://github.com/llvm/llvm-project/pull/244853
More information about the cfe-commits
mailing list