Skip to content

Commit f84e2c9

Browse files
committed
implement @hekota suggestion, add warning to test, add comments
1 parent 1139101 commit f84e2c9

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,16 +2048,14 @@ static bool CheckAllArgTypesAreCorrect(
20482048
static bool CheckFloatOrHalfVecRepresentation(Sema *S, SourceLocation Loc,
20492049
int ArgOrdinal,
20502050
clang::QualType PassedType) {
2051-
QualType EltTy = PassedType;
2052-
if (auto *VecTy = EltTy->getAs<VectorType>())
2053-
EltTy = VecTy->getElementType();
2051+
if (auto *VecTy = PassedType->getAs<VectorType>())
2052+
if (VecTy->getElementType()->isHalfType() ||
2053+
VecTy->getElementType()->isFloat32Type())
2054+
return false;
20542055

2055-
if (!PassedType->getAs<VectorType>() ||
2056-
!(EltTy->isHalfType() || EltTy->isFloat32Type()))
2057-
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
2058-
<< ArgOrdinal << /* vector of */ 4 << /* no int */ 0
2059-
<< /* half or float */ 2 << PassedType;
2060-
return false;
2056+
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
2057+
<< ArgOrdinal << /* vector of */ 4 << /* no int */ 0
2058+
<< /* half or float */ 2 << PassedType;
20612059
}
20622060

20632061
static bool CheckFloatOrHalfRepresentation(Sema *S, SourceLocation Loc,
@@ -2109,17 +2107,16 @@ static bool CheckFloatingOrIntRepresentation(Sema *S, SourceLocation Loc,
21092107
static bool CheckUnsignedIntVecRepresentation(Sema *S, SourceLocation Loc,
21102108
int ArgOrdinal,
21112109
clang::QualType PassedType) {
2112-
QualType EltTy = PassedType;
2113-
if (auto *VecTy = EltTy->getAs<VectorType>())
2114-
EltTy = VecTy->getElementType();
2110+
if (auto *VecTy = PassedType->getAs<VectorType>())
2111+
if (VecTy->getElementType()->isUnsignedIntegerType())
2112+
return false;
21152113

2116-
if (!PassedType->getAs<VectorType>() || !EltTy->isUnsignedIntegerType())
2117-
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
2118-
<< ArgOrdinal << /* vector of */ 4 << /* uint */ 3 << /* no fp */ 0
2119-
<< PassedType;
2120-
return false;
2114+
return S->Diag(Loc, diag::err_builtin_invalid_arg_type)
2115+
<< ArgOrdinal << /* vector of */ 4 << /* uint */ 3 << /* no fp */ 0
2116+
<< PassedType;
21212117
}
21222118

2119+
// checks for unsigned ints of all sizes
21232120
static bool CheckUnsignedIntRepresentation(Sema *S, SourceLocation Loc,
21242121
int ArgOrdinal,
21252122
clang::QualType PassedType) {
@@ -2387,10 +2384,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
23872384
if (SemaRef.checkArgCount(TheCall, 2))
23882385
return true;
23892386
if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy,
2390-
0))
2387+
0)) // only check for uint
23912388
return true;
23922389
if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.UnsignedIntTy,
2393-
1))
2390+
1)) // only check for uint
23942391
return true;
23952392
if (CheckAllArgsHaveSameType(&SemaRef, TheCall))
23962393
return true;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected=note,warning
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected=note
22

33
float2 test_no_second_arg(float2 p0) {
44
return __builtin_hlsl_mad(p0);
@@ -23,6 +23,7 @@ float2 test_mad_no_second_arg(float2 p0) {
2323
float2 test_mad_vector_size_mismatch(float3 p0, float2 p1) {
2424
return mad(p0, p0, p1);
2525
// expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}
26+
// expected-warning@-2 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}}
2627
}
2728

2829
float2 test_mad_builtin_vector_size_mismatch(float3 p0, float2 p1) {

0 commit comments

Comments
 (0)