forked from OSchip/llvm-project
[OpenCL] Only declare _sat conversions for integer types
The `-fdeclare-opencl-builtins` option was accepting saturated conversions for non-integer types, which contradicts both the OpenCL specification (v2.0 s6.2.3) and Clang's opencl-c.h file.
This commit is contained in:
parent
284279ac23
commit
81e8b60b72
|
@ -378,7 +378,11 @@ foreach RType = [Float, Double, Half, Char, UChar, Short,
|
|||
UShort, Int, UInt, Long, ULong] in {
|
||||
foreach IType = [Float, Double, Half, Char, UChar, Short,
|
||||
UShort, Int, UInt, Long, ULong] in {
|
||||
foreach sat = ["", "_sat"] in {
|
||||
// Conversions to integer type have a sat and non-sat variant.
|
||||
foreach sat = !cond(!eq(RType.Name, "float") : [""],
|
||||
!eq(RType.Name, "double") : [""],
|
||||
!eq(RType.Name, "half") : [""],
|
||||
1 : ["", "_sat"]) in {
|
||||
foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
|
||||
def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
|
||||
Attr.Const>;
|
||||
|
|
|
@ -71,11 +71,25 @@ kernel void basic_conversion() {
|
|||
int4 i4;
|
||||
|
||||
f = convert_float(d);
|
||||
d = convert_double_sat_rtp(f);
|
||||
d = convert_double_rtp(f);
|
||||
l2 = convert_long2_rtz(c2);
|
||||
i4 = convert_int4_sat(f4);
|
||||
}
|
||||
|
||||
kernel void basic_conversion_neg() {
|
||||
int i;
|
||||
float f;
|
||||
|
||||
f = convert_float_sat(i);
|
||||
#if !defined(__OPENCL_CPP_VERSION__)
|
||||
// expected-error@-2{{implicit declaration of function 'convert_float_sat' is invalid in OpenCL}}
|
||||
// expected-error@-3{{implicit conversion from 'int' to 'float' may lose precision}}
|
||||
#else
|
||||
// expected-error@-5{{use of undeclared identifier 'convert_float_sat'; did you mean 'convert_float'?}}
|
||||
// expected-note@-6{{'convert_float' declared here}}
|
||||
#endif
|
||||
}
|
||||
|
||||
char4 test_int(char c, char4 c4) {
|
||||
char m = max(c, c);
|
||||
char4 m4 = max(c4, c4);
|
||||
|
|
Loading…
Reference in New Issue