Skip to content

Commit 27ab5cc

Browse files
committed
Added sema checks
1 parent 9b07ba9 commit 27ab5cc

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

clang/lib/Sema/SemaAMDGPU.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID,
6363
OrderIndex = 0;
6464
ScopeIndex = 1;
6565
break;
66+
case AMDGPU::BI__builtin_amdgcn_mov_dpp: {
67+
if (SemaRef.checkArgCountRange(TheCall, 5, 5))
68+
return true;
69+
Expr *ValArg = TheCall->getArg(0);
70+
QualType Ty = ValArg->getType();
71+
if (!Ty->isArithmeticType()) {
72+
SemaRef.Diag(ValArg->getBeginLoc(),
73+
diag::err_typecheck_cond_expect_int_float)
74+
<< Ty << ValArg->getSourceRange();
75+
return true;
76+
}
77+
return false;
78+
}
79+
case AMDGPU::BI__builtin_amdgcn_update_dpp: {
80+
if (SemaRef.checkArgCountRange(TheCall, 6, 6))
81+
return true;
82+
for (unsigned I = 0; I != 2; ++I) {
83+
Expr *ValArg = TheCall->getArg(I);
84+
QualType Ty = ValArg->getType();
85+
if (!Ty->isArithmeticType()) {
86+
SemaRef.Diag(ValArg->getBeginLoc(),
87+
diag::err_typecheck_cond_expect_int_float)
88+
<< Ty << ValArg->getSourceRange();
89+
return true;
90+
}
91+
}
92+
return false;
93+
}
6694
default:
6795
return false;
6896
}

clang/test/SemaOpenCL/builtins-amdgcn-error-gfx9.cl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,37 @@ void test_gfx9_fmed3h(global half *out, half a, half b, half c)
77
{
88
*out = __builtin_amdgcn_fmed3h(a, b, c); // expected-error {{'__builtin_amdgcn_fmed3h' needs target feature gfx9-insts}}
99
}
10+
11+
void test_mov_dpp(global int* out, int src, int i)
12+
{
13+
*out = __builtin_amdgcn_mov_dpp(src, i, 0, 0, false); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
14+
*out = __builtin_amdgcn_mov_dpp(src, 0, i, 0, false); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
15+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0, i, false); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
16+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, i); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
17+
*out = __builtin_amdgcn_mov_dpp(src, 0.1, 0, 0, false); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
18+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0.1, 0, false); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
19+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0.1, false); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
20+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, 0.1); // expected-error{{argument to '__builtin_amdgcn_mov_dpp' must be a constant integer}}
21+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0); // expected-error{{too few arguments to function call, expected 5, have 4}}
22+
*out = __builtin_amdgcn_mov_dpp(src, 0, 0, 0, false, 1); // expected-error{{too many arguments to function call, expected at most 5, have 6}}
23+
*out = __builtin_amdgcn_mov_dpp(out, 0, 0, 0, false); // expected-error{{used type '__global int *__private' where integer or floating point type is required}}
24+
*out = __builtin_amdgcn_mov_dpp("aa", 0, 0, 0, false); // expected-error{{used type '__constant char[3]' where integer or floating point type is required}}
25+
}
26+
27+
void test_update_dpp(global int* out, int arg1, int arg2, int i)
28+
{
29+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, i, 0, 0, false); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
30+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, i, 0, false); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
31+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0, i, false); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
32+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0, 0, i); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
33+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0.1, 0, 0, false); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
34+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0.1, 0, false); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
35+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0, 0.1, false); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
36+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0, 0, 0.1); // expected-error{{argument to '__builtin_amdgcn_update_dpp' must be a constant integer}}
37+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0, 0); // expected-error{{too few arguments to function call, expected 6, have 5}}
38+
*out = __builtin_amdgcn_update_dpp(arg1, arg2, 0, 0, 0, false, 1); // expected-error{{too many arguments to function call, expected at most 6, have 7}}
39+
*out = __builtin_amdgcn_update_dpp(out, arg2, 0, 0, 0, false); // expected-error{{used type '__global int *__private' where integer or floating point type is required}}
40+
*out = __builtin_amdgcn_update_dpp(arg1, out, 0, 0, 0, false); // expected-error{{used type '__global int *__private' where integer or floating point type is required}}
41+
*out = __builtin_amdgcn_update_dpp("aa", arg2, 0, 0, 0, false); // expected-error{{used type '__constant char[3]' where integer or floating point type is required}}
42+
*out = __builtin_amdgcn_update_dpp(arg1, "aa", 0, 0, 0, false); // expected-error{{used type '__constant char[3]' where integer or floating point type is required}}
43+
}

0 commit comments

Comments
 (0)