On Sat, Feb 6, 2010 at 6:03 PM, Anders Carlsson <[email protected]> wrote: > Author: andersca > Date: Sat Feb 6 20:03:08 2010 > New Revision: 95512 > > URL: http://llvm.org/viewvc/llvm-project?rev=95512&view=rev > Log: > Use the right linkage for static variables inside C++ inline functions. > > Modified: > cfe/trunk/lib/CodeGen/CGDecl.cpp > cfe/trunk/lib/CodeGen/CodeGenFunction.h > cfe/trunk/test/CodeGenCXX/static-init.cpp > > Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=95512&r1=95511&r2=95512&view=diff > > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Feb 6 20:03:08 2010 > @@ -76,8 +76,21 @@ > case VarDecl::Auto: > case VarDecl::Register: > return EmitLocalBlockVarDecl(D); > - case VarDecl::Static: > - return EmitStaticBlockVarDecl(D); > + case VarDecl::Static: { > + llvm::GlobalValue::LinkageTypes Linkage = > + llvm::GlobalValue::InternalLinkage; > + > + // If this is a static declaration inside an inline function, it must > have > + // weak linkage so that the linker will merge multiple definitions of it. > + if (getContext().getLangOptions().CPlusPlus) { > + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) { > + if (FD->isInlined()) > + Linkage = llvm::GlobalValue::WeakAnyLinkage; > + } > + }
Do you need to check the linkage of the containing function? A static variable inside a function in an anonymous namespace, for example, shouldn't have weak linkage. -Eli _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
