diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b2a18a03f2910a7a49f8561953ad9f10cbae970f..b1550170accbe4fe0ca3808abc67c339b0f0ef41 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 0d2ec92a7af8258517c69809114a25a59295668f..2d16acd8a8c23b167a6893734555d3961a1b2315 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