Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12197,7 +12197,7 @@ def err_sycl_entry_point_on_main : Error<
def err_sycl_kernel_name_type : Error<
"'sycl_kernel_entry_point' kernel name argument must be a class type">;
def err_sycl_kernel_name_conflict : Error<
"'sycl_kernel_entry_point' kernel name argument conflicts with a previous"
"'sycl_kernel_entry_point' kernel name %0 conflicts with a previous"
" declaration">;

def warn_cuda_maxclusterrank_sm_90 : Warning<
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -10348,6 +10348,8 @@ class Sema final : public SemaBase {
PrintPragmaAttributeInstantiationPoint();
}
void PrintInstantiationStack();
void
PrintInstantiationStack(std::function<void(const PartialDiagnosticAt &)>);

/// Determines whether we are currently in a context where
/// template argument substitution failures are not considered
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Sema/SemaSYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class SemaSYCL : public SemaBase {
public:
SemaSYCL(Sema &S);

using ContextNotes = SmallVector<PartialDiagnosticAt, 1>;
llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>, ContextNotes>
SYCLKernelEntryContextNotes;

/// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current
/// context is "used as device code".
///
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16069,9 +16069,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
FD->setInvalidDecl();
} else if (Body) {
StmtResult SR = SYCL().BuildSYCLKernelCallStmt(FD, Body);
if (SR.isInvalid())
return nullptr;
Body = SR.get();
if (!SR.isInvalid()) {
Body = SR.get();
}
}
}

Expand Down
32 changes: 20 additions & 12 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,12 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
if (!FD->isInvalidDecl() && !FD->isDependentContext()) {
const SYCLKernelInfo *SKI =
getASTContext().findSYCLKernelInfo(SKEPAttr->getKernelName());
if (SKI) {
if (!declaresSameEntity(FD, SKI->GetKernelEntryPointDecl())) {
// FIXME: This diagnostic should include the origin of the kernel
// FIXME: names; not just the locations of the conflicting declarations.
Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict);
Diag(SKI->GetKernelEntryPointDecl()->getLocation(),
diag::note_previous_declaration);
FD->setInvalidDecl();
}
} else {
if (!SKI) {
// Note: In order to not interfere with SFINAE, we delay the diagnostic of
// conflicting names to when we act on the attribute.
ContextNotes &Notes = SYCLKernelEntryContextNotes[FD];
SemaRef.PrintInstantiationStack(
[&](const PartialDiagnosticAt &PD) { Notes.push_back(PD); });
getASTContext().registerSYCLEntryPointFunction(FD);
}
}
Expand All @@ -373,8 +369,20 @@ StmtResult SemaSYCL::BuildSYCLKernelCallStmt(FunctionDecl *FD, Stmt *Body) {
// stored declaration matches.
const SYCLKernelInfo &SKI =
getASTContext().getSYCLKernelInfo(SKEPAttr->getKernelName());
if (!declaresSameEntity(SKI.GetKernelEntryPointDecl(), FD))
llvm::report_fatal_error("SYCL kernel name conflict");
if (!declaresSameEntity(SKI.GetKernelEntryPointDecl(), FD)) {
Diag(FD->getLocation(), diag::err_sycl_kernel_name_conflict)
<< SKEPAttr->getKernelName();
Diag(SKI.GetKernelEntryPointDecl()->getLocation(),
diag::note_previous_declaration);
for (const PartialDiagnosticAt &PD :
SYCLKernelEntryContextNotes.at(SKI.GetKernelEntryPointDecl())) {
DiagnosticBuilder Builder(
SemaRef.Diags.Report(PD.first, PD.second.getDiagID()));
PD.second.Emit(Builder);
}
FD->setInvalidDecl();
return {/*Invalid=*/true};
}

using ParmDeclMap = OutlinedFunctionDeclBodyInstantiator::ParmDeclMap;
ParmDeclMap ParmMap;
Expand Down
Loading