Index: lib/AST/Decl.cpp =================================================================== --- lib/AST/Decl.cpp +++ lib/AST/Decl.cpp @@ -1262,6 +1262,16 @@ !isTemplateInstantiation(FD->getTemplateSpecializationKind())) return LinkageInfo::none(); + // Hiding a static local variable in an hidden function may + // affect the behavior of the program by having multiple copies of the + // variable in the program and dynamic link libraries. + // To avoid such problem, we make a static local variable visible from + // the linker even the containing function is hidden from the linker. + if (isa(D) && useInlineVisibilityHidden(FD)) { + assert(cast(D)->isStaticLocal()); + return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false); + } + LV = getLVForDecl(FD, computation); } if (!isExternallyVisible(LV.getLinkage())) Index: test/CodeGenCXX/visibility-inlines-hidden.cpp =================================================================== --- test/CodeGenCXX/visibility-inlines-hidden.cpp +++ test/CodeGenCXX/visibility-inlines-hidden.cpp @@ -36,6 +36,18 @@ extern template struct X1; +// CHECK: @_ZZN5test73fooEvE3var = linkonce_odr global i32 0, comdat +namespace test7 { + inline int foo(void) { + static int var = 0; + var++; + return var; + } + void bar(void) { + foo(); + } +} + void use(X0 *x0, X1 *x1, X2 *x2, X1 *x3) { // CHECK-LABEL: define linkonce_odr void @_ZN2X02f1Ev x0->f1();