Skip to content

Commit 4eba766

Browse files
committed
reorganized sema spirv checks, added target env to validation step of spirv backend tests
1 parent 9398b77 commit 4eba766

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

clang/lib/Sema/SemaSPIRV.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,44 +106,34 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID,
106106
return true;
107107

108108
// check if the all arguments have floating representation
109-
ExprResult A = TheCall->getArg(0);
110-
QualType ArgTyA = A.get()->getType();
111-
if (!ArgTyA->hasFloatingRepresentation()) {
112-
SemaRef.Diag(A.get()->getBeginLoc(),
113-
diag::err_typecheck_convert_incompatible)
114-
<< ArgTyA << SemaRef.Context.FloatTy << 1 << 0 << 0;
115-
return true;
109+
for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) {
110+
ExprResult Arg = TheCall->getArg(i);
111+
QualType ArgTy = Arg.get()->getType();
112+
if (!ArgTy->hasFloatingRepresentation()) {
113+
SemaRef.Diag(Arg.get()->getBeginLoc(),
114+
diag::err_builtin_invalid_arg_type)
115+
<< i + 1 << /* scalar or vector */ 5 << /* no int */ 0 << /* fp */ 1
116+
<< ArgTy;
117+
return true;
118+
}
116119
}
117120

121+
// check if all arguments are of the same type
122+
ExprResult A = TheCall->getArg(0);
118123
ExprResult B = TheCall->getArg(1);
119-
QualType ArgTyB = B.get()->getType();
120-
if (!ArgTyB->hasFloatingRepresentation()) {
121-
SemaRef.Diag(A.get()->getBeginLoc(),
122-
diag::err_typecheck_convert_incompatible)
123-
<< ArgTyB << SemaRef.Context.FloatTy << 1 << 0 << 0;
124-
return true;
125-
}
126-
127124
ExprResult C = TheCall->getArg(2);
128-
QualType ArgTyC = C.get()->getType();
129-
if (!ArgTyC->hasFloatingRepresentation()) {
130-
SemaRef.Diag(A.get()->getBeginLoc(),
131-
diag::err_typecheck_convert_incompatible)
132-
<< ArgTyC << SemaRef.Context.FloatTy << 1 << 0 << 0;
133-
return true;
134-
}
135-
136-
// check if all arguments are of the same type
137-
if (!(SemaRef.getASTContext().hasSameUnqualifiedType(ArgTyA, ArgTyB) &&
138-
SemaRef.getASTContext().hasSameUnqualifiedType(ArgTyA, ArgTyC))) {
125+
if (!(SemaRef.getASTContext().hasSameUnqualifiedType(A.get()->getType(),
126+
B.get()->getType()) &&
127+
SemaRef.getASTContext().hasSameUnqualifiedType(A.get()->getType(),
128+
C.get()->getType()))) {
139129
SemaRef.Diag(TheCall->getBeginLoc(),
140130
diag::err_vec_builtin_incompatible_vector)
141131
<< TheCall->getDirectCallee() << /*useAllTerminology*/ true
142132
<< SourceRange(A.get()->getBeginLoc(), C.get()->getEndLoc());
143133
return true;
144134
}
145135

146-
QualType RetTy = ArgTyA;
136+
QualType RetTy = A.get()->getType();
147137
TheCall->setType(RetTy);
148138
break;
149139
}

clang/test/SemaSPIRV/BuiltIns/smoothstep-errors.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ float2 test_too_many_arg(float2 p0) {
2020

2121
int test_int_scalar_inputs(int p0) {
2222
return __builtin_spirv_smoothstep(p0, p0, p0);
23-
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}}
23+
// expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int')}}
24+
}
25+
26+
float test_int_scalar_inputs2(float p0, int p1) {
27+
return __builtin_spirv_smoothstep(p0, p1, p1);
28+
// expected-error@-1 {{2nd argument must be a scalar or vector of floating-point types (was 'int')}}
29+
}
30+
31+
float test_int_scalar_inputs3(float p0, int p1) {
32+
return __builtin_spirv_smoothstep(p0, p0, p1);
33+
// expected-error@-1 {{3rd argument must be a scalar or vector of floating-point types (was 'int')}}
2434
}
2535

2636
float test_mismatched_arg(float p0, float2 p1) {

llvm/test/CodeGen/SPIRV/hlsl-intrinsics/smoothstep.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
2-
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val --target-env vulkan1.2 %}
33

44
; Make sure SPIRV operation function calls for smoothstep are lowered correctly.
55

llvm/test/CodeGen/SPIRV/opencl/smoothstep.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
22
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
3-
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4-
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val --target-env vulkan1.2 %}
4+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val --target-env vulkan1.2 %}
55

66
; CHECK-DAG: %[[#op_ext_cl:]] = OpExtInstImport "OpenCL.std"
77

0 commit comments

Comments
 (0)