[llvm-branch-commits] [clang] 200eb1a - Stop ExtractTypeForDeductionGuide from recursing on TypeSourceInfo

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 14 16:36:33 PST 2020


Author: Erich Keane
Date: 2020-12-14T19:35:08-05:00
New Revision: 200eb1abe2a1088a155f47b95dd1d35b3f37afa6

URL: https://github.com/llvm/llvm-project/commit/200eb1abe2a1088a155f47b95dd1d35b3f37afa6
DIFF: https://github.com/llvm/llvm-project/commit/200eb1abe2a1088a155f47b95dd1d35b3f37afa6.diff

LOG: Stop ExtractTypeForDeductionGuide from recursing on TypeSourceInfo

As reported in PR48177, the type-deduction extraction ends up going into
an infinite loop when the type referred to has a recursive definition.
This stops recursing and just substitutes the type-source-info the
TypeLocBuilder identified when transforming the base.

(cherry picked from commit 1c98f984105e552daa83ed8e92c61fba0e401410)

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplate.cpp
    clang/test/AST/deduction-guides.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c05ed0b14e3e..f788cf103503 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1963,8 +1963,7 @@ class ExtractTypeForDeductionGuide
     TypeLocBuilder InnerTLB;
     QualType Transformed =
         TransformType(InnerTLB, OrigDecl->getTypeSourceInfo()->getTypeLoc());
-    TypeSourceInfo *TSI =
-        TransformType(InnerTLB.getTypeSourceInfo(Context, Transformed));
+    TypeSourceInfo *TSI = InnerTLB.getTypeSourceInfo(Context, Transformed);
 
     TypedefNameDecl *Decl = nullptr;
 

diff  --git a/clang/test/AST/deduction-guides.cpp b/clang/test/AST/deduction-guides.cpp
index 0f5293bc063d..3a7f0bf4699e 100644
--- a/clang/test/AST/deduction-guides.cpp
+++ b/clang/test/AST/deduction-guides.cpp
@@ -37,3 +37,43 @@ HasDeductionGuideTypeAlias()->HasDeductionGuideTypeAlias<int>;
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for HasDeductionGuideTypeAlias> 'auto (HasDeductionGuideTypeAlias<T>) -> HasDeductionGuideTypeAlias<T>'
 // CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for HasDeductionGuideTypeAlias> 'auto () -> HasDeductionGuideTypeAlias<int>'
 } // namespace PR46111
+
+
+namespace PR48177 {
+  template <class A> struct Base {
+    using type_alias = A;
+  };
+  template<class T, int S, class A>
+  struct Derived : Base<A> {
+    using type_alias = typename Derived::type_alias;
+    Derived(Derived &&, typename Derived::type_alias const&);
+    Derived(T);
+  };
+
+  template<class T, class A>
+  Derived(T, A) -> Derived<T, 1, A>;
+
+  void init() {
+    Derived d {1,2};
+  }
+} // namespace PR48177
+
+// CHECK: CXXRecordDecl {{.*}} struct Derived
+// CHECK: TypeAliasDecl {{.*}} type_alias 'typename Derived<T, S, A>::type_alias'
+// CHECK-NEXT: DependentNameType {{.*}} 'typename Derived<T, S, A>::type_alias' dependent
+
+// CHECK: CXXRecordDecl {{.*}} struct Derived
+// CHECK: TypeAliasDecl {{.*}} type_alias 'typename Derived<int, 1, int>::type_alias':'int'
+// CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived<int, 1, int>::type_alias' sugar
+// CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base<int>::type_alias' sugar
+// CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
+// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
+// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: BuiltinType {{.*}} 'int'
+
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (Derived<T, S, A> &&, const typename Derived<T, S, A>::type_alias &) -> Derived<T, S, A>'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (T) -> Derived<T, S, A>'
+// CHECK: CXXDeductionGuideDecl {{.*}} implicit <deduction guide for Derived> 'auto (Derived<T, S, A>) -> Derived<T, S, A>'
+// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for Derived> 'auto (T, A) -> Derived<T, 1, A>'
+// CHECK: CXXDeductionGuideDecl {{.*}} <deduction guide for Derived> 'auto (int, int) -> Derived<int, 1, int>'


        


More information about the llvm-branch-commits mailing list