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;
 }
 


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;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to