Skip to content

[SYCL] Account for extern "C++" blocks in name validation #5014

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 2 commits into from
Nov 24, 2021
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
4 changes: 3 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5151,7 +5151,9 @@ bool Util::matchContext(const DeclContext *Ctx,
return false;
Ctx = Ctx->getParent();
}
return Ctx->isTranslationUnit();
return Ctx->isTranslationUnit() ||
(Ctx->isExternCXXContext() &&
Ctx->getEnclosingNamespaceContext()->isTranslationUnit());
}

bool Util::matchQualifiedTypeName(QualType Ty,
Expand Down
21 changes: 21 additions & 0 deletions clang/test/SemaSYCL/extern_cpp_decl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify -fsyntax-only %s

// Verify that declaration context validation techniques account for
// header files wrapped in extern "C++" declaration blocks.

// expected-no-diagnostics

extern "C++" {
#include "Inputs/sycl.hpp"
}

using namespace cl::sycl;

int main() {
accessor<int, 1, access::mode::read_write> ok_acc;

kernel_single_task<class use_local>(
[=]() {
ok_acc.use();
});
}