Skip to content

Commit 9c73c14

Browse files
committed
[CUDA][HIP] Fix implicit attribute of builtin
When a builtin function with generic pointer parameter is passed a pointer with address space, clang creates an overloaded builtin function but does not make it implicit. This causes error when the builtin is called by device functions since CUDA/HIP relies on the implicit attribute to treat a builtin function as callable on both host and device sides. Fixed by making the created overloaded builtin functions implicit.
1 parent 0e9740e commit 9c73c14

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6358,6 +6358,7 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context,
63586358
}
63596359
OverloadDecl->setParams(Params);
63606360
Sema->mergeDeclAttributes(OverloadDecl, FDecl);
6361+
OverloadDecl->setImplicit(true);
63616362
return OverloadDecl;
63626363
}
63636364

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// expected-no-diagnostics
2+
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa -fsyntax-only -verify -xhip %s
4+
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fsyntax-only -fcuda-is-device -verify -xhip %s
5+
6+
#include "Inputs/cuda.h"
7+
8+
__global__ void kernel() {
9+
__attribute__((address_space(0))) void *mem_ptr;
10+
(void)__builtin_amdgcn_is_shared(mem_ptr);
11+
}
12+
13+
template<typename T>
14+
__global__ void template_kernel(T *p) {
15+
__attribute__((address_space(0))) void *mem_ptr;
16+
(void)__builtin_amdgcn_is_shared(mem_ptr);
17+
}
18+
19+
int main() {
20+
int *p;
21+
kernel<<<1,1>>>();
22+
template_kernel<<<1,1>>>(p);
23+
}

0 commit comments

Comments
 (0)