You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[HLSL] For builtins aliases, apply implicit conversions before running custom type checking (#195365)
Fixes#195329 by making HLSL
builtin aliases apply implicit conversions before running custom type
checking.
After this PR:
- There are no more size 1 vectors being passed and returned to/from
aliased Clang builtins because they get truncated to scalars due to the
HLSL alias builtin not having explicit size 1 vector overloads.
- HLSL alias builtins no longer accept matrices unless they have
explicit matrix overloads. Matrices get implicitly truncated to scalars
and resolve to the scalar Clang builtin being aliased.
- Many calls with mismatched vector sizes no longer error with
`arguments are of different types` and instead follow Clang's overload
resolution rules with respect to HLSL's implicit conversion sequences.
(e.g., `dot(float3, float2)` -> `dot(float2, float2)` with warning)
- Calls with implicitly-convertible types no longer error. They are now
implicitly converted, and with a warning in some cases. (e.g.,
`f16tof32(bool)` -> `f16tof32(uint)` without warning, but
`f16tof32(short)` -> `f16tof32(uint)` with warning).
Assisted-by: Claude Opus 4.6
// expected-error@-1 {{no matching function for call to 'f32tof16'}}
78
78
}
79
79
80
+
// Overload resolution selects uint f32tof16(float); bool is implicitly converted to float.
80
81
uintf32tof16_bool(bool p0) {
81
82
returnf32tof16(p0);
82
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'bool')}}
83
83
}
84
84
85
+
// Overload resolution selects an overload; bool3 is implicitly converted.
85
86
uintf32tof16_bool3(bool3 p0) {
86
87
returnf32tof16(p0);
87
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'bool3' (aka 'vector<bool, 3>'))}}
88
+
// expected-warning@-1 {{implicit conversion turns vector to scalar: 'vector<unsigned int, 3>' (vector of 3 'unsigned int' values) to 'unsigned int'}}
88
89
}
89
90
90
91
92
+
// Overload resolution selects uint f32tof16(float); short is implicitly converted to float.
91
93
uintf32tof16_int16_t(short p0) {
92
94
returnf32tof16(p0);
93
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'short')}}
94
95
}
95
96
97
+
// Overload resolution selects uint f32tof16(float); unsigned short is implicitly converted to float.
96
98
uintf32tof16_int16_t(unsigned short p0) {
97
99
returnf32tof16(p0);
98
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'unsigned short')}}
99
100
}
100
101
102
+
// Overload resolution selects uint f32tof16(float); int is implicitly converted to float.
101
103
uintf32tof16_int(int p0) {
102
104
returnf32tof16(p0);
103
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int')}}
105
+
// expected-warning@-1 {{implicit conversion from 'int' to 'float' may lose precision}}
104
106
}
105
107
108
+
// Overload resolution selects uint f32tof16(float); long is implicitly converted to float.
106
109
uintf32tof16_int64_t(long p0) {
107
110
returnf32tof16(p0);
108
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'long')}}
111
+
// expected-warning@-1 {{implicit conversion from 'long' to 'float' may lose precision}}
109
112
}
110
113
114
+
// Overload resolution selects an overload; int3 is implicitly converted.
111
115
uint2f32tof16_int2_to_float2_promotion(int3 p0) {
112
116
returnf32tof16(p0);
113
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int3' (aka 'vector<int, 3>'))}}
117
+
// expected-warning@-1 {{implicit conversion truncates vector: 'vector<unsigned int, 3>' (vector of 3 'unsigned int' values) to 'vector<unsigned int, 2>' (vector of 2 'unsigned int' values)}}
118
+
// expected-warning@-2 {{implicit conversion from 'int3' (aka 'vector<int, 3>') to 'vector<float, 3>' (vector of 3 'float' values) may lose precision}}
114
119
}
115
120
121
+
// Overload resolution selects uint f32tof16(float); half is implicitly converted to float.
116
122
uintf32tof16_half(half p0) {
117
123
returnf32tof16(p0);
118
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'half')}}
119
124
}
120
125
126
+
// Overload resolution selects an overload; half2 is implicitly converted.
121
127
uintf32tof16_half2(half2 p0) {
122
128
returnf32tof16(p0);
123
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'half2' (aka 'vector<half, 2>'))}}
129
+
// expected-warning@-1 {{implicit conversion turns vector to scalar: 'vector<unsigned int, 2>' (vector of 2 'unsigned int' values) to 'unsigned int'}}
124
130
}
125
131
132
+
// Overload resolution selects uint f32tof16(float); uint is implicitly converted to float.
126
133
uintf32tof16_float(uint p0) {
127
134
returnf32tof16(p0);
128
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'uint' (aka 'unsigned int'))}}
135
+
// expected-warning@-1 {{implicit conversion from 'uint' (aka 'unsigned int') to 'float' may lose precision}}
129
136
}
130
137
138
+
// Overload resolution selects uint f32tof16(float); double is implicitly converted to float.
131
139
uintf32tof16_double(double p0) {
132
140
returnf32tof16(p0);
133
-
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'double')}}
141
+
// expected-warning@-1 {{implicit conversion loses floating-point precision: 'double' to 'float'}}
0 commit comments