Skip to content

Commit 892621d

Browse files
committed
update dot builtin sema checking + new test + fix tests
1 parent b46c602 commit 892621d

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,11 +2466,31 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24662466
case Builtin::BI__builtin_hlsl_dot: {
24672467
if (SemaRef.checkArgCount(TheCall, 2))
24682468
return true;
2469-
if (CheckVectorElementCallArgs(&SemaRef, TheCall))
2469+
// check no bool or bool vectors
2470+
const Expr *Arg0 = TheCall->getArg(0);
2471+
QualType T0 = Arg0->getType();
2472+
const Expr *Arg1 = TheCall->getArg(1);
2473+
QualType T1 = Arg1->getType();
2474+
QualType BoolType = SemaRef.getASTContext().BoolTy;
2475+
if (const auto *VT0 = T0->getAs<VectorType>())
2476+
T0 = VT0->getElementType();
2477+
if (const auto *VT1 = T1->getAs<VectorType>())
2478+
T1 = VT1->getElementType();
2479+
if (SemaRef.Context.hasSameUnqualifiedType(T0, BoolType))
2480+
return SemaRef.Diag(Arg0->getBeginLoc(),
2481+
diag::err_builtin_invalid_arg_type)
2482+
<< 1 << /* scalar or vector of */ 5 << /* integer ty */ 1
2483+
<< /* fp type */ 1 << Arg0->getType();
2484+
if (SemaRef.Context.hasSameUnqualifiedType(T1, BoolType))
2485+
return SemaRef.Diag(Arg1->getBeginLoc(),
2486+
diag::err_builtin_invalid_arg_type)
2487+
<< 2 << /* scalar or vector of */ 5 << /* integer ty */ 1
2488+
<< /* fp type */ 1 << Arg1->getType();
2489+
if (CheckNoDoubleVectors(&SemaRef, TheCall))
24702490
return true;
2471-
if (SemaRef.BuiltinVectorToScalarMath(TheCall))
2491+
if (CheckAllArgsHaveSameType(&SemaRef, TheCall))
24722492
return true;
2473-
if (CheckNoDoubleVectors(&SemaRef, TheCall))
2493+
if (SemaRef.BuiltinVectorToScalarMath(TheCall))
24742494
return true;
24752495
break;
24762496
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,37 @@ int64_t test_builtin_dot_vec_int16_to_int64_promotion(int64_t2 p0,
7676

7777
float test_builtin_dot_float2_splat(float p0, float2 p1) {
7878
return __builtin_hlsl_dot(p0, p1);
79-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
79+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
8080
}
8181

8282
float test_builtin_dot_float3_splat(float p0, float3 p1) {
8383
return __builtin_hlsl_dot(p0, p1);
84-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
84+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
8585
}
8686

8787
float test_builtin_dot_float4_splat(float p0, float4 p1) {
8888
return __builtin_hlsl_dot(p0, p1);
89-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
89+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
9090
}
9191

9292
float test_dot_float2_int_splat(float2 p0, int p1) {
9393
return __builtin_hlsl_dot(p0, p1);
94-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
94+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
9595
}
9696

9797
float test_dot_float3_int_splat(float3 p0, int p1) {
9898
return __builtin_hlsl_dot(p0, p1);
99-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
99+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
100100
}
101101

102102
float test_builtin_dot_int_vect_to_float_vec_promotion(int2 p0, float p1) {
103103
return __builtin_hlsl_dot(p0, p1);
104-
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}}
104+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
105105
}
106106

107107
int test_builtin_dot_bool_type_promotion(bool p0, float p1) {
108108
return __builtin_hlsl_dot(p0, p1);
109-
// expected-error@-1 {{1st argument must be a vector, integer or floating-point type (was 'bool')}}
109+
// expected-error@-1 {{1st argument must be a scalar or vector of integer or floating-point types (was 'bool')}}
110110
}
111111

112112
double test_dot_double(double2 p0, double2 p1) {
@@ -120,10 +120,15 @@ double test_dot_double_builtin(double2 p0, double2 p1) {
120120

121121
float builtin_bool_to_float_type_promotion ( float p0, bool p1 ) {
122122
return __builtin_hlsl_dot ( p0, p1 );
123-
// expected-error@-1 {{are of different types ('float' vs 'bool')}}
123+
// expected-error@-1 {{2nd argument must be a scalar or vector of integer or floating-point types (was 'bool')}}
124124
}
125125

126126
float builtin_dot_int_to_float_promotion ( float p0, int p1 ) {
127127
return __builtin_hlsl_dot (p0, p1 );
128-
// expected-error@-1 {{are of different types ('float' vs 'int')}}
128+
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
129+
}
130+
131+
// should not error
132+
uint builtin_dot_literal_shouldnt_error( uint4 p0) {
133+
return dot(p0, 1u.xxxx);
129134
}

0 commit comments

Comments
 (0)