Skip to content

Commit 4c44c91

Browse files
committed
[clang] Instantiate alias templates with sugar
This makes use of the changes introduced in D134604, in order to instantiate alias templates witn a final sugared substitution. This comes at no additional relevant cost. Since we don't track / unique them in specializations, we wouldn't be able to resugar them later anyway. Signed-off-by: Matheus Izvekov <[email protected]> Differential Revision: https://reviews.llvm.org/D136565
1 parent 2560c12 commit 4c44c91

File tree

11 files changed

+39
-64
lines changed

11 files changed

+39
-64
lines changed

clang-tools-extra/clangd/unittests/HoverTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ class Foo final {})cpp";
10671067
HI.LocalScope = "";
10681068
HI.Kind = index::SymbolKind::TypeAlias;
10691069
HI.Definition = "template <typename T> using AA = A<T>";
1070-
HI.Type = {"A<T>", "type-parameter-0-0"}; // FIXME: should be 'T'
1070+
HI.Type = {"A<T>", "T"};
10711071
HI.TemplateParameters = {{{"typename"}, std::string("T"), llvm::None}};
10721072
}},
10731073
{// Constant array

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,8 +3854,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
38543854

38553855
// Only substitute for the innermost template argument list.
38563856
MultiLevelTemplateArgumentList TemplateArgLists;
3857-
TemplateArgLists.addOuterTemplateArguments(Template, CanonicalConverted,
3858-
/*Final=*/false);
3857+
TemplateArgLists.addOuterTemplateArguments(Template, SugaredConverted,
3858+
/*Final=*/true);
38593859
TemplateArgLists.addOuterRetainedLevels(
38603860
AliasTemplate->getTemplateParameters()->getDepth());
38613861

clang/test/AST/ast-dump-template-decls.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,47 +120,31 @@ using type2 = typename C<int>::type1<void>;
120120
// CHECK-NEXT: TemplateArgument type 'void'
121121
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
122122
// CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
123-
// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
124-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
125123
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
126124
// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
127125
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
128126
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
129127
} // namespace PR55886
130128

131129
namespace PR56099 {
132-
template <typename... As> struct Y;
133-
template <typename... Bs> using Z = Y<Bs...>;
134-
template <typename... Cs> struct foo {
135-
template <typename... Ds> using bind = Z<Ds..., Cs...>;
136-
};
137-
using t1 = foo<int, short>::bind<char, float>;
138-
// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'Y<char, float, int, short>' sugar Y
139-
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... Bs pack_index 3
140-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
141-
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... Bs pack_index 2
142-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
143-
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... Bs pack_index 1
144-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
145-
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... Bs pack_index 0
146-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
147-
148130
template <typename... T> struct D {
149-
template <typename... U> using B = int(int (*...p)(T, U));
131+
template <typename... U> struct bind {
132+
using bound_type = int(int (*...p)(T, U));
133+
};
150134
};
151-
using t2 = D<float, char>::B<int, short>;
152-
// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'B<int, short>' sugar alias B
135+
template struct D<float, char>::bind<int, short>;
136+
// CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[1-9]+}}:5, col:45> col:11 bound_type 'int (int (*)(float, int), int (*)(char, short))'
153137
// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int (*)(char, short))' cdecl
154138
// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (float, int)' cdecl
155139
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... T pack_index 1
156140
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
157141
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... U pack_index 1
158-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
142+
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'bind'
159143
// CHECK: FunctionProtoType 0x{{[^ ]*}} 'int (char, short)' cdecl
160144
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... T pack_index 0
161145
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
162146
// CHECK: SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... U pack_index 0
163-
// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
147+
// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'bind'
164148
} // namespace PR56099
165149

166150
namespace subst_default_argument {
@@ -171,10 +155,8 @@ template<class E1, class E2> class E {};
171155
using test1 = D<E, int>;
172156
// CHECK: TypeAliasDecl 0x{{[^ ]*}} <line:{{[1-9]+}}:1, col:23> col:7 test1 'D<subst_default_argument::E, int>':'subst_default_argument::E<int, subst_default_argument::A<int>>'
173157
// CHECK: TemplateSpecializationType 0x{{[^ ]*}} 'A<int>' sugar A
174-
// CHECK-NEXT: |-TemplateArgument type 'int':'int'
175-
// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 1 D2
176-
// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[^ ]*}} 'D'
177-
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
158+
// CHECK-NEXT: |-TemplateArgument type 'int'
159+
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
178160
// CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A<int>'
179161
// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
180162
} // namespace subst_default_argument

clang/test/CXX/temp/temp.deduct.guide/p3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template<template<typename> typename TT> struct E { // expected-note 2{{template
3333
};
3434

3535
A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}}
36-
template<typename T> A(T) -> B<T>; // expected-error {{deduced type 'B<T>' (aka 'A<type-parameter-0-0>') of deduction guide is not written as a specialization of template 'A'}}
36+
template <typename T> A(T)->B<T>; // expected-error {{deduced type 'B<T>' (aka 'A<T>') of deduction guide is not written as a specialization of template 'A'}}
3737
template<typename T> A(T*) -> const A<T>; // expected-error {{deduced type 'const A<T>' of deduction guide is not a specialization of template 'A'}}
3838

3939
// A deduction-guide shall be declared in the same scope as the corresponding

clang/test/Misc/diag-template-diffing.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,22 @@ int f9(S9<int, char, U9<const double>>);
257257
int k9 = f9(V9<double>());
258258

259259
// CHECK-ELIDE-NOTREE: no matching function for call to 'f9'
260-
// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<[2 * ...], S9<[2 * ...], double>>' to 'S9<[2 * ...], S9<[2 * ...], const double>>' for 1st argument
260+
// CHECK-ELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<[2 * ...], U9<double>>' to 'S9<[2 * ...], U9<const double>>' for 1st argument
261261
// CHECK-NOELIDE-NOTREE: no matching function for call to 'f9'
262-
// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<int, char, S9<int, char, double>>' to 'S9<int, char, S9<int, char, const double>>' for 1st argument
262+
// CHECK-NOELIDE-NOTREE: candidate function not viable: no known conversion from 'S9<int, char, U9<double>>' to 'S9<int, char, U9<const double>>' for 1st argument
263263
// CHECK-ELIDE-TREE: no matching function for call to 'f9'
264264
// CHECK-ELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
265265
// CHECK-ELIDE-TREE: S9<
266-
// CHECK-ELIDE-TREE: [2 * ...],
267-
// CHECK-ELIDE-TREE: S9<
268-
// CHECK-ELIDE-TREE: [2 * ...],
269-
// CHECK-ELIDE-TREE: [double != const double]>>
266+
// CHECK-ELIDE-TREE: [2 * ...],
267+
// CHECK-ELIDE-TREE: U9<
268+
// CHECK-ELIDE-TREE: [(no qualifiers) != const] double>>
270269
// CHECK-NOELIDE-TREE: no matching function for call to 'f9'
271270
// CHECK-NOELIDE-TREE: candidate function not viable: no known conversion from argument type to parameter type for 1st argument
272271
// CHECK-NOELIDE-TREE: S9<
273-
// CHECK-NOELIDE-TREE: int,
274-
// CHECK-NOELIDE-TREE: char,
275-
// CHECK-NOELIDE-TREE: S9<
276-
// CHECK-NOELIDE-TREE: int,
277-
// CHECK-NOELIDE-TREE: char,
278-
// CHECK-NOELIDE-TREE: [double != const double]>>
272+
// CHECK-NOELIDE-TREE: int,
273+
// CHECK-NOELIDE-TREE: char,
274+
// CHECK-NOELIDE-TREE: U9<
275+
// CHECK-NOELIDE-TREE: [(no qualifiers) != const] double>>
279276

280277
template<typename ...A> class class_types {};
281278
void set10(class_types<int, int>) {}

clang/test/SemaCXX/sizeless-1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void template_fn_rvalue_ref(T &&) {}
325325

326326
#if __cplusplus >= 201103L
327327
template <typename T>
328-
using array_alias = T[1]; // expected-error {{array has sizeless element type '__SVInt8_t'}}
328+
using array_alias = T[1]; // expected-error {{array has sizeless element type 'svint8_t' (aka '__SVInt8_t')}}
329329
extern array_alias<int> *array_alias_int_ptr;
330330
extern array_alias<svint8_t> *array_alias_int8_ptr; // expected-note {{in instantiation of template type alias 'array_alias' requested here}}
331331
#endif

clang/test/SemaTemplate/make_integer_seq.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,27 @@ using test2 = B<int, 1>;
3737
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, 1>' sugar
3838
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, 1>' sugar alias __make_integer_seq
3939
// CHECK-NEXT: |-TemplateArgument template A
40-
// CHECK-NEXT: |-TemplateArgument type 'int':'int'
41-
// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar class depth 0 index 0 B1
42-
// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[0-9A-Fa-f]+}} 'B'
43-
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
40+
// CHECK-NEXT: |-TemplateArgument type 'int'
41+
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
4442
// CHECK-NEXT: |-TemplateArgument expr
4543
// CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}} <line:26:64> 'int'
4644
// CHECK-NEXT: | |-value: Int 1
4745
// CHECK-NEXT: | `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}} <col:64> 'int'
4846
// CHECK-NEXT: | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}} <col:21, col:24> col:24 referenced 'B1' depth 0 index 1 B2
4947
// CHECK-NEXT: | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:64> 'int' 1
5048
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A<int, 0>' sugar A
51-
// CHECK-NEXT: |-TemplateArgument type 'int':'int'
52-
// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar class depth 0 index 0 B1
53-
// CHECK-NEXT: | |-TypeAliasTemplate 0x{{[0-9A-Fa-f]+}} 'B'
54-
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
49+
// CHECK-NEXT: |-TemplateArgument type 'int'
50+
// CHECK-NEXT: | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
5551
// CHECK-NEXT: |-TemplateArgument expr
5652
// CHECK-NEXT: | `-ConstantExpr 0x{{[0-9A-Fa-f]+}} <col:64> 'int'
5753
// CHECK-NEXT: | |-value: Int 0
58-
// CHECK-NEXT: | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:64> 'int':'int' 0
54+
// CHECK-NEXT: | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:64> 'int' 0
5955
// CHECK-NEXT: `-RecordType 0x{{[0-9A-Fa-f]+}} 'A<int, 0>'
6056
// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
6157

