Skip to content

Commit 18ea213

Browse files
jmmartinez丹治秀樹
authored andcommitted
[HIP] Perform implicit pointer cast when compiling HIP, not when -fcuda-is-device (llvm#165387)
When compiling HIP device code, we add implicit casts for the pointer arguments passed to built-in calls. When compiling for the host, apply the same casts, since the device side of the source (device functions and kernels) should still pass type checks.
1 parent 3f36f2d commit 18ea213

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6736,14 +6736,13 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
67366736

67376737
checkDirectCallValidity(*this, Fn, FD, ArgExprs);
67386738

6739-
// If this expression is a call to a builtin function in HIP device
6740-
// compilation, allow a pointer-type argument to default address space to be
6741-
// passed as a pointer-type parameter to a non-default address space.
6742-
// If Arg is declared in the default address space and Param is declared
6743-
// in a non-default address space, perform an implicit address space cast to
6744-
// the parameter type.
6745-
if (getLangOpts().HIP && getLangOpts().CUDAIsDevice && FD &&
6746-
FD->getBuiltinID()) {
6739+
// If this expression is a call to a builtin function in HIP compilation,
6740+
// allow a pointer-type argument to default address space to be passed as a
6741+
// pointer-type parameter to a non-default address space. If Arg is declared
6742+
// in the default address space and Param is declared in a non-default
6743+
// address space, perform an implicit address space cast to the parameter
6744+
// type.
6745+
if (getLangOpts().HIP && FD && FD->getBuiltinID()) {
67476746
for (unsigned Idx = 0; Idx < ArgExprs.size() && Idx < FD->param_size();
67486747
++Idx) {
67496748
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)