[PATCH] D134362: [clang] Fix interaction between asm labels and inline builtins

serge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 21 07:33:44 PDT 2022


serge-sans-paille created this revision.
serge-sans-paille added reviewers: RKSimon, aaron.ballman, nickdesaulniers.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

One must pick the same name as the one referenced in CodeGenFunction when
generating .inline version of an inline builtin, otherwise they are not
correctly replaced.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134362

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/asm-label-inline-builtins.c


Index: clang/test/CodeGen/asm-label-inline-builtins.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/asm-label-inline-builtins.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+//
+// Verifies that clang-generated *.inline carry the same name at call and callee
+// site, in spite of asm labels.
+
+typedef struct _IO_FILE FILE;
+extern FILE *stdout;
+extern int vprintf (const char *__restrict __format, __builtin_va_list __arg);
+extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
+      const char *__restrict __format, __builtin_va_list __ap);
+extern int __vprintf_chk (int __flag, const char *__restrict __format,
+     __builtin_va_list __ap);
+
+extern __typeof (vprintf) vprintf __asm ("" "__" "vprintf" "ieee128");
+extern __typeof (__vfprintf_chk) __vfprintf_chk __asm ("" "__" "vfprintf_chk" "ieee128");
+extern __typeof (__vprintf_chk) __vprintf_chk __asm ("" "__" "vprintf_chk" "ieee128");
+
+// CHECK-NOT: @vprintf(
+// CHECK-NOT: @__vprintf_chk
+// CHECK-NOT: @vprintf.inline(
+
+extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
+vprintf (const char *__restrict __fmt, __builtin_va_list __ap)
+{
+  return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap);
+}
+// CHECK-LABEL: void @test(
+void test(const char *fmt, __builtin_va_list ap) {
+  // CHECK: call i32 @__vfprintf_chkieee128
+  vprintf(fmt, ap);
+}
Index: clang/lib/CodeGen/CGExpr.cpp
===================================================================
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5051,7 +5051,12 @@
   if (auto builtinID = FD->getBuiltinID()) {
     std::string NoBuiltinFD = ("no-builtin-" + FD->getName()).str();
     std::string NoBuiltins = "no-builtins";
-    std::string FDInlineName = (FD->getName() + ".inline").str();
+
+    std::string FDInlineName;
+    if (FD->hasAttr<AsmLabelAttr>())
+      FDInlineName = FD->getAttr<AsmLabelAttr>()->getLabel().str();
+    else
+      FDInlineName = (FD->getName() + ".inline").str();
 
     bool IsPredefinedLibFunction =
         CGF.getContext().BuiltinInfo.isPredefinedLibFunction(builtinID);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134362.461891.patch
Type: text/x-patch
Size: 2269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220921/309227d2/attachment.bin>


More information about the cfe-commits mailing list