Skip to content

Commit fdc868e

Browse files
committed
make sure you can't cast intangible types
1 parent 5fb0b9f commit fdc868e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,9 @@ bool SemaHLSL::CheckCompatibleParameterABI(FunctionDecl *New,
27102710
// clarity of what types are supported
27112711
bool SemaHLSL::CanPerformScalarCast(QualType SrcTy, QualType DestTy) {
27122712

2713+
if (!SrcTy->isScalarType() || !DestTy->isScalarType())
2714+
return false;
2715+
27132716
if (SemaRef.getASTContext().hasSameUnqualifiedType(SrcTy, DestTy))
27142717
return true;
27152718

clang/test/SemaHLSL/Language/SplatCasts-errors.hlsl

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -verify
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -verify -verify-ignore-unexpected=note
22

33
struct S {
4-
// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S' for 1st argument}}
5-
// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S' for 1st argument}}
6-
// expected-note@-3 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
74
int A : 8;
85
int B;
96
};
107

118
struct R {
12-
// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const R' for 1st argument}}
13-
// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'R' for 1st argument}}
14-
// expected-note@-3 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
159
int A;
1610
union {
1711
float F;
@@ -30,3 +24,26 @@ export void cantCast2() {
3024
R r = (R)1;
3125
// expected-error@-1 {{no matching conversion for C-style cast from 'int' to 'R'}}
3226
}
27+
28+
RWBuffer<float4> Buf;
29+
30+
// Can't cast an intangible type
31+
export void cantCast3() {
32+
Buf = (RWBuffer<float4>)1;
33+
// expected-error@-1 {{no matching conversion for C-style cast from 'int' to 'RWBuffer<float4>' (aka 'RWBuffer<vector<float, 4>>')}}
34+
}
35+
36+
export void cantCast4() {
37+
RWBuffer<float4> B[2] = (RWBuffer<float4>[2])1;
38+
// expected-error@-1 {{C-style cast from 'int' to 'RWBuffer<float4>[2]' (aka 'RWBuffer<vector<float, 4>>[2]') is not allowed}}
39+
}
40+
41+
struct X {
42+
int A;
43+
RWBuffer<float4> Buf;
44+
};
45+
46+
export void cantCast5() {
47+
X x = (X)1;
48+
// expected-error@-1 {{no matching conversion for C-style cast from 'int' to 'X'}}
49+
}

0 commit comments

Comments
 (0)