[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 14:59:32 PDT 2022


inclyc updated this revision to Diff 452569.
inclyc added a comment.

update comments


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,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
+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 buggy_func(
+    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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131866.452569.patch
Type: text/x-patch
Size: 1725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220814/7198d8f0/attachment-0001.bin>


More information about the cfe-commits mailing list