[PATCH] D148723: [clang] Restrict Inline Builtin to non-static, non-odr linkage

serge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 26 07:19:56 PDT 2023


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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148723.526059.patch
Type: text/x-patch
Size: 1546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230526/b3a412da/attachment.bin>


More information about the cfe-commits mailing list