Skip to content

Commit 3026fa0

Browse files
authored
[HLSL] add CustomTypeChecking to float builtins (llvm#133441)
- Add CustomTypeChecking to HLSL builtins that take float arguments - Add new builtin tests to confirm CustomTypeChecking doesn't promote scalar float arguments aren't promoted to double - fixes llvm#133440
1 parent 0c81105 commit 3026fa0

18 files changed

+199
-101
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,7 +4869,7 @@ def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> {
48694869

48704870
def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
48714871
let Spellings = ["__builtin_hlsl_elementwise_clamp"];
4872-
let Attributes = [NoThrow, Const];
4872+
let Attributes = [NoThrow, Const, CustomTypeChecking];
48734873
let Prototype = "void(...)";
48744874
}
48754875

@@ -4881,13 +4881,13 @@ def HLSLCross: LangBuiltin<"HLSL_LANG"> {
48814881

48824882
def HLSLDegrees : LangBuiltin<"HLSL_LANG"> {
48834883
let Spellings = ["__builtin_hlsl_elementwise_degrees"];
4884-
let Attributes = [NoThrow, Const];
4884+
let Attributes = [NoThrow, Const, CustomTypeChecking];
48854885
let Prototype = "void(...)";
48864886
}
48874887

48884888
def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
48894889
let Spellings = ["__builtin_hlsl_dot"];
4890-
let Attributes = [NoThrow, Const];
4890+
let Attributes = [NoThrow, Const, CustomTypeChecking];
48914891
let Prototype = "void(...)";
48924892
}
48934893

@@ -4917,7 +4917,7 @@ def HLSLFirstBitLow : LangBuiltin<"HLSL_LANG"> {
49174917

49184918
def HLSLFrac : LangBuiltin<"HLSL_LANG"> {
49194919
let Spellings = ["__builtin_hlsl_elementwise_frac"];
4920-
let Attributes = [NoThrow, Const];
4920+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49214921
let Prototype = "void(...)";
49224922
}
49234923

@@ -4929,7 +4929,7 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
49294929

49304930
def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
49314931
let Spellings = ["__builtin_hlsl_lerp"];
4932-
let Attributes = [NoThrow, Const];
4932+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49334933
let Prototype = "void(...)";
49344934
}
49354935

@@ -4941,25 +4941,25 @@ def HLSLMad : LangBuiltin<"HLSL_LANG"> {
49414941

49424942
def HLSLNormalize : LangBuiltin<"HLSL_LANG"> {
49434943
let Spellings = ["__builtin_hlsl_normalize"];
4944-
let Attributes = [NoThrow, Const];
4944+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49454945
let Prototype = "void(...)";
49464946
}
49474947

49484948
def HLSLRcp : LangBuiltin<"HLSL_LANG"> {
49494949
let Spellings = ["__builtin_hlsl_elementwise_rcp"];
4950-
let Attributes = [NoThrow, Const];
4950+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49514951
let Prototype = "void(...)";
49524952
}
49534953

49544954
def HLSLRSqrt : LangBuiltin<"HLSL_LANG"> {
49554955
let Spellings = ["__builtin_hlsl_elementwise_rsqrt"];
4956-
let Attributes = [NoThrow, Const];
4956+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49574957
let Prototype = "void(...)";
49584958
}
49594959

49604960
def HLSLSaturate : LangBuiltin<"HLSL_LANG"> {
49614961
let Spellings = ["__builtin_hlsl_elementwise_saturate"];
4962-
let Attributes = [NoThrow, Const];
4962+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49634963
let Prototype = "void(...)";
49644964
}
49654965

@@ -4983,7 +4983,7 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> {
49834983

49844984
def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
49854985
let Spellings = ["__builtin_hlsl_elementwise_radians"];
4986-
let Attributes = [NoThrow, Const];
4986+
let Attributes = [NoThrow, Const, CustomTypeChecking];
49874987
let Prototype = "void(...)";
49884988
}
49894989

@@ -5001,7 +5001,7 @@ def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
50015001

50025002
def HLSLClip: LangBuiltin<"HLSL_LANG"> {
50035003
let Spellings = ["__builtin_hlsl_elementwise_clip"];
5004-
let Attributes = [NoThrow, Const];
5004+
let Attributes = [NoThrow, Const, CustomTypeChecking];
50055005
let Prototype = "void(...)";
50065006
}
50075007

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
22

3-
// CHECK-LABEL: builtin_test_clamp_int4
4-
// CHECK: %hlsl.clamp = call <4 x i32> @llvm.dx.sclamp.v4i32(<4 x i32> %0, <4 x i32> %1, <4 x i32> %2)
5-
// CHECK: ret <4 x i32> %hlsl.clamp
6-
int4 builtin_test_clamp_int4(int4 p0, int4 p1, int4 p2) {
7-
return __builtin_hlsl_elementwise_clamp(p0, p1, p2);
8-
}
3+
4+
// CHECK-LABEL: builtin_clamp_half
5+
// CHECK: %hlsl.clamp = call reassoc nnan ninf nsz arcp afn half @llvm.dx.nclamp.f16(half %{{.*}}, half %{{.*}}, half %{{.*}})
6+
// CHECK: ret half %hlsl.clamp
7+
half builtin_clamp_half(half p0) { return __builtin_hlsl_elementwise_clamp(p0, p0, p0); }
8+
9+
// CHECK-LABEL: builtin_clamp_float
10+
// CHECK: %hlsl.clamp = call reassoc nnan ninf nsz arcp afn float @llvm.dx.nclamp.f32(float %{{.*}}, float %{{.*}}, float %{{.*}})
11+
// CHECK: ret float %hlsl.clamp
12+
float builtin_clamp_float(float p0) { return __builtin_hlsl_elementwise_clamp(p0, p0, p0); }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
// CHECK: define void @{{.*}}builtin_clip_float{{.*}}(float {{.*}} [[P0:%.*]])
4+
// CHECK: [[LOAD:%.*]] = load float, ptr [[P0]].addr, align 4
5+
// CHECK-NEXT: [[FCMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt float [[LOAD]], 0.000000e+00
6+
// CHECK-NO: call i1 @llvm.dx.any
7+
// CHECK-NEXT: call void @llvm.dx.discard(i1 [[FCMP]])
8+
void builtin_clip_float (float p0) {
9+
__builtin_hlsl_elementwise_clip(p0);
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_degrees_half
5+
// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn half @llvm.dx.degrees.f16(half %{{.*}})
6+
// CHECK: ret half %hlsl.degrees
7+
half builtin_degrees_half(half p0) {
8+
return __builtin_hlsl_elementwise_degrees(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_degrees_float
12+
// CHECK: %hlsl.degrees = call reassoc nnan ninf nsz arcp afn float @llvm.dx.degrees.f32(float %{{.*}})
13+
// CHECK: ret float %hlsl.degrees
14+
float builtin_degrees_float (float p0) {
15+
return __builtin_hlsl_elementwise_degrees(p0);
16+
}
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
22

3-
// CHECK-LABEL: builtin_bool_to_float_type_promotion
4-
// CHECK: %conv1 = uitofp i1 %loadedv to double
5-
// CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn double %conv, %conv1
6-
// CHECK: %conv2 = fptrunc reassoc nnan ninf nsz arcp afn double %hlsl.dot to float
7-
// CHECK: ret float %conv2
8-
float builtin_bool_to_float_type_promotion ( float p0, bool p1 ) {
9-
return __builtin_hlsl_dot ( (double)p0, (double)p1 );
3+
4+
// CHECK-LABEL: builtin_dot_half
5+
// CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn half %{{.*}}, %{{.*}}
6+
// CHECK: ret half %hlsl.dot
7+
half builtin_dot_half ( half p0, half p1 ) {
8+
return __builtin_hlsl_dot (p0, p1 );
109
}
1110

12-
// CHECK-LABEL: builtin_bool_to_float_arg1_type_promotion
13-
// CHECK: %conv = uitofp i1 %loadedv to double
14-
// CHECK: %conv1 = fpext reassoc nnan ninf nsz arcp afn float %1 to double
15-
// CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn double %conv, %conv1
16-
// CHECK: %conv2 = fptrunc reassoc nnan ninf nsz arcp afn double %hlsl.dot to float
17-
// CHECK: ret float %conv2
18-
float builtin_bool_to_float_arg1_type_promotion ( bool p0, float p1 ) {
19-
return __builtin_hlsl_dot ( (double)p0, (double)p1 );
11+
// CHECK-LABEL: builtin_dot_float
12+
// CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}}
13+
// CHECK: ret float %hlsl.dot
14+
float builtin_dot_float ( float p0, float p1 ) {
15+
return __builtin_hlsl_dot (p0, p1 );
2016
}
2117

22-
// CHECK-LABEL: builtin_dot_int_to_float_promotion
23-
// CHECK: %conv = fpext reassoc nnan ninf nsz arcp afn float %0 to double
24-
// CHECK: %conv1 = sitofp i32 %1 to double
25-
// CHECK: dot = fmul reassoc nnan ninf nsz arcp afn double %conv, %conv1
26-
// CHECK: %conv2 = fptrunc reassoc nnan ninf nsz arcp afn double %hlsl.dot to float
27-
// CHECK: ret float %conv2
28-
float builtin_dot_int_to_float_promotion ( float p0, int p1 ) {
29-
return __builtin_hlsl_dot ( (double)p0, (double)p1 );
18+
// CHECK-LABEL: builtin_dot_double
19+
// CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn double %{{.*}}, %{{.*}}
20+
// CHECK: ret double %hlsl.dot
21+
double builtin_dot_double( double p0, double p1 ) {
22+
return __builtin_hlsl_dot (p0, p1 );
3023
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_frac_half
5+
// CHECK: %hlsl.frac = call reassoc nnan ninf nsz arcp afn half @llvm.dx.frac.f16(half %{{.*}})
6+
// CHECK: ret half %hlsl.frac
7+
half builtin_frac_half(half p0) {
8+
return __builtin_hlsl_elementwise_frac(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_frac_float
12+
// CHECK: %hlsl.frac = call reassoc nnan ninf nsz arcp afn float @llvm.dx.frac.f32(float %{{.*}})
13+
// CHECK: ret float %hlsl.frac
14+
float builtin_frac_float (float p0) {
15+
return __builtin_hlsl_elementwise_frac(p0);
16+
}
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
22

3-
// CHECK-LABEL: builtin_lerp_half_vector
4-
// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.dx.lerp.v3f16(<3 x half> %0, <3 x half> %1, <3 x half> %2)
5-
// CHECK: ret <3 x half> %hlsl.lerp
6-
half3 builtin_lerp_half_vector (half3 p0) {
7-
return __builtin_hlsl_lerp ( p0, p0, p0 );
8-
}
93

10-
// CHECK-LABEL: builtin_lerp_floar_vector
11-
// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.dx.lerp.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %2)
12-
// CHECK: ret <2 x float> %hlsl.lerp
13-
float2 builtin_lerp_floar_vector ( float2 p0) {
14-
return __builtin_hlsl_lerp ( p0, p0, p0 );
15-
}
4+
// CHECK-LABEL: builtin_lerp_half
5+
// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn half @llvm.dx.lerp.f16(half %{{.*}}, half %{{.*}}, half %{{.*}})
6+
// CHECK: ret half %hlsl.lerp
7+
half builtin_lerp_half(half p0) { return __builtin_hlsl_lerp(p0, p0, p0); }
8+
9+
// CHECK-LABEL: builtin_lerp_float
10+
// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn float @llvm.dx.lerp.f32(float %{{.*}}, float %{{.*}}, float %{{.*}})
11+
// CHECK: ret float %hlsl.lerp
12+
float builtin_lerp_float(float p0) { return __builtin_hlsl_lerp(p0, p0, p0); }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_normalize_half
5+
// CHECK: %hlsl.normalize = call reassoc nnan ninf nsz arcp afn half @llvm.dx.normalize.f16(half %{{.*}})
6+
// CHECK: ret half %hlsl.normalize
7+
half builtin_normalize_half(half p0) {
8+
return __builtin_hlsl_normalize(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_normalize_float
12+
// CHECK: %hlsl.normalize = call reassoc nnan ninf nsz arcp afn float @llvm.dx.normalize.f32(float %{{.*}})
13+
// CHECK: ret float %hlsl.normalize
14+
float builtin_normalize_float (float p0) {
15+
return __builtin_hlsl_normalize(p0);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_radians_half
5+
// CHECK: %hlsl.radians = call reassoc nnan ninf nsz arcp afn half @llvm.dx.radians.f16(half %{{.*}})
6+
// CHECK: ret half %hlsl.radians
7+
half builtin_radians_half(half p0) {
8+
return __builtin_hlsl_elementwise_radians(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_radians_float
12+
// CHECK: %hlsl.radians = call reassoc nnan ninf nsz arcp afn float @llvm.dx.radians.f32(float %{{.*}})
13+
// CHECK: ret float %hlsl.radians
14+
float builtin_radians_float (float p0) {
15+
return __builtin_hlsl_elementwise_radians(p0);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_rcp_half
5+
// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn half 0xH3C00, %{{.*}}
6+
// CHECK: ret half %hlsl.rcp
7+
half builtin_rcp_half(half p0) {
8+
return __builtin_hlsl_elementwise_rcp(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_rcp_float
12+
// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn float 1.000000e+00, %{{.*}}
13+
// CHECK: ret float %hlsl.rcp
14+
float builtin_rcp_float(float p0) {
15+
return __builtin_hlsl_elementwise_rcp(p0);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_rsqrt_half
5+
// CHECK: %hlsl.rsqrt = call reassoc nnan ninf nsz arcp afn half @llvm.dx.rsqrt.f16(half %{{.*}})
6+
// CHECK: ret half %hlsl.rsqrt
7+
half builtin_rsqrt_half(half p0) {
8+
return __builtin_hlsl_elementwise_rsqrt(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_rsqrt_float
12+
// CHECK: %hlsl.rsqrt = call reassoc nnan ninf nsz arcp afn float @llvm.dx.rsqrt.f32(float %{{.*}})
13+
// CHECK: ret float %hlsl.rsqrt
14+
float builtin_rsqrt_float (float p0) {
15+
return __builtin_hlsl_elementwise_rsqrt(p0);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
2+
3+
4+
// CHECK-LABEL: builtin_saturate_half
5+
// CHECK: %hlsl.saturate = call reassoc nnan ninf nsz arcp afn half @llvm.dx.saturate.f16(half %{{.*}})
6+
// CHECK: ret half %hlsl.saturate
7+
half builtin_saturate_half(half p0) {
8+
return __builtin_hlsl_elementwise_saturate(p0);
9+
}
10+
11+
// CHECK-LABEL: builtin_saturate_float
12+
// CHECK: %hlsl.saturate = call reassoc nnan ninf nsz arcp afn float @llvm.dx.saturate.f32(float %{{.*}})
13+
// CHECK: ret float %hlsl.saturate
14+
float builtin_saturate_float (float p0) {
15+
return __builtin_hlsl_elementwise_saturate(p0);
16+
}

clang/test/SemaHLSL/BuiltIns/clamp-errors.hlsl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ float2 test_scalar_first_arg3(float p0, float2 p1) {
3535
// expected-error@-1 {{call to 'clamp' is ambiguous}}
3636
}
3737

38-
float3 test_thing(float3 p0, float2 p1) {
38+
float3 test_clamp_vector_size_last_arg_mismatch(float3 p0, float2 p1) {
3939
return clamp(p0, p0, p1);
40-
// expected-error@-1 {{cannot initialize return object of type 'float3' (aka 'vector<float, 3>') with an rvalue of type 'vector<float, 2>' (vector of 2 'float' values)}}
40+
// expected-error@-1 {{all arguments to 'clamp' must have the same type}}
4141
}
4242

4343
typedef float float5 __attribute__((ext_vector_type(5)));
@@ -48,13 +48,12 @@ float5 vec_too_big(float5 p0) {
4848
// expected-error@-1 {{call to 'clamp' is ambiguous}}
4949
}
5050

51-
float2 test_clamp_vector_size_mismatch(float3 p0, float2 p1) {
51+
float2 test_clamp_vector_size_ret_mismatch(float3 p0, float3 p1) {
5252
return clamp(p0, p0, p1);
5353
// expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}
54-
// expected-warning@-2 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}
5554
}
5655

57-
float2 test_clamp_builtin_vector_size_mismatch(float3 p0, float2 p1) {
56+
float2 test_clamp_builtin_vector_size_first_arg_mismatch(float3 p0, float2 p1) {
5857
return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
5958
// expected-error@-1 {{all arguments to '__builtin_hlsl_elementwise_clamp' must have the same type}}
6059
}

clang/test/SemaHLSL/BuiltIns/clip-errors.hlsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ void test_first_arg_type_mismatch(bool p) {
1616
// expected-error@-1 {{invalid operand of type 'bool' where 'float' or a vector of such type is required}}
1717
}
1818

19-
void test_first_arg_type_mismatch_3(half3 p) {
19+
void test_first_arg_type_mismatch_2(half3 p) {
2020
__builtin_hlsl_elementwise_clip(p);
2121
// expected-error@-1 {{invalid operand of type 'half3' (aka 'vector<half, 3>') where 'float' or a vector of such type is required}}
2222
}
2323

24-
void test_first_arg_type_mismatch_3(double p) {
24+
void test_first_arg_type_mismatch_3(half p) {
25+
__builtin_hlsl_elementwise_clip(p);
26+
// expected-error@-1 {{invalid operand of type 'half' where 'float' or a vector of such type is required}}
27+
}
28+
29+
void test_first_arg_type_mismatch_4(double p) {
2530
__builtin_hlsl_elementwise_clip(p);
2631
// expected-error@-1 {{invalid operand of type 'double' where 'float' or a vector of such type is required}}
2732
}

clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected=note
22

33
float test_no_second_arg(float2 p0) {
44
return __builtin_hlsl_dot(p0);
@@ -17,7 +17,7 @@ float test_dot_no_second_arg(float2 p0) {
1717

1818
float test_dot_vector_size_mismatch(float3 p0, float2 p1) {
1919
return dot(p0, p1);
20-
// expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}
20+
// expected-error@-1 {{all arguments to 'dot' must have the same type}}
2121
}
2222

2323
float test_dot_builtin_vector_size_mismatch(float3 p0, float2 p1) {
@@ -104,7 +104,7 @@ float test_builtin_dot_int_vect_to_float_vec_promotion(int2 p0, float p1) {
104104
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
105105
}
106106

107-
int test_builtin_dot_bool_type_promotion(bool p0, bool p1) {
107+
int test_builtin_dot_bool_type_promotion(bool p0, float p1) {
108108
return __builtin_hlsl_dot(p0, p1);
109109
// expected-error@-1 {{1st argument must be a vector, integer or floating-point type (was 'bool')}}
110110
}
@@ -117,3 +117,13 @@ double test_dot_double_builtin(double2 p0, double2 p1) {
117117
return __builtin_hlsl_dot(p0, p1);
118118
// expected-error@-1 {{passing 'double2' (aka 'vector<double, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}}
119119
}
120+
121+
float builtin_bool_to_float_type_promotion ( float p0, bool p1 ) {
122+
return __builtin_hlsl_dot ( p0, p1 );
123+
// expected-error@-1 {{are of different types ('float' vs 'bool')}}
124+
}
125+
126+
float builtin_dot_int_to_float_promotion ( float p0, int p1 ) {
127+
return __builtin_hlsl_dot (p0, p1 );
128+
// expected-error@-1 {{are of different types ('float' vs 'int')}}
129+
}

0 commit comments

Comments
 (0)