adamcz created this revision. adamcz added a reviewer: sammccall. adamcz requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
There was a missing isInvalid() check leading to an attempt to instantiate template with an empty instantiation stack. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D100675 Files: clang/lib/Sema/SemaTemplateDeduction.cpp clang/test/SemaCXX/template-specialization-fatal.cpp Index: clang/test/SemaCXX/template-specialization-fatal.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/template-specialization-fatal.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s +// Verify clang doesn't assert()-fail on template specialization happening after +// fatal error. + +#include "not_found.h" // expected-error {{'not_found.h' file not found}} + +template <class _Tp, class _Up, class = void> +struct __is_core_convertible : public false_type {}; + +template <class _Tp, class _Up> +struct __is_core_convertible<_Tp, _Up, decltype(static_cast<void (*)(_Up)>(0)( + static_cast<_Tp (*)()>(0)()))> : public true_type {}; Index: clang/lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- clang/lib/Sema/SemaTemplateDeduction.cpp +++ clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5466,6 +5466,9 @@ Deduced.end()); Sema::InstantiatingTemplate Inst(S, Info.getLocation(), P2, DeducedArgs, Info); + if (Inst.isInvalid()) + return false; + auto *TST1 = T1->castAs<TemplateSpecializationType>(); bool AtLeastAsSpecialized; S.runWithSufficientStackSpace(Info.getLocation(), [&] {
Index: clang/test/SemaCXX/template-specialization-fatal.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/template-specialization-fatal.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s +// Verify clang doesn't assert()-fail on template specialization happening after +// fatal error. + +#include "not_found.h" // expected-error {{'not_found.h' file not found}} + +template <class _Tp, class _Up, class = void> +struct __is_core_convertible : public false_type {}; + +template <class _Tp, class _Up> +struct __is_core_convertible<_Tp, _Up, decltype(static_cast<void (*)(_Up)>(0)( + static_cast<_Tp (*)()>(0)()))> : public true_type {}; Index: clang/lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- clang/lib/Sema/SemaTemplateDeduction.cpp +++ clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5466,6 +5466,9 @@ Deduced.end()); Sema::InstantiatingTemplate Inst(S, Info.getLocation(), P2, DeducedArgs, Info); + if (Inst.isInvalid()) + return false; + auto *TST1 = T1->castAs<TemplateSpecializationType>(); bool AtLeastAsSpecialized; S.runWithSufficientStackSpace(Info.getLocation(), [&] {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits