]> granicus.if.org Git - clang/commitdiff
[CUDA] do not allow attribute-based overloading for __global__ functions.
authorArtem Belevich <tra@google.com>
Wed, 24 Feb 2016 21:54:45 +0000 (21:54 +0000)
committerArtem Belevich <tra@google.com>
Wed, 24 Feb 2016 21:54:45 +0000 (21:54 +0000)
__global__ functions are present on both host and device side,
so providing __host__ or __device__ overloads is not going to
do anything useful.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261778 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaCUDA/function-overload.cu

index f1b74ad5545aeebdff73eff28d5593e9a8333626..a80a87ed4377485d6b105fb3fc289e3591d76ce1 100644 (file)
@@ -1129,7 +1129,10 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old,
     // Don't allow mixing of HD with other kinds. This guarantees that
     // we have only one viable function with this signature on any
     // side of CUDA compilation .
-    if ((NewTarget == CFT_HostDevice) || (OldTarget == CFT_HostDevice))
+    // __global__ functions can't be overloaded based on attribute
+    // difference because, like HD, they also exist on both sides.
+    if ((NewTarget == CFT_HostDevice) || (OldTarget == CFT_HostDevice) ||
+        (NewTarget == CFT_Global) || (OldTarget == CFT_Global))
       return false;
 
     // Allow overloading of functions with same signature, but
index bc9fe2a1ebb66418ceee6a898ee252fba998a6fd..bdbd550e95784a4bab02d1c0f03934cbffaaa26a 100644 (file)
@@ -302,3 +302,13 @@ struct m_hdd {
   __host__ __device__ void operator delete(void *ptr) {} // expected-note {{previous declaration is here}}
   __device__ void operator delete(void *ptr) {} // expected-error {{class member cannot be redeclared}}
 };
+
+// __global__ functions can't be overloaded based on attribute
+// difference.
+struct G {
+  friend void friend_of_g(G &arg);
+private:
+  int x;
+};
+__global__ void friend_of_g(G &arg) { int x = arg.x; } // expected-note {{previous definition is here}}
+void friend_of_g(G &arg) { int x = arg.x; } // expected-error {{redefinition of 'friend_of_g'}}