serge-sans-paille updated this revision to Diff 461893.
serge-sans-paille added a comment.

(rebased on main branch)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134362/new/

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);


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);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to