[PATCH] D102850: [C++4OpenCL] Allow address space conversion in reinterpret_cast
Ole Strohm via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 20 08:55:56 PDT 2021
olestrohm created this revision.
olestrohm added reviewers: Anastasia, svenvh.
olestrohm added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
olestrohm requested review of this revision.
Herald added a subscriber: cfe-commits.
This fixes the prioritization of address spaces when choosing a constructor,
stopping them from being considered equally good, which made the construction
of types that could be constructed by more than one of the constructors.
It does this by preferring the most specific address space, which is decided by seeing
if one of the address spaces is a superset of the other, and preferring the other.
Fixes: PR50329
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102850
Files:
clang/lib/Sema/SemaOverload.cpp
clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===================================================================
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -11,8 +11,7 @@
int x;
// Local variables are handled in local_addrspace_init.clcpp
- // FIXME: __private and __generic constructors clash for __private variable
- // X() /*__generic*/ = default;
+ X() /*__generic*/ = default;
X() __private : x(0) {}
X() __global : x(0) {}
constexpr X() __constant : x(0) {}
@@ -30,7 +29,7 @@
// CHECK: @_ZZ1kE3cx2 = internal addrspace(2) constant %struct.X { i32 1 }
kernel void k() {
- // Check that the constructor for px is executed
+ // Check that the constructor for px calls the __private constructor
// CHECK: %px = alloca %struct.X
// CHECK-NEXT: call spir_func void @_ZN1XC1Ev(%struct.X* {{.*}}%px)
__private X px;
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9867,6 +9867,16 @@
S.IdentifyCUDAPreference(Caller, Cand2.Function);
}
+ if (S.getLangOpts().OpenCL) {
+ if (const auto *CD1 = dyn_cast_or_null<CXXConstructorDecl>(Cand1.Function)) {
+ if (const auto *CD2 = dyn_cast_or_null<CXXConstructorDecl>(Cand2.Function)) {
+ return Qualifiers::isAddressSpaceSupersetOf(
+ CD2->getMethodQualifiers().getAddressSpace(),
+ CD1->getMethodQualifiers().getAddressSpace());
+ }
+ }
+ }
+
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102850.346756.patch
Type: text/x-patch
Size: 1640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210520/be025d8f/attachment.bin>
More information about the cfe-commits
mailing list