-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[PCH, CUDA] Take CUDA attributes into account #125127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
During deserialization of CUDA AST we must consider CUDA target attributes to distinguish overloads from redeclarations.
Member
|
@llvm/pr-subscribers-clang Author: Artem Belevich (Artem-B) ChangesDuring deserialization of CUDA AST we must consider CUDA target attributes to distinguish overloads from redeclarations. Full diff: https://github.com/llvm/llvm-project/pull/125127.diff 2 Files Affected:
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cd1bcb3b9a063d8..5e7461365c1ff91 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7224,6 +7224,17 @@ 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,
@@ -7254,7 +7265,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 {
diff --git a/clang/test/PCH/cuda-kernel-call.cu b/clang/test/PCH/cuda-kernel-call.cu
index ffb0c1444fe69a6..32b192147fb36ea 100644
--- a/clang/test/PCH/cuda-kernel-call.cu
+++ b/clang/test/PCH/cuda-kernel-call.cu
@@ -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
@@ -14,12 +16,19 @@ void kcall(void (*kp)()) {
__global__ void kern() {
}
+__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
|
This comment was marked as resolved.
This comment was marked as resolved.
kadircet
approved these changes
Jan 31, 2025
Member
kadircet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot, LGTM!
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
During deserialization of CUDA AST we must consider CUDA target attributes to distinguish overloads from redeclarations. Fixes llvm#106394
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
cuda
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During deserialization of CUDA AST we must consider CUDA target attributes to distinguish overloads from redeclarations.
Fixes #106394