Skip to content

Commit e91291b

Browse files
committed
add early failure if lerp arguments were type promoted to double
1 parent c280356 commit e91291b

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5233,10 +5233,6 @@ bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
52335233
TheCall->getArg(1)->getEndLoc());
52345234
retValue = true;
52355235
}
5236-
5237-
if (!retValue)
5238-
TheCall->setType(VecTyA->getElementType());
5239-
52405236
return retValue;
52415237
}
52425238
}
@@ -5254,7 +5250,11 @@ bool CheckAllArgsHaveFloatRepresentation(Sema *S, CallExpr *TheCall) {
52545250
QualType ExpectedType = S->Context.FloatTy;
52555251
for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) {
52565252
QualType PassedType = TheCall->getArg(i)->getType();
5257-
if (!PassedType->hasFloatingRepresentation()) {
5253+
ExpectedType = PassedType->isHalfType() && S->getLangOpts().NativeHalfType
5254+
? S->Context.HalfTy
5255+
: S->Context.FloatTy;
5256+
if (PassedType == S->Context.DoubleTy ||
5257+
!PassedType->hasFloatingRepresentation()) {
52585258
if (auto *VecTyA = PassedType->getAs<VectorType>())
52595259
ExpectedType = S->Context.getVectorType(
52605260
ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind());
@@ -5300,6 +5300,8 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
53005300
return true;
53015301
if (SemaBuiltinElementwiseTernaryMath(TheCall))
53025302
return true;
5303+
if (CheckAllArgsHaveFloatRepresentation(this, TheCall))
5304+
return true;
53035305
break;
53045306
}
53055307
case Builtin::BI__builtin_hlsl_mad: {

clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
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
2-
// XFAIL: *
3-
4-
// CHECK-LABEL: builtin_lerp_half_scalar
5-
// CHECK: %dx.lerp = call half @llvm.dx.lerp.f16(half %{{.*}}, half %{{.*}}, half %{{.*}})
6-
// CHECK: ret half %dx.lerp
7-
half builtin_lerp_half_scalar (half p0) {
8-
return __builtin_hlsl_lerp ( p0, p0, p0 );
9-
}
10-
11-
// CHECK-LABEL: builtin_lerp_float_scalar
12-
// CHECK: %dx.lerp = call float @llvm.dx.lerp.f32(float %{{.*}}, float %{{.*}}, float %{{.*}})
13-
// CHECK: ret float %dx.lerp
14-
float builtin_lerp_float_scalar ( float p0) {
15-
return __builtin_hlsl_lerp ( p0, p0, p0 );
16-
}
172

183
// CHECK-LABEL: builtin_lerp_half_vector
194
// CHECK: %dx.lerp = call <3 x half> @llvm.dx.lerp.v3f16(<3 x half> %0, <3 x half> %1, <3 x half> %2)

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,18 @@ float builtin_lerp_int_to_float_promotion(float p0, int p1) {
9292

9393
float4 test_lerp_int4(int4 p0, int4 p1, int4 p2) {
9494
return __builtin_hlsl_lerp(p0, p1, p2);
95-
// expected-error@-1 {{1st argument must be a floating point type (was 'int4' (aka 'vector<int, 4>'))}}
96-
}
95+
// expected-error@-1 {{1st argument must be a floating point type (was 'int4' (aka 'vector<int, 4>'))}}
96+
}
97+
98+
// note: DefaultVariadicArgumentPromotion --> DefaultArgumentPromotion has already promoted to double
99+
// we don't know anymore that the input was half when __builtin_hlsl_lerp is called so we default to float
100+
// for expected type
101+
half builtin_lerp_half_scalar (half p0) {
102+
return __builtin_hlsl_lerp ( p0, p0, p0 );
103+
// expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}}
104+
}
105+
106+
float builtin_lerp_float_scalar ( float p0) {
107+
return __builtin_hlsl_lerp ( p0, p0, p0 );
108+
// expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}}
109+
}

0 commit comments

Comments
 (0)