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();


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();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to