Skip to content

Commit 6590576

Browse files
committed
Fix const error check for object subscript operator (#3580)
(cherry picked from commit de00b01)
1 parent 6b8d715 commit 6590576

9 files changed

Lines changed: 313 additions & 114 deletions

tools/clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9460,7 +9460,10 @@ bool CheckForModifiableLvalue(Expr *E, SourceLocation Loc, Sema &S) { // HLSL Ch
94609460
assert(!E->hasPlaceholderType(BuiltinType::PseudoObject));
94619461
// HLSL Change Starts - check const for array subscript operator for HLSL vector/matrix
94629462
if (S.Context.getLangOpts().HLSL && E->getStmtClass() == Stmt::CXXOperatorCallExprClass) {
9463-
// check if it's a vector or matrix
9463+
// check if it's a vector or matrix
9464+
const CXXOperatorCallExpr *expr = cast<CXXOperatorCallExpr>(E);
9465+
QualType qt = expr->getArg(0)->getType();
9466+
if ((hlsl::IsMatrixType(&S, qt) || hlsl::IsVectorType(&S, qt)))
94649467
return HLSLCheckForModifiableLValue(E, Loc, S);
94659468
}
94669469
// HLSL Change Ends

tools/clang/test/HLSL/array-index-out-of-bounds-HV-2016.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
void dead()
44
{
55
int array[2];
6-
array[-1] = 0; /* expected-warning {{array index -1 is before the beginning of the array}} fxc-pass */
6+
array[-1] = 0; /* expected-warning {{array index -1 is before the beginning of the array}} fxc-pass {{}} */
77
array[0] = 0;
88
array[1] = 0;
9-
array[2] = 0; /* expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}} fxc-pass */
9+
array[2] = 0; /* expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}} fxc-pass {{}} */
1010
}
1111

1212
void main() {}

tools/clang/test/HLSL/attributes.hlsl

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// RUN: %clang_cc1 -Wno-unused-value -fsyntax-only -ffreestanding -verify -verify-ignore-unexpected=note %s
22

3-
struct F2 : float2 {}; // expected-error {{base 'vector' is marked 'final'}}
4-
struct F4x4 : float4x4 {}; // expected-error {{base 'matrix' is marked 'final'}}
5-
struct Tex3D : Texture3D<float> {}; // expected-error {{base 'Texture3D' is marked 'final'}}
6-
struct BABuf : ByteAddressBuffer {}; // expected-error {{base 'ByteAddressBuffer' is marked 'final'}}
7-
struct StructBuf : StructuredBuffer<int> {}; // expected-error {{base 'StructuredBuffer' is marked 'final'}}
8-
struct Samp : SamplerState {}; // expected-error {{base 'SamplerState' is marked 'final'}}
3+
struct F2 : float2 {}; // expected-error {{base 'vector' is marked 'final'}} fxc-error {{X3094: base type is not a struct, class or interface}}
4+
struct F4x4 : float4x4 {}; // expected-error {{base 'matrix' is marked 'final'}} fxc-error {{X3094: base type is not a struct, class or interface}}
5+
struct Tex3D : Texture3D<float> {}; // expected-error {{base 'Texture3D' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'Texture3D'}}
6+
struct BABuf : ByteAddressBuffer {}; // expected-error {{base 'ByteAddressBuffer' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'ByteAddressBuffer'}}
7+
struct StructBuf : StructuredBuffer<int> {}; // expected-error {{base 'StructuredBuffer' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'StructuredBuffer'}}
8+
struct Samp : SamplerState {}; // expected-error {{base 'SamplerState' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'SamplerState'}}
99

1010
struct Vertex { float3 pos : POSITION; };
11-
struct GSTS : TriangleStream<Vertex> {}; // expected-error {{base 'TriangleStream' is marked 'final'}}
12-
struct HSIP : InputPatch<Vertex, 16> {}; // expected-error {{base 'InputPatch' is marked 'final'}}
13-
struct HSOP : OutputPatch<Vertex, 16> {}; // expected-error {{base 'OutputPatch' is marked 'final'}}
11+
struct GSTS : TriangleStream<Vertex> {}; // expected-error {{base 'TriangleStream' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'TriangleStream'}}
12+
struct HSIP : InputPatch<Vertex, 16> {}; // expected-error {{base 'InputPatch' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'InputPatch'}}
13+
struct HSOP : OutputPatch<Vertex, 16> {}; // expected-error {{base 'OutputPatch' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'OutputPatch'}}
1414

15-
struct RD : RayDesc {}; // expected-error {{base 'RayDesc' is marked 'final'}}
16-
struct BITIA : BuiltInTriangleIntersectionAttributes {}; // expected-error {{base 'BuiltInTriangleIntersectionAttributes' is marked 'final'}}
17-
struct RTAS : RaytracingAccelerationStructure {}; // expected-error {{base 'RaytracingAccelerationStructure' is marked 'final'}}
18-
struct GRS : GlobalRootSignature {}; // expected-error {{base 'GlobalRootSignature' is marked 'final'}}
15+
struct RD : RayDesc {}; // expected-error {{base 'RayDesc' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'RayDesc'}}
16+
struct BITIA : BuiltInTriangleIntersectionAttributes {}; // expected-error {{base 'BuiltInTriangleIntersectionAttributes' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'BuiltInTriangleIntersectionAttributes'}}
17+
struct RTAS : RaytracingAccelerationStructure {}; // expected-error {{base 'RaytracingAccelerationStructure' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'RaytracingAccelerationStructure'}}
18+
struct GRS : GlobalRootSignature {}; // expected-error {{base 'GlobalRootSignature' is marked 'final'}} fxc-error {{X3000: syntax error: unexpected token 'GlobalRootSignature'}}
1919

2020
void main() {}

tools/clang/test/HLSL/conversions-non-numeric-aggregates.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ struct ObjStruct { Buffer a; };
77

88
void main()
99
{
10-
(Buffer[1])0; /* expected-error {{cannot convert from 'literal int' to 'Buffer [1]'}} */
11-
(ObjStruct)0; /* expected-error {{cannot convert from 'literal int' to 'ObjStruct'}} */
12-
(Buffer[1])(int[1])0; /* expected-error {{cannot convert from 'int [1]' to 'Buffer [1]'}} */
13-
(ObjStruct)(NumStruct)0; /* expected-error {{cannot convert from 'NumStruct' to 'ObjStruct'}} */
10+
(Buffer[1])0; /* expected-error {{cannot convert from 'literal int' to 'Buffer [1]'}} fxc-error {{X3017: cannot convert from 'int' to 'Buffer<float4>[1]'}} */
11+
(ObjStruct)0; /* expected-error {{cannot convert from 'literal int' to 'ObjStruct'}} fxc-error {{X3017: cannot convert from 'int' to 'struct ObjStruct'}} */
12+
(Buffer[1])(int[1])0; /* expected-error {{cannot convert from 'int [1]' to 'Buffer [1]'}} fxc-error {{X3017: cannot convert from 'const int[1]' to 'Buffer<float4>[1]'}} */
13+
(ObjStruct)(NumStruct)0; /* expected-error {{cannot convert from 'NumStruct' to 'ObjStruct'}} fxc-error {{X3017: cannot convert from 'const struct NumStruct' to 'struct ObjStruct'}} */
1414

1515
Buffer oa1[1];
1616
ObjStruct os1;
17-
(int)oa1; /* expected-error {{cannot convert from 'Buffer [1]' to 'int'}} */
18-
(int)os1; /* expected-error {{cannot convert from 'ObjStruct' to 'int'}} */
17+
(int)oa1; /* expected-error {{cannot convert from 'Buffer [1]' to 'int'}} fxc-error {{X3017: cannot convert from 'Buffer<float4>[1]' to 'int'}} */
18+
(int)os1; /* expected-error {{cannot convert from 'ObjStruct' to 'int'}} fxc-error {{X3017: cannot convert from 'struct ObjStruct' to 'int'}} */
1919
}

tools/clang/test/HLSL/incomp_array_err.hlsl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
// Verify error on on incomplete array in a struct or class
44

5-
typedef const int inta[];
5+
typedef const int inta[]; /* fxc-error {{X3072: array dimensions of type must be explicit}} */
66

7-
static inta s_test1 = {1, 2, 3};
7+
static inta s_test1 = {1, 2, 3}; /* fxc-error {{X3000: unrecognized identifier 'inta'}} */
88

99
static int s_test2[] = { 4, 5, 6 };
1010

1111
struct foo1 {
1212
float4 member;
13-
inta a; // expected-error {{array dimensions of struct/class members must be explicit}}
13+
inta a; // expected-error {{array dimensions of struct/class members must be explicit}} fxc-error {{X3000: unrecognized identifier 'inta'}}
1414
};
1515

1616
struct foo2 {
17-
int a[]; // expected-error {{array dimensions of struct/class members must be explicit}}
17+
int a[]; // expected-error {{array dimensions of struct/class members must be explicit}} fxc-error {{X3072: 'foo2::a': array dimensions of struct/class members must be explicit}}
1818
float4 member;
1919
};
2020

2121
class foo3 {
2222
float4 member;
23-
inta a; // expected-error {{array dimensions of struct/class members must be explicit}}
23+
inta a; // expected-error {{array dimensions of struct/class members must be explicit}} fxc-error {{X3000: unrecognized identifier 'inta'}}
2424
};
2525

2626
class foo4 {
2727
float4 member;
28-
int a[]; // expected-error {{array dimensions of struct/class members must be explicit}}
29-
};
28+
int a[]; // expected-error {{array dimensions of struct/class members must be explicit}} fxc-error {{X3072: 'foo4::a': array dimensions of struct/class members must be explicit}}
29+
};

0 commit comments

Comments
 (0)