serge-sans-paille updated this revision to Diff 516645.
serge-sans-paille retitled this revision from "[clang] Enforce internal linkage 
for inline builtin" to "[clang] Enforce external linkage for inline builtin 
original declaration".
serge-sans-paille edited the summary of this revision.
serge-sans-paille added a comment.
Herald added a subscriber: mstorsjo.

Change approach and update test case accordingly.


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

https://reviews.llvm.org/D148723

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/asm-label-inline-builtins.c
  clang/test/CodeGen/inline-builtin-asm-name.c
  clang/test/CodeGen/inline-builtin-comdat.c
  clang/test/CodeGen/pr9614.c

Index: clang/test/CodeGen/pr9614.c
===================================================================
--- clang/test/CodeGen/pr9614.c
+++ clang/test/CodeGen/pr9614.c
@@ -30,6 +30,8 @@
   memchr("", '.', 0);
 }
 
+// CHECK-LABEL: declare i32 @abs(i32
+//
 // CHECK-LABEL: define{{.*}} void @f()
 // CHECK: call void @foo()
 // CHECK: call i32 @abs(i32 noundef %0)
@@ -37,9 +39,8 @@
 // CHECK: call void @llvm.prefetch.p0(
 // CHECK: call ptr @memchr(
 // CHECK: ret void
-
-// CHECK: declare void @foo()
-// CHECK: declare i32 @abs(i32
-// CHECK: declare ptr @strrchr(ptr noundef, i32 noundef)
-// CHECK: declare ptr @memchr(
-// CHECK: declare void @llvm.prefetch.p0(
+//
+// CHECK-LABEL: declare void @foo()
+// CHECK-LABEL: declare ptr @strrchr(ptr noundef, i32 noundef)
+// CHECK-LABEL: declare ptr @memchr(
+// CHECK-LABEL: declare void @llvm.prefetch.p0(
Index: clang/test/CodeGen/inline-builtin-comdat.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/inline-builtin-comdat.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-windows -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
+// Make sure we don't generate definition for Inline Builtins, and that all
+// linkage are compatible with comdat rules.
+
+double __cdecl frexp( double _X, int* _Y);
+inline __attribute__((always_inline))  long double __cdecl frexpl( long double __x, int *__exp ) {
+  return (long double) frexp((double)__x, __exp );
+}
+
+long double pain(void)
+{
+    long double f = 123.45;
+    int i;
+    long double f2 = frexpl(f, &i);
+    return f2;
+}
+
+// CHECK-NOT: define {{.*}} @frexpl(
+//
+// CHECK-LABEL: declare dso_local double @frexpl(
+//
+// CHECK-LABEL: define internal double @frexpl.inline(
+// CHECK:       call double @frexp
+//
+// CHECK-LABEL: declare dso_local double @frexp(
+//
+// CHECK-LABEL: define dso_local double @pain(
+// CHECK:    call double @frexpl.inline(
Index: clang/test/CodeGen/inline-builtin-asm-name.c
===================================================================
--- clang/test/CodeGen/inline-builtin-asm-name.c
+++ clang/test/CodeGen/inline-builtin-asm-name.c
@@ -1,14 +1,14 @@
 // RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s -disable-llvm-optzns | FileCheck %s
 
-// CHECK: call i32 @"\01_asm_func_name.inline"
-
-// CHECK: declare dso_local i32 @"\01_asm_func_name"(ptr noundef, i32 noundef, ptr noundef, ptr noundef)
-
-// CHECK: define internal i32 @"\01_asm_func_name.inline"
-
+// CHECK-LABEL: declare dso_local i32 @"\01_asm_func_name"(ptr noundef, i32 noundef, ptr noundef, ptr noundef)
+//
+// CHECK-LABEL: define internal i32 @"\01_asm_func_name.inline"(
 // CHECK: call i32 @__mingw_vsnprintf
-
-// CHECK: declare dso_local i32 @__mingw_vsnprintf
+//
+// CHECK-LABEL: declare dso_local i32 @__mingw_vsnprintf
+//
+// CHECK-LABEL: define dso_local void @call(ptr noundef %fmt, ...)
+// CHECK: call i32 @"\01_asm_func_name.inline"
 
 typedef unsigned int size_t;
 
Index: clang/test/CodeGen/asm-label-inline-builtins.c
===================================================================
--- clang/test/CodeGen/asm-label-inline-builtins.c
+++ clang/test/CodeGen/asm-label-inline-builtins.c
@@ -25,8 +25,8 @@
   vprintf(fmt, ap);
 }
 
-// CHECK-LABEL: void @test(
-// CHECK: call i32 @__vprintfieee128.inline(
-//
 // CHECK-LABEL: internal i32 @__vprintfieee128.inline(
 // CHECK: call i32 @__vfprintf_chkieee128(
+//
+// CHECK-LABEL: void @test(
+// CHECK: call i32 @__vprintfieee128.inline(
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11552,6 +11552,11 @@
   if (!FD->isExternallyVisible())
     return GVA_Internal;
 
+  // Inline Builtin declaration are forward declared as external and their
+  // actual implementation is provided under the ".inline" declaration.
+  if (FD->isInlineBuiltinDeclaration())
+    return GVA_StrongExternal;
+
   // Non-user-provided functions get emitted as weak definitions with every
   // use, no matter whether they've been explicitly instantiated etc.
   if (!FD->isUserProvided())
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to