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());
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());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits