inclyc created this revision. Herald added a project: All. inclyc added reviewers: mizvekov, aaron.ballman. inclyc updated this revision to Diff 452566. inclyc added a comment. inclyc added subscribers: cfe-commits, clang. inclyc published this revision for review. Herald added a project: clang.
improve test case Reported by https://github.com/llvm/llvm-project/issues/57142 In this case, `AutoTypes.FindNodeOrInsertPos` found appropriate `AT` value and should return that directly, however before this patch we assumes that it always get `InsertPos` back and create a new `AT` for it. In fact `InsertPos` is a nullptr, which causes segmentfault. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D131866 Files: clang/lib/AST/ASTContext.cpp clang/test/SemaCXX/sugared-auto.cpp Index: clang/test/SemaCXX/sugared-auto.cpp =================================================================== --- clang/test/SemaCXX/sugared-auto.cpp +++ clang/test/SemaCXX/sugared-auto.cpp @@ -41,3 +41,39 @@ N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}} } // namespace function_basic + +namespace issue57142 { + +// Should not crash here +// Reported by https://github.com/llvm/llvm-project/issues/57142 + + +// Only crashes if `tuple` is defined outside of the buggy namespace with `auto` +namespace outer { + template <class... Types> class tuple; +} // namespace outer + +namespace { +struct false_type { + static const bool value = false; +}; + +struct true_type { + static const bool value = true; +}; + +template<template<typename...> class, typename> +struct IsTemplateOf : false_type {}; + + + +template<class T, template<typename...> class ATemplate> +concept InitFrom = IsTemplateOf<ATemplate, T>::value; + + +static void Import( + const InitFrom<outer::tuple> auto& C // before this patch clang crashes here +); +} // namespace + +} // namespace issue57142 Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -5732,7 +5732,8 @@ Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack, TypeConstraintConcept, CanonArgs, true); // Find the insert position again. - AutoTypes.FindNodeOrInsertPos(ID, InsertPos); + if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) + return QualType(AT, 0); } } else { Canon = DeducedType.getCanonicalType();
Index: clang/test/SemaCXX/sugared-auto.cpp =================================================================== --- clang/test/SemaCXX/sugared-auto.cpp +++ clang/test/SemaCXX/sugared-auto.cpp @@ -41,3 +41,39 @@ N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}} } // namespace function_basic + +namespace issue57142 { + +// Should not crash here +// Reported by https://github.com/llvm/llvm-project/issues/57142 + + +// Only crashes if `tuple` is defined outside of the buggy namespace with `auto` +namespace outer { + template <class... Types> class tuple; +} // namespace outer + +namespace { +struct false_type { + static const bool value = false; +}; + +struct true_type { + static const bool value = true; +}; + +template<template<typename...> class, typename> +struct IsTemplateOf : false_type {}; + + + +template<class T, template<typename...> class ATemplate> +concept InitFrom = IsTemplateOf<ATemplate, T>::value; + + +static void Import( + const InitFrom<outer::tuple> auto& C // before this patch clang crashes here +); +} // namespace + +} // namespace issue57142 Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -5732,7 +5732,8 @@ Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack, TypeConstraintConcept, CanonArgs, true); // Find the insert position again. - AutoTypes.FindNodeOrInsertPos(ID, InsertPos); + if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) + return QualType(AT, 0); } } else { Canon = DeducedType.getCanonicalType();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits