This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG80c1adfd18b5: [clang] Invalidate a non-dependent-type RecordDecl when it has any dependent… (authored by hokein).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D102773/new/ https://reviews.llvm.org/D102773 Files: clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaTemplate/temp_class_spec.cpp Index: clang/test/SemaTemplate/temp_class_spec.cpp =================================================================== --- clang/test/SemaTemplate/temp_class_spec.cpp +++ clang/test/SemaTemplate/temp_class_spec.cpp @@ -375,3 +375,16 @@ Bar() : Foo<Z>() {} }; } // namespace + +namespace Crash { +template<typename T> +class Base {}; + +template<typename T> class Foo; + +template <typename T> +class Foo<int> : public Base<T> {}; // expected-error{{partial specialization of 'Foo' does not use any of its template parameters}} + +// verify that getASTRecordLayout doesn't crash on the ClassTemplateSpecializationDecl. +constexpr int s = sizeof(Foo<int>); +} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -2508,6 +2508,14 @@ } } + // Make sure that we don't make an ill-formed AST where the type of the + // Class is non-dependent and its attached base class specifier is an + // dependent type, which violates invariants in many clang code paths (e.g. + // constexpr evaluator). If this case happens (in errory-recovery mode), we + // explicitly mark the Class decl invalid. The diagnostic was already + // emitted. + if (!Class->getTypeForDecl()->isDependentType()) + Class->setInvalidDecl(); return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual, Class->getTagKind() == TTK_Class, Access, TInfo, EllipsisLoc);
Index: clang/test/SemaTemplate/temp_class_spec.cpp =================================================================== --- clang/test/SemaTemplate/temp_class_spec.cpp +++ clang/test/SemaTemplate/temp_class_spec.cpp @@ -375,3 +375,16 @@ Bar() : Foo<Z>() {} }; } // namespace + +namespace Crash { +template<typename T> +class Base {}; + +template<typename T> class Foo; + +template <typename T> +class Foo<int> : public Base<T> {}; // expected-error{{partial specialization of 'Foo' does not use any of its template parameters}} + +// verify that getASTRecordLayout doesn't crash on the ClassTemplateSpecializationDecl. +constexpr int s = sizeof(Foo<int>); +} Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -2508,6 +2508,14 @@ } } + // Make sure that we don't make an ill-formed AST where the type of the + // Class is non-dependent and its attached base class specifier is an + // dependent type, which violates invariants in many clang code paths (e.g. + // constexpr evaluator). If this case happens (in errory-recovery mode), we + // explicitly mark the Class decl invalid. The diagnostic was already + // emitted. + if (!Class->getTypeForDecl()->isDependentType()) + Class->setInvalidDecl(); return new (Context) CXXBaseSpecifier(SpecifierRange, Virtual, Class->getTagKind() == TTK_Class, Access, TInfo, EllipsisLoc);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits