Skip to content

Commit 5a560b3

Browse files
authored
Revert "[Clang] Preserve more sugars in constraint evaluation" (llvm#163322)
Reverts llvm#162991 That patch breaks certain uses of VLAs when combined with constrained types. This is a pre-existing issue that occurs when concepts are instantiated with sugar. See also llvm#102353 and related PRs. I tried to fix it on top of the status quo in llvm#163167, but that approach turned out to be unfeasible, and our maintainer was clearly unhappy with it, hence this revert. Even after this patch, some VLA uses remain broken on trunk (see the example below), because our normalization patch depends on sugar to correctly compile libc++, due to a very subtle underlying bug. Still, this is the best attempt to mitigate the problem for now. We discussed this and agreed that the long-term solution is to remove the sugar dependencies from concepts, before the VLA issue is properly resolved through a larger refactoring. I'll add a related test (which passes with partially applied sugar) after this revert, since I don't have a reduced example yet.
1 parent 401308f commit 5a560b3

File tree

8 files changed

+19
-18
lines changed

8 files changed

+19
-18
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
614614
for (unsigned I = 0, MappedIndex = 0; I < Used.size(); I++) {
615615
TemplateArgument Arg;
616616
if (Used[I])
617-
Arg = CTAI.SugaredConverted[MappedIndex++];
617+
Arg = S.Context.getCanonicalTemplateArgument(
618+
CTAI.SugaredConverted[MappedIndex++]);
618619
if (I < SubstitutedOuterMost.size()) {
619620
SubstitutedOuterMost[I] = Arg;
620621
Offset = I + 1;

clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace std_example {
149149
template<typename T> constexpr bool is_same_v<T, T> = true;
150150

151151
template<typename T, typename U> concept same_as = is_same_v<T, U>;
152-
// expected-note@-1 {{because 'is_same_v<int, typename T2::inner>' evaluated to false}}
152+
// expected-note@-1 {{because 'is_same_v<int, typename std_example::T2::inner>' evaluated to false}}
153153

154154
static_assert(C1<int>);
155155
static_assert(C1<int*>);
@@ -160,7 +160,7 @@ namespace std_example {
160160
template<typename T> concept C2 =
161161
requires(T x) {
162162
{*x} -> same_as<typename T::inner>;
163-
// expected-note@-1{{because 'same_as<int, typename T2::inner>' evaluated to false}}
163+
// expected-note@-1{{because 'same_as<int, typename std_example::T2::inner>' evaluated to false}}
164164
// expected-note@-2{{because '*x' would be invalid: indirection requires pointer operand ('int' invalid)}}
165165
};
166166

clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using r4i = X<void>::r4<int>; // expected-error{{constraints not satisfied for c
2727

2828
// C++ [expr.prim.req.nested] Examples
2929
namespace std_example {
30-
template<typename U> concept C1 = sizeof(U) == 1; // expected-note{{because 'sizeof(decltype(+t)) == 1' (4 == 1) evaluated to false}}
30+
template<typename U> concept C1 = sizeof(U) == 1; // expected-note{{because 'sizeof(int) == 1' (4 == 1) evaluated to false}}
3131
template<typename T> concept D =
3232
requires (T t) {
3333
requires C1<decltype (+t)>; // expected-note{{because 'decltype(+t)' (aka 'int') does not satisfy 'C1'}}

clang/test/CXX/temp/temp.param/p10-2a.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ concept OneOf = (is_same_v<T, Ts> || ...); // #OneOf
9595
// expected-note@#OneOf 3{{because 'is_same_v<int, char[1]>' evaluated to false}}
9696
// expected-note@#OneOf 3{{and 'is_same_v<int, char[2]>' evaluated to false}}
9797
// expected-note@#OneOf {{because 'is_same_v<decltype(nullptr), char>' evaluated to false}}
98-
// expected-note@#OneOf {{because 'is_same_v<decltype(nullptr), char>' evaluated to false}}
99-
// expected-note@#OneOf {{and 'is_same_v<decltype(nullptr), int>' evaluated to false}}
98+
// expected-note@#OneOf {{because 'is_same_v<std::nullptr_t, char>' evaluated to false}}
99+
// expected-note@#OneOf {{and 'is_same_v<std::nullptr_t, int>' evaluated to false}}
100100
// expected-note@#OneOf {{and 'is_same_v<decltype(nullptr), int>' evaluated to false}}
101101

102102
template<OneOf<char[1], char[2]> T, OneOf<int, long, char> U>

clang/test/SemaHLSL/BuiltIns/Buffers.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Buffer<double2> r4;
2020
// expected-error@+4 {{constraints not satisfied for class template 'Buffer'}}
2121
// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class Buffer}}
2222
// expected-note@*:* {{because 'Buffer<int>' does not satisfy '__is_typed_resource_element_compatible'}}
23-
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(Buffer<int>)' evaluated to false}}
23+
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(hlsl::Buffer<int>)' evaluated to false}}
2424
Buffer<Buffer<int> > r5;
2525

2626
struct s {
@@ -66,7 +66,7 @@ Buffer<half[4]> r10;
6666
typedef vector<int, 8> int8;
6767
// expected-error@+3 {{constraints not satisfied for class template 'Buffer'}}
6868
// expected-note@*:* {{because 'int8' (aka 'vector<int, 8>') does not satisfy '__is_typed_resource_element_compatible'}}
69-
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(int8)' evaluated to false}}
69+
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(vector<int, 8>)' evaluated to false}}
7070
Buffer<int8> r11;
7171

7272
typedef int MyInt;
@@ -91,7 +91,7 @@ Buffer<numbers> r15;
9191

9292
// expected-error@+3 {{constraints not satisfied for class template 'Buffer'}}
9393
// expected-note@*:* {{because 'double3' (aka 'vector<double, 3>') does not satisfy '__is_typed_resource_element_compatible'}}
94-
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(double3)' evaluated to false}}
94+
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(vector<double, 3>)' evaluated to false}}
9595
Buffer<double3> r16;
9696

9797

clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RWBuffer<double2> r4;
2020
// expected-error@+4 {{constraints not satisfied for class template 'RWBuffer'}}
2121
// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class RWBuffer}}
2222
// expected-note@*:* {{because 'RWBuffer<int>' does not satisfy '__is_typed_resource_element_compatible'}}
23-
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(RWBuffer<int>)' evaluated to false}}
23+
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(hlsl::RWBuffer<int>)' evaluated to false}}
2424
RWBuffer<RWBuffer<int> > r5;
2525

2626
struct s {
@@ -66,7 +66,7 @@ RWBuffer<half[4]> r10;
6666
typedef vector<int, 8> int8;
6767
// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}
6868
// expected-note@*:* {{because 'int8' (aka 'vector<int, 8>') does not satisfy '__is_typed_resource_element_compatible'}}
69-
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(int8)' evaluated to false}}
69+
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(vector<int, 8>)' evaluated to false}}
7070
RWBuffer<int8> r11;
7171

7272
typedef int MyInt;
@@ -91,7 +91,7 @@ RWBuffer<numbers> r15;
9191

9292
// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}
9393
// expected-note@*:* {{because 'double3' (aka 'vector<double, 3>') does not satisfy '__is_typed_resource_element_compatible'}}
94-
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(double3)' evaluated to false}}
94+
// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(vector<double, 3>)' evaluated to false}}
9595
RWBuffer<double3> r16;
9696

9797

clang/test/SemaTemplate/concepts-recursive-inst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ struct my_range{
6868
void baz() {
6969
auto it = begin(rng); // #BEGIN_CALL
7070
// expected-error-re@#INF_REQ {{satisfaction of constraint {{.*}} depends on itself}}
71-
// expected-note@#INF_BEGIN {{while checking the satisfaction of concept 'Inf<struct my_range>' requested here}}
72-
// expected-note@#INF_BEGIN_EXPR {{while checking constraint satisfaction for template 'begin<struct my_range>' required here}}
71+
// expected-note@#INF_BEGIN {{while checking the satisfaction of concept 'Inf<DirectRecursiveCheck::my_range>' requested here}}
72+
// expected-note@#INF_BEGIN_EXPR {{while checking constraint satisfaction for template 'begin<DirectRecursiveCheck::my_range>' required here}}
7373
// expected-note@#INF_BEGIN_EXPR {{while substituting deduced template arguments into function template 'begin'}}
7474
// expected-note@#INF_BEGIN_EXPR {{in instantiation of requirement here}}
7575
// expected-note@#INF_REQ {{while substituting template arguments into constraint expression here}}

clang/test/SemaTemplate/concepts.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,13 +833,13 @@ struct Parent {
833833
static_assert(Parent<void>::TakesUnary<int, 0>::i == 0);
834834
// expected-error@+3{{constraints not satisfied for class template 'TakesUnary'}}
835835
// expected-note@#UNARY{{because 'decltype(0ULL)' (aka 'unsigned long long') does not satisfy 'C'}}
836-
// expected-note@#61777_C{{because 'sizeof(decltype(0ULL)) == 4' (8 == 4) evaluated to false}}
836+
// expected-note@#61777_C{{because 'sizeof(unsigned long long) == 4' (8 == 4) evaluated to false}}
837837
static_assert(Parent<void>::TakesUnary<int, 0uLL>::i == 0);
838838

839839
static_assert(Parent<int>::TakesBinary<int, 0>::i == 0);
840840
// expected-error@+3{{constraints not satisfied for class template 'TakesBinary'}}
841841
// expected-note@#BINARY{{because 'C2<decltype(0ULL), int>' evaluated to false}}
842-
// expected-note@#61777_C2{{because 'sizeof(decltype(0ULL)) == sizeof(int)' (8 == 4) evaluated to false}}
842+
// expected-note@#61777_C2{{because 'sizeof(unsigned long long) == sizeof(int)' (8 == 4) evaluated to false}}
843843
static_assert(Parent<int>::TakesBinary<int, 0ULL>::i == 0);
844844
}
845845

@@ -1329,8 +1329,8 @@ static_assert(__cpp17_iterator<not_move_constructible>); \
13291329
// expected-error {{static assertion failed}} \
13301330
// expected-note {{because 'not_move_constructible' does not satisfy '__cpp17_iterator'}} \
13311331
// expected-note@#__cpp17_copy_constructible {{because 'not_move_constructible' does not satisfy '__cpp17_copy_constructible'}} \
1332-
// expected-note@#__cpp17_move_constructible {{because 'not_move_constructible' does not satisfy '__cpp17_move_constructible'}} \
1333-
// expected-note@#is_move_constructible_v {{because 'is_move_constructible_v<not_move_constructible>' evaluated to false}}
1332+
// expected-note@#__cpp17_move_constructible {{because 'parameter_mapping_regressions::case3::not_move_constructible' does not satisfy '__cpp17_move_constructible'}} \
1333+
// expected-note@#is_move_constructible_v {{because 'is_move_constructible_v<parameter_mapping_regressions::case3::not_move_constructible>' evaluated to false}}
13341334
}
13351335

13361336
namespace case4 {

0 commit comments

Comments
 (0)