Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2466,11 +2466,31 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
case Builtin::BI__builtin_hlsl_dot: {
if (SemaRef.checkArgCount(TheCall, 2))
return true;
if (CheckVectorElementCallArgs(&SemaRef, TheCall))
// check no bool or bool vectors
const Expr *Arg0 = TheCall->getArg(0);
QualType T0 = Arg0->getType();
const Expr *Arg1 = TheCall->getArg(1);
QualType T1 = Arg1->getType();
QualType BoolType = SemaRef.getASTContext().BoolTy;
if (const auto *VT0 = T0->getAs<VectorType>())
T0 = VT0->getElementType();
if (const auto *VT1 = T1->getAs<VectorType>())
T1 = VT1->getElementType();
if (SemaRef.Context.hasSameUnqualifiedType(T0, BoolType))
return SemaRef.Diag(Arg0->getBeginLoc(),
diag::err_builtin_invalid_arg_type)
<< 1 << /* scalar or vector of */ 5 << /* integer ty */ 1
<< /* fp type */ 1 << Arg0->getType();
if (SemaRef.Context.hasSameUnqualifiedType(T1, BoolType))
return SemaRef.Diag(Arg1->getBeginLoc(),
diag::err_builtin_invalid_arg_type)
<< 2 << /* scalar or vector of */ 5 << /* integer ty */ 1
<< /* fp type */ 1 << Arg1->getType();
if (CheckNoDoubleVectors(&SemaRef, TheCall))
return true;
if (SemaRef.BuiltinVectorToScalarMath(TheCall))
if (CheckAllArgsHaveSameType(&SemaRef, TheCall))
return true;
if (CheckNoDoubleVectors(&SemaRef, TheCall))
if (SemaRef.BuiltinVectorToScalarMath(TheCall))
return true;
break;
}
Expand Down
23 changes: 14 additions & 9 deletions clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,37 @@ int64_t test_builtin_dot_vec_int16_to_int64_promotion(int64_t2 p0,

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

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

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

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

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

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

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

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

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

float builtin_dot_int_to_float_promotion ( float p0, int p1 ) {
return __builtin_hlsl_dot (p0, p1 );
// expected-error@-1 {{are of different types ('float' vs 'int')}}
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
}

// should not error
uint builtin_dot_literal_shouldnt_error( uint4 p0) {
return dot(p0, 1u.xxxx);
}
Loading