Skip to content

Commit ed2f606

Browse files
committed
[HIP] Perform implicit pointer cast when compiling device code, not when -fcuda-is-device
When compiling HIP device code, we add implicit casts for the pointer arguments being passed to builtin calls. When compiling for the host, apply the same casts for __device__ or __kernel__ functions, since the device side of the source should still pass type checks. This patch changes the condition depending on -fcuda-is-device to depend on if the builtin's caller is marked as __device__ or __kernel__. stack-info: PR: llvm#165387, branch: users/jmmartinez/fix/load_lds_typesignature/1
1 parent e588c7f commit ed2f606

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6734,8 +6734,10 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
67346734
// If Arg is declared in the default address space and Param is declared
67356735
// in a non-default address space, perform an implicit address space cast to
67366736
// the parameter type.
6737-
if (getLangOpts().HIP && getLangOpts().CUDAIsDevice && FD &&
6738-
FD->getBuiltinID()) {
6737+
FunctionDecl *Caller = getCurFunctionDecl(/*AllowLambda =*/true);
6738+
bool CallerIsDevice = Caller && (Caller->hasAttr<CUDAGlobalAttr>() ||
6739+
Caller->hasAttr<CUDADeviceAttr>());
6740+
if (getLangOpts().HIP && CallerIsDevice && FD && FD->getBuiltinID()) {
67396741
for (unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size();
67406742
++Idx) {
67416743
ParmVarDecl *Param = FD->getParamDecl(Idx);

clang/test/SemaHIP/amdgpu-gfx950-load-to-lds.hip

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: amdgpu-registered-target
2-
// RUN: %clang_cc1 -fsyntax-only -triple amdgcn -target-cpu gfx950 -verify=device %s -fcuda-is-device
3-
// RUN: %clang_cc1 -fsyntax-only -triple x86_64 -aux-triple amdgcn -verify=host %s
4-
// device-no-diagnostics
2+
// RUN: %clang_cc1 -fsyntax-only -triple amdgcn -target-cpu gfx950 -verify %s -fcuda-is-device
3+
// RUN: %clang_cc1 -fsyntax-only -triple x86_64 -aux-triple amdgcn -verify %s
4+
// expected-no-diagnostics
55

66
#define __device__ __attribute__((device))
77
#define __global__ __attribute__((global))
@@ -20,11 +20,11 @@ __device__ void i_am_device(void* src, __amdgpu_buffer_rsrc_t rsrc, __shared__ v
2020
__builtin_amdgcn_struct_ptr_buffer_load_lds(rsrc, dst, 12, vindex, voffset, soffset, 0, 0);
2121
__builtin_amdgcn_struct_ptr_buffer_load_lds(rsrc, dst, 16, vindex, voffset, soffset, 0, 0);
2222

23-
__builtin_amdgcn_load_to_lds(src, dst, 1, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
24-
__builtin_amdgcn_load_to_lds(src, dst, 2, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
25-
__builtin_amdgcn_load_to_lds(src, dst, 4, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
26-
__builtin_amdgcn_load_to_lds(src, dst, 12, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
27-
__builtin_amdgcn_load_to_lds(src, dst, 16, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
23+
__builtin_amdgcn_load_to_lds(src, dst, 1, 0, 0);
24+
__builtin_amdgcn_load_to_lds(src, dst, 2, 0, 0);
25+
__builtin_amdgcn_load_to_lds(src, dst, 4, 0, 0);
26+
__builtin_amdgcn_load_to_lds(src, dst, 12, 0, 0);
27+
__builtin_amdgcn_load_to_lds(src, dst, 16, 0, 0);
2828

2929
__builtin_amdgcn_global_load_lds(src, dst, 1, 0 , 0);
3030
__builtin_amdgcn_global_load_lds(src, dst, 2, 0 , 0);
@@ -46,11 +46,11 @@ __global__ void i_am_kernel(void* src, __amdgpu_buffer_rsrc_t rsrc, __shared__ v
4646
__builtin_amdgcn_struct_ptr_buffer_load_lds(rsrc, dst, 12, vindex, voffset, soffset, 0, 0);
4747
__builtin_amdgcn_struct_ptr_buffer_load_lds(rsrc, dst, 16, vindex, voffset, soffset, 0, 0);
4848

49-
__builtin_amdgcn_load_to_lds(src, dst, 1, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
50-
__builtin_amdgcn_load_to_lds(src, dst, 2, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
51-
__builtin_amdgcn_load_to_lds(src, dst, 4, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
52-
__builtin_amdgcn_load_to_lds(src, dst, 12, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
53-
__builtin_amdgcn_load_to_lds(src, dst, 16, 0, 0); // host-error{{cannot initialize a parameter of type '__attribute__((address_space(3))) void *' with an lvalue of type 'void *'}}
49+
__builtin_amdgcn_load_to_lds(src, dst, 1, 0, 0);
50+
__builtin_amdgcn_load_to_lds(src, dst, 2, 0, 0);
51+
__builtin_amdgcn_load_to_lds(src, dst, 4, 0, 0);
52+
__builtin_amdgcn_load_to_lds(src, dst, 12, 0, 0);
53+
__builtin_amdgcn_load_to_lds(src, dst, 16, 0, 0);
5454

5555
__builtin_amdgcn_global_load_lds(src, dst, 1, 0 , 0);
5656
__builtin_amdgcn_global_load_lds(src, dst, 2, 0 , 0);

0 commit comments

Comments
 (0)