Debian Codegraph @

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

raw
1 // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected=note
2
3 float2 test_no_second_arg(float2 p0) {
4 return __builtin_hlsl_elementwise_clamp(p0);
5 // expected-error@-1 {{too few arguments to function call, expected 3, have 1}}
6 }
7
8 float2 test_no_third_arg(float2 p0) {
9 return __builtin_hlsl_elementwise_clamp(p0, p0);
10 // expected-error@-1 {{too few arguments to function call, expected 3, have 2}}
11 }
12
13 float2 test_too_many_arg(float2 p0) {
14 return __builtin_hlsl_elementwise_clamp(p0, p0, p0, p0);
15 // expected-error@-1 {{too many arguments to function call, expected 3, have 4}}
16 }
17
18 float2 test_clamp_no_second_arg(float2 p0) {
19 return clamp(p0);
20 // expected-error@-1 {{no matching function for call to 'clamp'}}
21 }
22
23 float test_scalar_first_arg(float p0, float2 p1) {
24 return clamp(p0, p1, p1);
25 // expected-error@-1 {{call to 'clamp' is ambiguous}}
26 }
27
28 float test_scalar_first_arg2(float p0, float2 p1) {
29 return clamp(p0, p0, p1);
30 // expected-error@-1 {{call to 'clamp' is ambiguous}}
31 }
32
33 float2 test_scalar_first_arg3(float p0, float2 p1) {
34 return clamp(p0, p0, p1);
35 // expected-error@-1 {{call to 'clamp' is ambiguous}}
36 }
37
38 float3 test_clamp_vector_size_last_arg_mismatch(float3 p0, float2 p1) {
39 return clamp(p0, p0, p1);
40 // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}}
41 }
42
43 typedef float float5 __attribute__((ext_vector_type(5)));
44
45 // check vectors of wrong size are rejected
46 float5 vec_too_big(float5 p0) {
47 return clamp(p0, p0, p0);
48 // expected-error@-1 {{call to 'clamp' is ambiguous}}
49 }
50
51 float2 test_clamp_vector_size_ret_mismatch(float3 p0, float3 p1) {
52 return clamp(p0, p0, p1);
53 // expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}
54 }
55
56 float2 test_clamp_builtin_vector_size_first_arg_mismatch(float3 p0, float2 p1) {
57 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
58 // expected-error@-1 {{arguments are of different types ('vector<[...], 3>' vs 'vector<[...], 2>')}}
59 }
60
61 float test_clamp_scalar_mismatch(float p0, half p1) {
62 return clamp(p1, p0, p1);
63 // expected-error@-1 {{call to 'clamp' is ambiguous}}
64 }
65
66 float2 test_clamp_element_type_mismatch(half2 p0, float2 p1) {
67 return clamp(p1, p0, p1);
68 // expected-error@-1 {{call to 'clamp' is ambiguous}}
69 }
70
71 float2 test_builtin_clamp_float2_splat(float p0, float2 p1) {
72 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
73 // expected-error@-1 {{arguments are of different types ('float' vs 'float2' (aka 'vector<float, 2>'))}}
74 }
75
76 float3 test_builtin_clamp_float3_splat(float p0, float3 p1) {
77 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
78 // expected-error@-1 {{arguments are of different types ('float' vs 'float3' (aka 'vector<float, 3>'))}}
79 }
80
81 float4 test_builtin_clamp_float4_splat(float p0, float4 p1) {
82 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
83 // expected-error@-1 {{arguments are of different types ('float' vs 'float4' (aka 'vector<float, 4>'))}}
84 }
85
86 float2 test_clamp_float2_int_splat(float2 p0, int p1) {
87 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
88 // expected-error@-1 {{arguments are of different types ('float2' (aka 'vector<float, 2>') vs 'int')}}
89 }
90
91 float3 test_clamp_float3_int_splat(float3 p0, int p1) {
92 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
93 // expected-error@-1 {{arguments are of different types ('float3' (aka 'vector<float, 3>') vs 'int')}}
94 }
95
96 float2 test_builtin_clamp_int_vect_to_float_vec_promotion(int2 p0, float p1) {
97 return __builtin_hlsl_elementwise_clamp(p0, p1, p1);
98 // expected-error@-1 {{arguments are of different types ('int2' (aka 'vector<int, 2>') vs 'float')}}
99 }
100
101 float test_builtin_clamp_bool_type_promotion(bool p0) {
102 return __builtin_hlsl_elementwise_clamp(p0, p0, p0);
103 // expected-error@-1 {{1st argument must be a vector, integer or floating-point type (was 'bool')}}
104 }
105
106 float builtin_bool_to_float_type_promotion(float p0, bool p1) {
107 return __builtin_hlsl_elementwise_clamp(p0, p0, p1);
108 // expected-error@-1 {{3rd argument must be a vector, integer or floating-point type (was 'bool')}}
109 }
110
111 float builtin_bool_to_float_type_promotion2(bool p0, float p1) {
112 return __builtin_hlsl_elementwise_clamp(p1, p0, p1);
113 // expected-error@-1 {{2nd argument must be a vector, integer or floating-point type (was 'bool')}}
114 }
115
116 float builtin_clamp_int_to_float_promotion(float p0, int p1) {
117 return __builtin_hlsl_elementwise_clamp(p0, p0, p1);
118 // expected-error@-1 {{arguments are of different types ('float' vs 'int')}}
119 }
120
121 float builtin_clamp_reject_array(int Arr[2]) {
122 return __builtin_hlsl_elementwise_clamp(Arr, Arr, Arr);
123 // expected-error@-1 {{1st argument must be a vector, integer or floating-point type (was 'int *')}}
124 }