[cfe-commits] r117410 - in /cfe/trunk: lib/CodeGen/CGDeclCXX.cpp lib/CodeGen/ItaniumCXXABI.cpp test/CodeGenCXX/specialized-static-data-mem-init.cpp
Douglas Gregor
dgregor at apple.com
Tue Oct 26 17:06:57 PDT 2010
On Oct 26, 2010, at 3:47 PM, Fariborz Jahanian wrote:
> Author: fjahanian
> Date: Tue Oct 26 17:47:47 2010
> New Revision: 117410
>
> URL: http://llvm.org/viewvc/llvm-project?rev=117410&view=rev
> Log:
> Patch to provide guard when initializing instances
> of static data member of a class template.
> Fixes //rdar :// 8562966 and pr8409.
>
> Added:
> cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp
> Modified:
> cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
> cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=117410&r1=117409&r2=117410&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Tue Oct 26 17:47:47 2010
> @@ -253,7 +253,15 @@
> SourceLocation());
>
> llvm::Constant *DeclPtr = CGM.GetAddrOfGlobalVar(D);
> - EmitCXXGlobalVarDeclInit(*D, DeclPtr);
> + if (D->isStaticDataMember() &&
> + D->getInstantiatedFromStaticDataMember() && D->getInit()){
This should check whether D will get weak linkage. If not, we don't need the guards.
> + llvm::GlobalVariable *GV = dyn_cast<llvm::GlobalVariable>(DeclPtr);
> + assert(GV && "GenerateCXXGlobalVarDeclInitFunc - GV is null");
> + GV->setConstant(false);
> + EmitCXXStaticLocalInit(*D, GV);
> + }
> + else
> + EmitCXXGlobalVarDeclInit(*D, DeclPtr);
>
> FinishFunction();
> }
>
> Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=117410&r1=117409&r2=117410&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
> +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue Oct 26 17:47:47 2010
> @@ -1092,9 +1092,14 @@
> // Create the guard variable.
> llvm::SmallString<256> GuardVName;
> getMangleContext().mangleItaniumGuardVariable(&D, GuardVName);
> + llvm::GlobalValue::LinkageTypes Linkage = GV->getLinkage();
> + if (D.isStaticDataMember() &&
> + D.getInstantiatedFromStaticDataMember())
> + Linkage = llvm::GlobalVariable::WeakAnyLinkage;
> +
> llvm::GlobalVariable *GuardVariable =
> new llvm::GlobalVariable(CGM.getModule(), GuardTy,
> - false, GV->getLinkage(),
> + false, Linkage,
> llvm::ConstantInt::get(GuardTy, 0),
> GuardVName.str());
>
>
> Added: cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp?rev=117410&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp Tue Oct 26 17:47:47 2010
> @@ -0,0 +1,29 @@
> +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
> +// rdar: // 8562966
> +// pr8409
> +
> +// CHECK: @_ZN1CIiE11needs_guardE = weak global
> +// CHECK: @_ZGVN1CIiE11needs_guardE = weak global
> +
> +struct K
> +{
> + K();
> + K(const K &);
> + ~K();
> + void PrintNumK();
> +};
> +
> +template<typename T>
> +struct C
> +{
> + void Go() { needs_guard.PrintNumK(); }
> + static K needs_guard;
> +};
> +
> +template<typename T> K C<T>::needs_guard;
> +
> +void F()
> +{
> + C<int>().Go();
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list