Author: epilk Date: Mon Jul 23 15:47:37 2018 New Revision: 337766 URL: http://llvm.org/viewvc/llvm-project?rev=337766&view=rev Log: [Sema] Fix crash on BlockExprs in a default member initializers
Clang would crash when instantiating a BlockDecl that appeared in a default-member-initializer of a class template. Fix this by deferring the instantiation until we instantate the BlockExpr. rdar://41200624 Differential revision: https://reviews.llvm.org/D49688 Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/test/SemaCXX/instantiate-blocks.cpp Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=337766&r1=337765&r2=337766&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Jul 23 15:47:37 2018 @@ -2083,6 +2083,11 @@ Sema::InstantiateClass(SourceLocation Po if (Member->getDeclContext() != Pattern) continue; + // BlockDecls can appear in a default-member-initializer. They must be the + // child of a BlockExpr, so we only know how to instantiate them from there. + if (isa<BlockDecl>(Member)) + continue; + if (Member->isInvalidDecl()) { Instantiation->setInvalidDecl(); continue; Modified: cfe/trunk/test/SemaCXX/instantiate-blocks.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/instantiate-blocks.cpp?rev=337766&r1=337765&r2=337766&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/instantiate-blocks.cpp (original) +++ cfe/trunk/test/SemaCXX/instantiate-blocks.cpp Mon Jul 23 15:47:37 2018 @@ -30,3 +30,12 @@ int main(void) noret((float)0.0, double(0.0)); // expected-note {{in instantiation of function template specialization 'noret<float, double>' requested here}} } +namespace rdar41200624 { +template <class T> +struct S { + int (^p)() = ^{ return 0; }; + T (^t)() = ^{ return T{}; }; + T s = ^{ return T{}; }(); +}; +S<int> x; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits