Author: gbiv Date: Mon Mar 19 20:27:44 2018 New Revision: 327945 URL: http://llvm.org/viewvc/llvm-project?rev=327945&view=rev Log: Properly construct `inline` members without initializers
Digging through commit logs, it appears the checks in this block predate `inline` class variables. With them, we fail to emit dynamic initializers for members that don't have an explicit initializer, and we won't go out of our way to instantiate the class denoted by `Var->getType()`. Fixes PR35599. Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=327945&r1=327944&r2=327945&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Mar 19 20:27:44 2018 @@ -4202,7 +4202,9 @@ void Sema::InstantiateVariableInitialize Var->setInvalidDecl(); } } else { - if (Var->isStaticDataMember()) { + // `inline` variables are a definition and declaration all in one; we won't + // pick up an initializer from anywhere else. + if (Var->isStaticDataMember() && !Var->isInline()) { if (!Var->isOutOfLine()) return; Modified: cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp?rev=327945&r1=327944&r2=327945&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp (original) +++ cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Mon Mar 19 20:27:44 2018 @@ -111,3 +111,29 @@ int e = d<int>; // CHECK-NOT: __cxa_guard_acquire(i64* @_ZGV1b) // CHECK: call i32 @_Z1fv // CHECK-NOT: __cxa_guard_release(i64* @_ZGV1b) + +namespace PR35599 { +struct Marker1 {}; +struct Marker2 {}; + +template <typename> +struct Foo { + struct Bar { Bar(); }; + inline static Bar bar; +}; + +void run() { + // All we want here are ODR uses. Anything that requires that the type is + // complete is uninteresting. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-value" + Foo<Marker1>::bar; +#pragma clang diagnostic pop + static_cast<void>(Foo<Marker2>::bar); +} + +// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat +// CHECK: call void @_ZN7PR355993FooINS_7Marker1EE3BarC1Ev +// CHECK-LABEL: define {{.*}}global_var_init{{.*}}comdat +// CHECK: call void @_ZN7PR355993FooINS_7Marker2EE3BarC1Ev +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits