serge-sans-paille updated this revision to Diff 526059.
serge-sans-paille retitled this revision from "[clang] Fix comdat for 
InlineBuiltin declarations" to "[clang] Restrict Inline Builtin to non-static, 
non-odr linkage".
serge-sans-paille edited the summary of this revision.
serge-sans-paille added a comment.

Add a linkage check to further restrict what's an inline builtin.


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

https://reviews.llvm.org/D148723

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGen/inline-builtin-comdat.c


Index: clang/test/CodeGen/inline-builtin-comdat.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/inline-builtin-comdat.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-windows -S -emit-llvm -disable-llvm-passes 
%s -o - | FileCheck %s
+// Inline builtin are not supported for odr linkage
+// CHECK-NOT: .inline
+
+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;
+}
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3301,8 +3301,23 @@
     return false;
 
   const FunctionDecl *Definition;
-  return hasBody(Definition) && Definition->isInlineSpecified() &&
-         Definition->hasAttr<AlwaysInlineAttr>();
+  if (!hasBody(Definition))
+    return false;
+
+  if (!Definition->isInlineSpecified() ||
+      !Definition->hasAttr<AlwaysInlineAttr>())
+    return false;
+
+  ASTContext &Context = getASTContext();
+  switch (Context.GetGVALinkageForFunction(this)) {
+  case GVA_Internal:
+  case GVA_DiscardableODR:
+  case GVA_StrongODR:
+    return false;
+  case GVA_AvailableExternally:
+  case GVA_StrongExternal:
+    return true;
+  }
 }
 
 bool FunctionDecl::isDestroyingOperatorDelete() const {


Index: clang/test/CodeGen/inline-builtin-comdat.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/inline-builtin-comdat.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-windows -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
+// Inline builtin are not supported for odr linkage
+// CHECK-NOT: .inline
+
+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;
+}
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3301,8 +3301,23 @@
     return false;
 
   const FunctionDecl *Definition;
-  return hasBody(Definition) && Definition->isInlineSpecified() &&
-         Definition->hasAttr<AlwaysInlineAttr>();
+  if (!hasBody(Definition))
+    return false;
+
+  if (!Definition->isInlineSpecified() ||
+      !Definition->hasAttr<AlwaysInlineAttr>())
+    return false;
+
+  ASTContext &Context = getASTContext();
+  switch (Context.GetGVALinkageForFunction(this)) {
+  case GVA_Internal:
+  case GVA_DiscardableODR:
+  case GVA_StrongODR:
+    return false;
+  case GVA_AvailableExternally:
+  case GVA_StrongExternal:
+    return true;
+  }
 }
 
 bool FunctionDecl::isDestroyingOperatorDelete() const {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to