kpet created this revision. kpet added reviewers: Anastasia, mikael. Herald added subscribers: cfe-commits, yaxunl. Herald added a project: clang.
When the expression used to initialise this has a pointer type, check the address space of the pointee type instead of the pointer type to decide whether an address space cast is required. It is the pointee type that carries the address space qualifier. Repository: rC Clang https://reviews.llvm.org/D61319 Files: lib/Sema/SemaOverload.cpp test/SemaOpenCLCXX/this-initialisation-from-pointer.cl Index: test/SemaOpenCLCXX/this-initialisation-from-pointer.cl =================================================================== --- /dev/null +++ test/SemaOpenCLCXX/this-initialisation-from-pointer.cl @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -cl-std=c++ -triple spir -fsyntax-only -verify -ast-dump %s | FileCheck %s +// expected-no-diagnostics + +struct foo { + void init() { + m_data = 1; + } +private: + int m_data; +}; + +kernel void test(global struct foo* afoo) { + afoo->init(); + // CHECK: CXXMemberCallExpr {{.*}} <line:{{[0-9]+}}:{{[0-9]+}}, col:{{[0-9]+}}> 'void' + // CHECK-NEXT: MemberExpr {{.*}} <col:{{[0-9]+}}, col:{{[0-9]+}}> '<bound member function type>' ->init {{.*}} + // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{[0-9]+}}> '__generic foo *' <AddressSpaceConversion> +} Index: lib/Sema/SemaOverload.cpp =================================================================== --- lib/Sema/SemaOverload.cpp +++ lib/Sema/SemaOverload.cpp @@ -5278,12 +5278,12 @@ } if (!Context.hasSameType(From->getType(), DestType)) { - if (From->getType().getAddressSpace() != DestType.getAddressSpace()) - From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion, - From->getValueKind()).get(); + CastKind CK; + if (FromRecordType.getAddressSpace() != DestType.getAddressSpace()) + CK = CK_AddressSpaceConversion; else - From = ImpCastExprToType(From, DestType, CK_NoOp, - From->getValueKind()).get(); + CK = CK_NoOp; + From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get(); } return From; }
Index: test/SemaOpenCLCXX/this-initialisation-from-pointer.cl =================================================================== --- /dev/null +++ test/SemaOpenCLCXX/this-initialisation-from-pointer.cl @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -cl-std=c++ -triple spir -fsyntax-only -verify -ast-dump %s | FileCheck %s +// expected-no-diagnostics + +struct foo { + void init() { + m_data = 1; + } +private: + int m_data; +}; + +kernel void test(global struct foo* afoo) { + afoo->init(); + // CHECK: CXXMemberCallExpr {{.*}} <line:{{[0-9]+}}:{{[0-9]+}}, col:{{[0-9]+}}> 'void' + // CHECK-NEXT: MemberExpr {{.*}} <col:{{[0-9]+}}, col:{{[0-9]+}}> '<bound member function type>' ->init {{.*}} + // CHECK-NEXT: ImplicitCastExpr {{.*}} <col:{{[0-9]+}}> '__generic foo *' <AddressSpaceConversion> +} Index: lib/Sema/SemaOverload.cpp =================================================================== --- lib/Sema/SemaOverload.cpp +++ lib/Sema/SemaOverload.cpp @@ -5278,12 +5278,12 @@ } if (!Context.hasSameType(From->getType(), DestType)) { - if (From->getType().getAddressSpace() != DestType.getAddressSpace()) - From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion, - From->getValueKind()).get(); + CastKind CK; + if (FromRecordType.getAddressSpace() != DestType.getAddressSpace()) + CK = CK_AddressSpaceConversion; else - From = ImpCastExprToType(From, DestType, CK_NoOp, - From->getValueKind()).get(); + CK = CK_NoOp; + From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get(); } return From; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits