[PATCH] D128223: [clang] Cached linkage assertion for static locals of static function

Chris Bowler via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 10 10:16:52 PST 2022


cebowleratibm updated this revision to Diff 473756.
cebowleratibm retitled this revision from "[clang] Linkage computation of static locals may require forcing visibility computation" to "[clang] Cached linkage assertion for static locals of static function".
cebowleratibm edited the summary of this revision.
This revision is now accepted and ready to land.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128223

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGenCXX/linkage-static-local-crash.cpp


Index: clang/test/CodeGenCXX/linkage-static-local-crash.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/linkage-static-local-crash.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -mdefault-visibility-export-mapping=explicit -fvisibility-inlines-hidden -emit-llvm %s -o - | FileCheck %s
+
+struct C {
+  template <typename> 
+  __attribute__((__visibility__("hidden"))) 
+  static int& f() {
+    static int g = 42;
+    return g;
+  }
+};
+
+template<typename T>
+void foo(T i) { C::f<T>(); }
+
+void bar() {
+  foo([]{});
+}
+
+// CHECK: @"_ZZN1C1fIZ3barvE3$_0EERivE1g" = internal global i32 42, align 4
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1368,7 +1368,8 @@
     // is not explicitly attributed as a hidden function,
     // we should not make static local variables in the function hidden.
     LV = getLVForDecl(FD, computation);
-    if (isa<VarDecl>(D) && useInlineVisibilityHidden(FD) &&
+    if (isExternallyVisible(LV.getLinkage()) &&
+        isa<VarDecl>(D) && useInlineVisibilityHidden(FD) &&
         !LV.isVisibilityExplicit() &&
         !Context.getLangOpts().VisibilityInlinesHiddenStaticLocalVar) {
       assert(cast<VarDecl>(D)->isStaticLocal());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128223.473756.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221110/55260129/attachment-0001.bin>


More information about the cfe-commits mailing list