Currently clang does not allow implicit cast of a pointer to a pointer type in different address space but allows C-style cast of a pointer to a pointer type in different address space. However, there is a bug in Sema causing incorrect Cast Expr in AST for the latter case, which in turn results in invalid LLVM IR in codegen. This is because Sema::IsQualificationConversion returns true for a cast of pointer to a pointer type in different address space, which in turn allows a standard conversion and results in a cast expression with no op in AST. This patch fixes that by let Sema::IsQualificationConversion returns false for a cast of pointer to a pointer type in different address space, which in turn disallows standard conversion, implicit cast, and static cast. Finally it results in an reinterpret cast and correct conversion kind is set. Differential Revision: https://reviews.llvm.org/D49294 llvm-svn: 337540
16 lines
586 B
C++
16 lines
586 B
C++
// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck %s
|
|
|
|
#define __private__ __attribute__((address_space(5)))
|
|
|
|
void func_pchar(__private__ char *x);
|
|
|
|
void test_cast(char *gen_ptr) {
|
|
// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
|
|
// CHECK-NEXT: store i8 addrspace(5)* %[[cast]]
|
|
__private__ char *priv_ptr = (__private__ char *)gen_ptr;
|
|
|
|
// CHECK: %[[cast:.*]] = addrspacecast i8* %{{.*}} to i8 addrspace(5)*
|
|
// CHECK-NEXT: call void @_Z10func_pcharPU3AS5c(i8 addrspace(5)* %[[cast]])
|
|
func_pchar((__private__ char *)gen_ptr);
|
|
}
|