Skip to content

Commit 366592b

Browse files
authored
[HLSL] prevent generation of double intrinsics via the builtins (#86555)
fixes #86551 closes #86552 Thanks to #86440 and #86407 it makes more sense for us to do type checks early via Sema to prevent the generation of invalid intrinsics.
1 parent 350bda4 commit 366592b

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,6 @@ float3 cos(float3);
392392
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
393393
float4 cos(float4);
394394

395-
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
396-
double cos(double);
397-
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
398-
double2 cos(double2);
399-
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
400-
double3 cos(double3);
401-
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
402-
double4 cos(double4);
403-
404395
//===----------------------------------------------------------------------===//
405396
// dot product builtins
406397
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaChecking.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5624,6 +5624,21 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
56245624
TheCall, /*CheckForFloatArgs*/
56255625
TheCall->getArg(0)->getType()->hasFloatingRepresentation()))
56265626
return true;
5627+
break;
5628+
}
5629+
// Note these are llvm builtins that we want to catch invalid intrinsic
5630+
// generation. Normal handling of these builitns will occur elsewhere.
5631+
case Builtin::BI__builtin_elementwise_cos:
5632+
case Builtin::BI__builtin_elementwise_sin:
5633+
case Builtin::BI__builtin_elementwise_log:
5634+
case Builtin::BI__builtin_elementwise_log2:
5635+
case Builtin::BI__builtin_elementwise_log10:
5636+
case Builtin::BI__builtin_elementwise_pow:
5637+
case Builtin::BI__builtin_elementwise_sqrt:
5638+
case Builtin::BI__builtin_elementwise_trunc: {
5639+
if (CheckFloatOrHalfRepresentations(this, TheCall))
5640+
return true;
5641+
break;
56275642
}
56285643
}
56295644
return false;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cos
2+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sin
3+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log
4+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log2
5+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log10
6+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_sqrt
7+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_trunc
8+
9+
10+
double2 test_double_builtin(double2 p0) {
11+
return TEST_FUNC(p0);
12+
// 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)}}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify
2+
3+
double2 test_double_builtin(double2 p0, double2 p1) {
4+
return __builtin_elementwise_pow(p0,p1);
5+
// 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)}}
6+
}

0 commit comments

Comments
 (0)