[PATCH] D61319: [PR41674] [OpenCL] Fix initialisation of this via pointer
Kévin Petit via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 30 09:33:47 PDT 2019
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61319.197351.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190430/c4364477/attachment.bin>
More information about the cfe-commits
mailing list