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

2022-09-22 Thread serge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd4420402927e: [clang] Fix interaction between asm labels and 
inline builtins (authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D134362?vs=462009=462096#toc

Repository:
  rG LLVM Github Monorepo

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,10 @@
   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();
+
+auto *A = FD->getAttr();
+StringRef Ident = A ? A->getLabel() : FD->getName();
+std::string FDInlineName = (Ident + ".inline").str();
 
 bool IsPredefinedLibFunction =
 CGF.getContext().BuiltinInfo.isPredefinedLibFunction(builtinID);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -162,6 +162,7 @@
   `Issue 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


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,10 

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

2022-09-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

Please make sure to mark comments as "Done" in phab to help reviewers skip over 
stale feedback.




Comment at: clang/lib/CodeGen/CGExpr.cpp:5055-5059
+std::string FDInlineName;
+if (auto *A = FD->getAttr())
+  FDInlineName = (A->getLabel() + ".inline").str();
+else
+  FDInlineName = (FD->getName() + ".inline").str();

Might be able to DRY this up slightly more:

```
auto *A = FD->getAttr();
StringRef Ident = A ? A->getLabel() : FD->getName();
std::string FDInlineName = (Ident + ".inline").str();
```


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

https://reviews.llvm.org/D134362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-21 Thread serge via Phabricator via cfe-commits
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())
+  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 `_
 - 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


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() + 

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

2022-09-21 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5057
+if (FD->hasAttr())
+  FDInlineName = FD->getAttr()->getLabel().str();
+else

This is throwing away the ".inline" suffix?  Is that intentional?


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

https://reviews.llvm.org/D134362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5056-5057
+std::string FDInlineName;
+if (FD->hasAttr())
+  FDInlineName = FD->getAttr()->getLabel().str();
+else

I think you could use:

```
if (auto *A = FD->getAttr())
  FDInlineName = A->getLabel().str();
else
  ...
```


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

https://reviews.llvm.org/D134362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-21 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/CodeGen/asm-label-inline-builtins.c:18-20
+// CHECK-NOT: @vprintf(
+// CHECK-NOT: @__vprintf_chk
+// CHECK-NOT: @vprintf.inline(

please be consistent wrt. the trailing open paren `(`.

Let's add a check for the declaration of `@vprintf.inline`?


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

https://reviews.llvm.org/D134362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rjmccall, efriedma.
aaron.ballman added a comment.

Adding some more codegen reviewers. Can you add a release note for the fix?


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

https://reviews.llvm.org/D134362

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-21 Thread serge via Phabricator via cfe-commits
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())
+  FDInlineName = FD->getAttr()->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())
+  FDInlineName = FD->getAttr()->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


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

2022-09-21 Thread serge via Phabricator via cfe-commits
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())
+  FDInlineName = FD->getAttr()->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())
+  FDInlineName = FD->getAttr()->getLabel().str();
+else
+  FDInlineName = (FD->getName() + ".inline").str();
 
 bool