From: Richard Smith Date: Fri, 3 Nov 2017 01:26:01 +0000 (+0000) Subject: [c++17] Visit class template explicit specializations just like all other class defin... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e124612eda3561d10fa5749583e0fabf813e2c82;p=platform%2Fupstream%2Fllvm.git [c++17] Visit class template explicit specializations just like all other class definitions in codegen. If an explicit specialization has a static data member, it may be a definition and we may need to register it for emission. llvm-svn: 317296 --- diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b2a18a0..b155017 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4030,6 +4030,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { case Decl::Namespace: EmitDeclContext(cast(D)); break; + case Decl::ClassTemplateSpecialization: { + const auto *Spec = cast(D); + if (DebugInfo && + Spec->getSpecializationKind() == TSK_ExplicitInstantiationDefinition && + Spec->hasDefinition()) + DebugInfo->completeTemplateDefinition(*Spec); + } LLVM_FALLTHROUGH; case Decl::CXXRecord: if (DebugInfo) { if (auto *ES = D->getASTContext().getExternalSource()) @@ -4216,15 +4223,6 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { EmitOMPThreadPrivateDecl(cast(D)); break; - case Decl::ClassTemplateSpecialization: { - const auto *Spec = cast(D); - if (DebugInfo && - Spec->getSpecializationKind() == TSK_ExplicitInstantiationDefinition && - Spec->hasDefinition()) - DebugInfo->completeTemplateDefinition(*Spec); - break; - } - case Decl::OMPDeclareReduction: EmitOMPDeclareReduction(cast(D)); break; diff --git a/clang/test/CodeGenCXX/cxx1z-inline-variables.cpp b/clang/test/CodeGenCXX/cxx1z-inline-variables.cpp index 0d2ec92..2d16acd 100644 --- a/clang/test/CodeGenCXX/cxx1z-inline-variables.cpp +++ b/clang/test/CodeGenCXX/cxx1z-inline-variables.cpp @@ -67,6 +67,18 @@ int &use3 = X::a; template<> int X::b = 20; template<> inline int X::c = 30; +template struct Y; +template<> struct Y { + static constexpr int a = 123; + static constexpr int b = 456; + static constexpr int c = 789; +}; +// CHECK: @_ZN1YIiE1aE = weak_odr constant i32 123 +constexpr int Y::a; +// CHECK: @_ZN1YIiE1bE = linkonce_odr constant i32 456 +const int &yib = Y::b; +// CHECK-NOT: @_ZN1YIiE1cE + // CHECK-LABEL: define {{.*}}global_var_init // CHECK: call i32 @_Z1fv