Skip to content

Commit 8477ca6

Browse files
authored
[HIP][Clang][Sema] Fix crash when calling builtins with pointer arguments (#95957)
Crashed when the number of args passed was less than number of parameters in builtin definition, because we were indexing the list of args while iterating through the entire number of parameters.
1 parent dbf12b2 commit 8477ca6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6500,7 +6500,8 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
65006500
// the parameter type.
65016501
if (getLangOpts().HIP && getLangOpts().CUDAIsDevice && FD &&
65026502
FD->getBuiltinID()) {
6503-
for (unsigned Idx = 0; Idx < FD->param_size(); ++Idx) {
6503+
for (unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size();
6504+
++Idx) {
65046505
ParmVarDecl *Param = FD->getParamDecl(Idx);
65056506
if (!ArgExprs[Idx] || !Param || !Param->getType()->isPointerType() ||
65066507
!ArgExprs[Idx]->getType()->isPointerType())
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// REQUIRES: x86-registered-target
3+
4+
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -fsyntax-only -verify %s
5+
6+
void call_amdgpu_builtins() {
7+
__builtin_amdgcn_fence(); // expected-error {{too few arguments to function call, expected at least 2, have 0}}
8+
__builtin_amdgcn_atomic_inc32(); // expected-error {{too few arguments to function call, expected 4, have 0}}
9+
__builtin_amdgcn_atomic_inc32(0); // expected-error {{too few arguments to function call, expected 4, have 1}}
10+
__builtin_amdgcn_atomic_inc32(0, 0); // expected-error {{too few arguments to function call, expected 4, have 2}}
11+
__builtin_amdgcn_atomic_inc32(0, 0, 0); // expected-error {{too few arguments to function call, expected 4, have 3}}
12+
__builtin_amdgcn_atomic_inc64(); // expected-error {{too few arguments to function call, expected 4, have 0}}
13+
__builtin_amdgcn_atomic_dec32(); // expected-error {{too few arguments to function call, expected 4, have 0}}
14+
__builtin_amdgcn_atomic_dec64(); // expected-error {{too few arguments to function call, expected 4, have 0}}
15+
__builtin_amdgcn_div_scale(); // expected-error {{too few arguments to function call, expected 4, have 0}}
16+
__builtin_amdgcn_div_scale(0); // expected-error {{too few arguments to function call, expected 4, have 1}}
17+
__builtin_amdgcn_div_scale(0, 0); // expected-error {{too few arguments to function call, expected 4, have 2}}
18+
__builtin_amdgcn_div_scale(0, 0, 0); // expected-error {{too few arguments to function call, expected 4, have 3}}
19+
__builtin_amdgcn_div_scalef(); // expected-error {{too few arguments to function call, expected 4, have 0}}
20+
__builtin_amdgcn_ds_faddf(); // expected-error {{too few arguments to function call, expected 5, have 0}}
21+
__builtin_amdgcn_ds_fminf(); // expected-error {{too few arguments to function call, expected 5, have 0}}
22+
__builtin_amdgcn_ds_fmaxf(); // expected-error {{too few arguments to function call, expected 5, have 0}}
23+
__builtin_amdgcn_ds_append(); // expected-error {{too few arguments to function call, expected 1, have 0}}
24+
__builtin_amdgcn_ds_consume(); // expected-error {{too few arguments to function call, expected 1, have 0}}
25+
__builtin_amdgcn_is_shared(); // expected-error {{too few arguments to function call, expected 1, have 0}}
26+
__builtin_amdgcn_is_private(); // expected-error {{too few arguments to function call, expected 1, have 0}}
27+
}
28+

0 commit comments

Comments
 (0)