|
| 1 | +[1mdiff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp[m |
| 2 | +[1mindex 6c93afdfaa81..e36bfeab7b49 100644[m |
| 3 | +[1m--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp[m |
| 4 | +[1m+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp[m |
| 5 | +[36m@@ -330,7 +330,7 @@[m [mstruct TemplateParameterListBuilder {[m |
| 6 | + // matches the CSE that is constructed when parsing the below C++ code:[m |
| 7 | + //[m |
| 8 | + // template<typename T>[m |
| 9 | +[31m- // concept is_typed_resource_element_compatible = sizeof(T) <= 16;[m |
| 10 | +[32m+[m[32m // concept is_typed_resource_element_compatible = __builtin_hlsl_typed_resource_element_compatible<T> && !__builtin_hlsl_is_intangible<T>[m |
| 11 | + // template<typename element_type> requires[m |
| 12 | + // is_typed_resource_element_compatible<element_type>[m |
| 13 | + // struct RWBuffer {[m |
| 14 | +[36m@@ -568,11 +568,11 @@[m [mstatic BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,[m |
| 15 | + .addDefaultHandleConstructor(S);[m |
| 16 | + }[m |
| 17 | + [m |
| 18 | +[31m-BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context,[m |
| 19 | +[32m+[m[32mBinaryOperator *constructTypedResourceConstraintExpr(ASTContext &Context,[m |
| 20 | + SourceLocation NameLoc,[m |
| 21 | + TemplateTypeParmDecl *T) {[m |
| 22 | + // Obtain the QualType for 'unsigned long'[m |
| 23 | +[31m- QualType UnsignedLongType = Context.UnsignedLongTy;[m |
| 24 | +[32m+[m[32m QualType BoolTy = Context.BoolTy;[m |
| 25 | + [m |
| 26 | + // Create a QualType that points to this TemplateTypeParmDecl[m |
| 27 | + QualType TType = Context.getTypeDeclType(T);[m |
| 28 | +[36m@@ -581,21 +581,22 @@[m [mBinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context,[m |
| 29 | + TypeSourceInfo *TTypeSourceInfo =[m |
| 30 | + Context.getTrivialTypeSourceInfo(TType, NameLoc);[m |
| 31 | + [m |
| 32 | +[31m- UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr([m |
| 33 | +[31m- UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc);[m |
| 34 | +[32m+[m[32m TypeTraitExpr *TypedResExpr = TypeTraitExpr::Create([m |
| 35 | +[32m+[m[32m Context, BoolTy, NameLoc, UTT_IsTypedResourceElementCompatible,[m |
| 36 | +[32m+[m[32m {TTypeSourceInfo}, NameLoc, true);[m |
| 37 | + [m |
| 38 | +[31m- // Create an IntegerLiteral for the value '16' with size type[m |
| 39 | +[31m- QualType SizeType = Context.getSizeType();[m |
| 40 | +[31m- llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16);[m |
| 41 | +[31m- IntegerLiteral *SizeLiteral =[m |
| 42 | +[31m- new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc);[m |
| 43 | +[32m+[m[32m TypeTraitExpr *IsIntangibleExpr =[m |
| 44 | +[32m+[m[32m TypeTraitExpr::Create(Context, BoolTy, NameLoc, UTT_IsIntangibleType,[m |
| 45 | +[32m+[m[32m {TTypeSourceInfo}, NameLoc, true);[m |
| 46 | + [m |
| 47 | +[31m- QualType BoolTy = Context.BoolTy;[m |
| 48 | +[32m+[m[32m UnaryOperator *NotIntangibleExpr = UnaryOperator::Create([m |
| 49 | +[32m+[m[32m Context, IsIntangibleExpr, UO_Not, BoolTy, VK_LValue, OK_Ordinary,[m |
| 50 | +[32m+[m[32m NameLoc, false, FPOptionsOverride());[m |
| 51 | + [m |
| 52 | + BinaryOperator *binaryOperator =[m |
| 53 | +[31m- BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression[m |
| 54 | +[31m- SizeLiteral, // Right-hand side expression[m |
| 55 | +[31m- BO_LE, // Binary operator kind (<=)[m |
| 56 | +[32m+[m[32m BinaryOperator::Create(Context, TypedResExpr, // Left-hand side expression[m |
| 57 | +[32m+[m[32m NotIntangibleExpr, // Right-hand side expression[m |
| 58 | +[32m+[m[32m BO_LAnd, // Binary operator kind (&&)[m |
| 59 | + BoolTy, // Result type (bool)[m |
| 60 | + VK_LValue, // Value kind[m |
| 61 | + OK_Ordinary, // Object kind[m |
| 62 | +[36m@@ -609,13 +610,10 @@[m [mExpr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,[m |
| 63 | + TemplateTypeParmDecl *T) {[m |
| 64 | + ASTContext &Context = S.getASTContext();[m |
| 65 | + [m |
| 66 | +[31m- // first get the "sizeof(T) <= 16" expression, as a binary operator[m |
| 67 | +[31m- BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T);[m |
| 68 | +[31m- // TODO: add the 'builtin_hlsl_is_typed_resource_element_compatible' builtin[m |
| 69 | +[31m- // and return a binary operator that evaluates the builtin on the given[m |
| 70 | +[31m- // template type parameter 'T'.[m |
| 71 | +[31m- // Defined in issue https://github.com/llvm/llvm-project/issues/113223[m |
| 72 | +[31m- return SizeOfLEQ16;[m |
| 73 | +[32m+[m[32m BinaryOperator *TypedResourceConstraintExpr =[m |
| 74 | +[32m+[m[32m constructTypedResourceConstraintExpr(Context, NameLoc, T);[m |
| 75 | +[32m+[m |
| 76 | +[32m+[m[32m return TypedResourceConstraintExpr;[m |
| 77 | + }[m |
| 78 | + [m |
| 79 | + ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD) {[m |
| 80 | +[1mdiff --git a/clang/test/AST/HLSL/is_typed_resource_element_compatible_concept.hlsl b/clang/test/AST/HLSL/is_typed_resource_element_compatible_concept.hlsl[m |
| 81 | +[1mindex 414ed6eb8212..362ce96e808f 100644[m |
| 82 | +[1m--- a/clang/test/AST/HLSL/is_typed_resource_element_compatible_concept.hlsl[m |
| 83 | +[1m+++ b/clang/test/AST/HLSL/is_typed_resource_element_compatible_concept.hlsl[m |
| 84 | +[36m@@ -2,9 +2,13 @@[m |
| 85 | + [m |
| 86 | + // CHECK: ConceptDecl 0x{{[0-9a-f]+}} <<invalid sloc>> <invalid sloc> __is_typed_resource_element_compatible[m |
| 87 | + // CHECK: |-TemplateTypeParmDecl 0x{{[0-9a-f]+}} <<invalid sloc>> <invalid sloc> referenced typename depth 0 index 0 element_type[m |
| 88 | +[31m-// CHECK: `-BinaryOperator 0x{{[0-9a-f]+}} <<invalid sloc>> 'bool' lvalue '<='[m |
| 89 | +[31m-// CHECK: |-UnaryExprOrTypeTraitExpr 0x{{[0-9a-f]+}} <<invalid sloc>> 'unsigned long' sizeof 'element_type'[m |
| 90 | +[31m-// CHECK: `-IntegerLiteral 0x{{[0-9a-f]+}} <<invalid sloc>> 'unsigned long' 16[m |
| 91 | +[31m-[m |
| 92 | +[32m+[m[32m// CHECK: `-BinaryOperator 0x{{[0-9a-f]+}} <<invalid sloc>> 'bool' lvalue '&&'[m[41m[m |
| 93 | +[32m+[m[32m// CHECK: |-TypeTraitExpr 0x{{[0-9a-f]+}} <<invalid sloc>> 'bool' __builtin_hlsl_is_typed_resource_element_compatible[m[41m[m |
| 94 | +[32m+[m[32m// CHECK: `-TemplateTypeParmType 0x{{[0-9a-f]+}} 'element_type' dependent depth 0 index 0[m[41m[m |
| 95 | +[32m+[m[32m// CHECK: `-TemplateTypeParm 0x{{[0-9a-f]+}} 'element_type'[m[41m[m |
| 96 | +[32m+[m[32m// CHECK: `-UnaryOperator 0x{{[0-9a-f]+}} <<invalid sloc>> 'bool' lvalue prefix '~' cannot overflow[m[41m[m |
| 97 | +[32m+[m[32m// CHECK: `-TypeTraitExpr 0x{{[0-9a-f]+}} <<invalid sloc>> 'bool' __builtin_hlsl_is_intangible[m[41m[m |
| 98 | +[32m+[m[32m// CHECK: `-TemplateTypeParmType 0x{{[0-9a-f]+}} 'element_type' dependent depth 0 index 0[m[41m[m |
| 99 | +[32m+[m[32m// CHECK: `-TemplateTypeParm 0x{{[0-9a-f]+}} 'element_type'[m[41m[m |
| 100 | + [m |
| 101 | + RWBuffer<float> Buffer;[m |
| 102 | +[1mdiff --git a/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl b/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl[m |
| 103 | +[1mindex 438f8021f96a..8d018bacea7f 100644[m |
| 104 | +[1m--- a/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl[m |
| 105 | +[1m+++ b/clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl[m |
| 106 | +[36m@@ -1,16 +1,79 @@[m |
| 107 | + // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify %s[m |
| 108 | + [m |
| 109 | + typedef vector<float, 3> float3;[m |
| 110 | +[32m+[m[32mtypedef vector<double, 2> double2;[m |
| 111 | +[32m+[m[32mtypedef vector<double, 3> double3;[m |
| 112 | + [m |
| 113 | +[31m-RWBuffer<float3> Buffer;[m |
| 114 | + [m |
| 115 | +[31m-// expected-error@+2 {{class template 'RWBuffer' requires template arguments}}[m |
| 116 | +[31m-// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class RWBuffer {}}}[m |
| 117 | +[31m-RWBuffer BufferErr1;[m |
| 118 | +[32m+[m[32m// expected-error@+4 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 119 | +[32m+[m[32m// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class RWBuffer}}[m |
| 120 | +[32m+[m[32m// expected-note@*:* {{because 'hlsl::RWBuffer<int>' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 121 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(hlsl::RWBuffer<int>)' evaluated to false}}[m |
| 122 | +[32m+[m[32mRWBuffer<RWBuffer<int> > r5;[m |
| 123 | +[32m+[m |
| 124 | +[32m+[m[32mstruct s {[m |
| 125 | +[32m+[m[32m int x;[m |
| 126 | +[32m+[m[32m};[m |
| 127 | +[32m+[m |
| 128 | +[32m+[m[32mstruct Empty {};[m |
| 129 | +[32m+[m |
| 130 | +[32m+[m[32mtemplate<typename T> struct TemplatedBuffer {[m |
| 131 | +[32m+[m[32m T a;[m |
| 132 | +[32m+[m[32m};[m |
| 133 | +[32m+[m |
| 134 | +[32m+[m[32mtemplate<typename T> struct TemplatedVector {[m |
| 135 | +[32m+[m[32m vector<T, 4> v;[m |
| 136 | +[32m+[m[32m};[m |
| 137 | +[32m+[m |
| 138 | +[32m+[m |
| 139 | +[32m+[m[32m// expected-error@+4 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 140 | +[32m+[m[32m// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class RWBuffer}}[m |
| 141 | +[32m+[m[32m// expected-note@*:* {{because 'TemplatedBuffer<int>' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 142 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(TemplatedBuffer<int>)' evaluated to false}}[m |
| 143 | +[32m+[m[32mRWBuffer<TemplatedBuffer<int> > r8;[m |
| 144 | +[32m+[m[32m// expected-error@+4 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 145 | +[32m+[m[32m// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class RWBuffer}}[m |
| 146 | +[32m+[m[32m// expected-note@*:* {{because 'TemplatedVector<int>' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 147 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(TemplatedVector<int>)' evaluated to false}}[m |
| 148 | +[32m+[m[32mRWBuffer<TemplatedVector<int> > r9;[m |
| 149 | +[32m+[m |
| 150 | +[32m+[m[32m// arrays not allowed[m |
| 151 | +[32m+[m[32m// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 152 | +[32m+[m[32m// expected-note@*:* {{because 'half[4]' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 153 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(__fp16[4])' evaluated to false}}[m |
| 154 | +[32m+[m[32mRWBuffer<half[4]> r10;[m |
| 155 | +[32m+[m |
| 156 | +[32m+[m[32mtypedef vector<int, 8> int8;[m |
| 157 | +[32m+[m[32m// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 158 | +[32m+[m[32m// expected-note@*:* {{because 'vector<int, 8>' (vector of 8 'int' values) does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 159 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(int __attribute__((ext_vector_type(8))))' evaluated to false}}[m |
| 160 | +[32m+[m[32mRWBuffer<int8> r11;[m |
| 161 | +[32m+[m |
| 162 | +[32m+[m[32mtypedef int MyInt;[m |
| 163 | +[32m+[m[32mRWBuffer<MyInt> r12;[m |
| 164 | +[32m+[m |
| 165 | +[32m+[m[32m// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 166 | +[32m+[m[32m// expected-note@*:* {{because 'bool' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 167 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(_Bool)' evaluated to false}}[m |
| 168 | +[32m+[m[32mRWBuffer<bool> r13;[m |
| 169 | +[32m+[m |
| 170 | +[32m+[m[32m// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 171 | +[32m+[m[32m// expected-note@*:* {{because 'vector<bool, 2>' (vector of 2 'bool' values) does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 172 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(_Bool __attribute__((ext_vector_type(2))))' evaluated to false}}[m |
| 173 | +[32m+[m[32mRWBuffer<vector<bool, 2>> r14;[m |
| 174 | +[32m+[m |
| 175 | +[32m+[m[32menum numbers { one, two, three };[m |
| 176 | +[32m+[m |
| 177 | +[32m+[m[32m// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 178 | +[32m+[m[32m// expected-note@*:* {{because 'numbers' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 179 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(numbers)' evaluated to false}}[m |
| 180 | +[32m+[m[32mRWBuffer<numbers> r15;[m |
| 181 | +[32m+[m |
| 182 | +[32m+[m[32m// expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 183 | +[32m+[m[32m// expected-note@*:* {{because 'vector<double, 3>' (vector of 3 'double' values) does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 184 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(double __attribute__((ext_vector_type(3))))' evaluated to false}}[m |
| 185 | +[32m+[m[32mRWBuffer<double3> r16;[m |
| 186 | + [m |
| 187 | +[31m-// expected-error@+2 {{too few template arguments for class template 'RWBuffer'}}[m |
| 188 | +[31m-// expected-note@*:* {{template declaration from hidden source: template <typename element_type> requires __is_typed_resource_element_compatible<element_type> class RWBuffer {}}}[m |
| 189 | +[31m-RWBuffer<> BufferErr2;[m |
| 190 | + [m |
| 191 | + struct threeDoubles {[m |
| 192 | + double a;[m |
| 193 | +[36m@@ -20,7 +83,7 @@[m [mstruct threeDoubles {[m |
| 194 | + [m |
| 195 | + // expected-error@+3 {{constraints not satisfied for class template 'RWBuffer'}}[m |
| 196 | + // expected-note@*:* {{because 'threeDoubles' does not satisfy '__is_typed_resource_element_compatible'}}[m |
| 197 | +[31m-// expected-note@*:* {{because 'sizeof(threeDoubles) <= 16UL' (24 <= 16) evaluated to false}}[m |
| 198 | +[32m+[m[32m// expected-note@*:* {{because '__builtin_hlsl_is_typed_resource_element_compatible(threeDoubles)' evaluated to false}}[m |
| 199 | + RWBuffer<threeDoubles> BufferErr3;[m |
| 200 | + [m |
| 201 | + [m |
| 202 | +[1mdiff --git a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl[m |
| 203 | +[1mindex d3d79aa0499e..cb3e9ae7a615 100644[m |
| 204 | +[1m--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl[m |
| 205 | +[1m+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl[m |
| 206 | +[36m@@ -1,9 +1,10 @@[m |
| 207 | + // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -fnative-half-type -verify %s[m |
| 208 | + [m |
| 209 | + // types must be complete[m |
| 210 | +[31m-_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resource_t), "");[m |
| 211 | +[32m+[m[32m_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resource_t), "");[m[41m[m |
| 212 | + [m |
| 213 | + // expected-note@+1{{forward declaration of 'notComplete'}}[m |
| 214 | + struct notComplete;[m |
| 215 | + // expected-error@+1{{incomplete type 'notComplete' where a complete type is required}}[m |
| 216 | + _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notComplete), "");[m |
| 217 | +[41m+ [m |
|
0 commit comments