[PATCH] D131866: [clang] fix frontend crash in auto type templates
YingChi Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 14 15:09:01 PDT 2022
inclyc updated this revision to Diff 452572.
inclyc added a comment.
.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131866/new/
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,33 @@
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
+namespace outer {
+ template <class... Types> class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+ static const bool value = false;
+};
+
+template<template<typename...> class, typename>
+struct IsTemplateOf : false_type {};
+
+template<class T, template<typename...> class ATemplate>
+concept InitFrom = IsTemplateOf<ATemplate, T>::value;
+
+
+static void buggy_func(
+ const InitFrom<outer::tuple> auto& C // crashed here in #57142
+);
+} // 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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131866.452572.patch
Type: text/x-patch
Size: 1646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220814/6f72c7c4/attachment.bin>
More information about the cfe-commits
mailing list