6258
template <template <class T, T...> class S, class T, int N> struct C {
6359
using test3 = __make_integer_seq<S, T, N>;
64-
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:63:3, col:43> col:9 test3 '__make_integer_seq<S, T, N>':'__make_integer_seq<type-parameter-0-1, N>'
60+
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:59:3, col:43> col:9 test3 '__make_integer_seq<S, T, N>':'__make_integer_seq<type-parameter-0-1, N>'
6561
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<S, T, N>' sugar dependent
6662
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<S, T, N>' sugar dependent alias __make_integer_seq
6763
// CHECK-NEXT: |-TemplateArgument template S
@@ -80,7 +76,7 @@ template <template <class T, T...> class S, class T, int N> struct C {
8076
// CHECK-NEXT: `-DeclRefExpr 0x{{[0-9A-Fa-f]+}} <col:42> 'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
8177

8278
using test4 = __make_integer_seq<A, T, 1>;
83-
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:82:3, col:43> col:9 test4 '__make_integer_seq<A, T, 1>':'__make_integer_seq<A, type-parameter-0-1, 1>'
79+
// CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:78:3, col:43> col:9 test4 '__make_integer_seq<A, T, 1>':'__make_integer_seq<A, type-parameter-0-1, 1>'
8480
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, T, 1>' sugar dependent
8581
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, T, 1>' sugar dependent alias __make_integer_seq
8682
// CHECK-NEXT: |-TemplateArgument template A
@@ -99,7 +95,7 @@ template <template <class T, T...> class S, class T, int N> struct C {
9995
// CHECK-NEXT: `-IntegerLiteral 0x{{[0-9A-Fa-f]+}} <col:42> 'int' 1
10096

10197
using test5 = __make_integer_seq<A, int, N>;
102-
// CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:101:3, col:45> col:9 test5 '__make_integer_seq<A, int, N>':'__make_integer_seq<A, int, N>'
98+
// CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <line:97:3, col:45> col:9 test5 '__make_integer_seq<A, int, N>':'__make_integer_seq<A, int, N>'
10399
// CHECK-NEXT: `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, N>' sugar dependent
104100
// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq<A, int, N>' sugar dependent alias __make_integer_seq
105101
// CHECK-NEXT: |-TemplateArgument template A

clang/test/SemaTemplate/temp_arg_nontype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ namespace dependent_nested_partial_specialization {
437437

438438
template<template<typename> class X> struct A {
439439
template<typename T, X<T> N> struct B; // expected-note 2{{here}}
440-
template<typename T> struct B<T, 0> {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y<T>' (aka 'type-parameter-0-0 *')}}
440+
template <typename T> struct B<T, 0> {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y<T>' (aka 'T *')}}
441441
};
442442
A<X>::B<int, 0> ax;
443443
A<Y>::B<int, &n> ay; // expected-error {{undefined}} expected-note {{instantiation of}}

lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test(self):
2424
result_type="std::shared_ptr<int>",
2525
result_summary="3 strong=1 weak=1",
2626
result_children=[ValueCheck(name="__ptr_")])
27-
self.expect_expr("*s", result_type="int", result_value="3")
28-
self.expect_expr("*s = 5", result_type="int", result_value="5")
29-
self.expect_expr("*s", result_type="int", result_value="5")
27+
self.expect_expr("*s", result_type="element_type", result_value="3")
28+
self.expect_expr("*s = 5", result_type="element_type", result_value="5")
29+
self.expect_expr("*s", result_type="element_type", result_value="5")
3030
self.expect_expr("(bool)s", result_type="bool", result_value="true")
3131
self.expect("expr s.reset()")
3232
self.expect_expr("(bool)s", result_type="bool", result_value="false")

lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test(self):
2323
self.expect_expr("w",
2424
result_type="std::weak_ptr<Foo>",
2525
result_children=[ValueCheck(name="__ptr_")])
26-
self.expect_expr("*w.lock()", result_type="Foo")
26+
self.expect_expr("*w.lock()", result_type="element_type")
2727
self.expect_expr("w.lock()->a", result_type="int", result_value="3")
2828
self.expect_expr("w.lock()->a = 5",
2929
result_type="int",

lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test(self):
2424
result_type="std::weak_ptr<int>",
2525
result_summary="3 strong=1 weak=2",
2626
result_children=[ValueCheck(name="__ptr_")])
27-
self.expect_expr("*w.lock()", result_type="int", result_value="3")
28-
self.expect_expr("*w.lock() = 5", result_type="int", result_value="5")
29-
self.expect_expr("*w.lock()", result_type="int", result_value="5")
27+
self.expect_expr("*w.lock()", result_type="element_type", result_value="3")
28+
self.expect_expr("*w.lock() = 5", result_type="element_type", result_value="5")
29+
self.expect_expr("*w.lock()", result_type="element_type", result_value="5")
3030
self.expect_expr("w.use_count()", result_type="long", result_value="1")
3131
self.expect("expr w.reset()")
3232
self.expect_expr("w.use_count()", result_type="long", result_value="0")

0 commit comments

Comments
 (0)