Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7224,6 +7224,16 @@ static bool isSameQualifier(const NestedNameSpecifier *X,
return !PX && !PY;
}

static bool hasSameCudaAttrs(const FunctionDecl *A, const FunctionDecl *B) {
if (!A->getASTContext().getLangOpts().CUDA)
return true; // Target attributes are overloadable in CUDA compilation only.
if (A->hasAttr<CUDADeviceAttr>() != B->hasAttr<CUDADeviceAttr>())
return false;
if (A->hasAttr<CUDADeviceAttr>() && B->hasAttr<CUDADeviceAttr>())
return A->hasAttr<CUDAHostAttr>() == B->hasAttr<CUDAHostAttr>();
return true; // unattributed and __host__ functions are the same.
}

/// Determine whether the attributes we can overload on are identical for A and
/// B. Will ignore any overloadable attrs represented in the type of A and B.
static bool hasSameOverloadableAttrs(const FunctionDecl *A,
Expand Down Expand Up @@ -7254,7 +7264,7 @@ static bool hasSameOverloadableAttrs(const FunctionDecl *A,
if (Cand1ID != Cand2ID)
return false;
}
return true;
return hasSameCudaAttrs(A, B);
}

bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const {
Expand Down
11 changes: 11 additions & 0 deletions clang/test/PCH/cuda-kernel-call.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -emit-pch -o %t %s
// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s
// RUN: %clang_cc1 -emit-pch -fcuda-is-device -o %t-device %s
// RUN: %clang_cc1 -fcuda-is-device -include-pch %t-device -fsyntax-only %s

#ifndef HEADER
#define HEADER
Expand All @@ -14,12 +16,21 @@ void kcall(void (*kp)()) {
__global__ void kern() {
}

// Make sure that target overloaded functions remain
// available as overloads after PCH deserialization.
__host__ int overloaded_func();
__device__ int overloaded_func();

#else
// Using the header.

void test() {
kcall(kern);
kern<<<1, 1>>>();
overloaded_func();
}

__device__ void test () {
overloaded_func();
}
#endif