[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 14:40:44 PDT 2022


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

Address reviews.


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

https://reviews.llvm.org/D134362

Files:
  clang/docs/ReleaseNotes.rst
  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,32 @@
+// 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 ("__vprintfieee128");
+extern __typeof (__vfprintf_chk) __vfprintf_chk __asm ("__vfprintf_chkieee128");
+extern __typeof (__vprintf_chk) __vprintf_chk __asm ("__vprintf_chkieee128");
+
+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);
+}
+
+void test(const char *fmt, __builtin_va_list ap) {
+  vprintf(fmt, ap);
+}
+
+// CHECK-LABEL: void @test(
+// CHECK: call i32 @__vprintfieee128.inline(
+//
+// CHECK-LABEL: internal i32 @__vprintfieee128.inline(
+// CHECK: call i32 @__vfprintf_chkieee128(
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 (auto *A = FD->getAttr<AsmLabelAttr>())
+      FDInlineName = (A->getLabel() + ".inline").str();
+    else
+      FDInlineName = (FD->getName() + ".inline").str();
 
     bool IsPredefinedLibFunction =
         CGF.getContext().BuiltinInfo.isPredefinedLibFunction(builtinID);
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -160,6 +160,7 @@
   `Issue 53628 <https://github.com/llvm/llvm-project/issues/53628>`_
 - The template arguments of a variable template being accessed as a
   member will now be represented in the AST.
+- Fix incorrect handling of inline builtins with asm labels.
 
 
 Improvements to Clang's diagnostics


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134362.462009.patch
Type: text/x-patch
Size: 2735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220921/78297b7a/attachment-0001.bin>


More information about the cfe-commits mailing list