Skip to content

Commit d6ff7dc

Browse files
committed
[PCH, CUDA] Take CUDA attributes into account
During deserialization of CUDA AST we must consider CUDA target attributes to distinguish overloads from redeclarations.
1 parent b108fbe commit d6ff7dc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7224,6 +7224,17 @@ static bool isSameQualifier(const NestedNameSpecifier *X,
72247224
return !PX && !PY;
72257225
}
72267226

7227+
static bool hasSameCudaAttrs(const FunctionDecl *A,
7228+
const FunctionDecl *B) {
7229+
if (!A->getASTContext().getLangOpts().CUDA)
7230+
return true; // Target attributes are overloadable in CUDA compilation only.
7231+
if (A->hasAttr<CUDADeviceAttr>() != B->hasAttr<CUDADeviceAttr>())
7232+
return false;
7233+
if (A->hasAttr<CUDADeviceAttr>() && B->hasAttr<CUDADeviceAttr>())
7234+
return A->hasAttr<CUDAHostAttr>() == B->hasAttr<CUDAHostAttr>();
7235+
return true; // unattributed and __host__ functions are the same.
7236+
}
7237+
72277238
/// Determine whether the attributes we can overload on are identical for A and
72287239
/// B. Will ignore any overloadable attrs represented in the type of A and B.
72297240
static bool hasSameOverloadableAttrs(const FunctionDecl *A,
@@ -7254,7 +7265,7 @@ static bool hasSameOverloadableAttrs(const FunctionDecl *A,
72547265
if (Cand1ID != Cand2ID)
72557266
return false;
72567267
}
7257-
return true;
7268+
return hasSameCudaAttrs(A, B);
72587269
}
72597270

72607271
bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const {

clang/test/PCH/cuda-kernel-call.cu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -emit-pch -o %t %s
22
// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s
3+
// RUN: %clang_cc1 -emit-pch -fcuda-is-device -o %t-device %s
4+
// RUN: %clang_cc1 -fcuda-is-device -include-pch %t-device -fsyntax-only %s
35

46
#ifndef HEADER
57
#define HEADER
@@ -14,12 +16,19 @@ void kcall(void (*kp)()) {
1416
__global__ void kern() {
1517
}
1618

19+
__host__ int overloaded_func();
20+
__device__ int overloaded_func();
21+
1722
#else
1823
// Using the header.
1924

2025
void test() {
2126
kcall(kern);
2227
kern<<<1, 1>>>();
28+
overloaded_func();
2329
}
2430

31+
__device__ void test () {
32+
overloaded_func();
33+
}
2534
#endif

0 commit comments

Comments
 (0)