Skip to content

Commit fcd7e31

Browse files
authored
[SYCL] Account for extern "C++" blocks in name validation (#5014)
When validating a name declared in scopes such as cl::sycl::kernel_handler, we were assuming that the top-level declaration context would be Decl::TranslationUnit. This is not the case when the header file is wrapped explicitly in extern "C++" blocks. Signed-off-by: Premanand M Rao <[email protected]>
1 parent 5ca3628 commit fcd7e31

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5172,7 +5172,9 @@ bool Util::matchContext(const DeclContext *Ctx,
51725172
return false;
51735173
Ctx = Ctx->getParent();
51745174
}
5175-
return Ctx->isTranslationUnit();
5175+
return Ctx->isTranslationUnit() ||
5176+
(Ctx->isExternCXXContext() &&
5177+
Ctx->getEnclosingNamespaceContext()->isTranslationUnit());
51765178
}
51775179

51785180
bool Util::matchQualifiedTypeName(QualType Ty,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -verify -fsyntax-only %s
2+
3+
// Verify that declaration context validation techniques account for
4+
// header files wrapped in extern "C++" declaration blocks.
5+
6+
// expected-no-diagnostics
7+
8+
extern "C++" {
9+
#include "Inputs/sycl.hpp"
10+
}
11+
12+
using namespace cl::sycl;
13+
14+
int main() {
15+
accessor<int, 1, access::mode::read_write> ok_acc;
16+
17+
kernel_single_task<class use_local>(
18+
[=]() {
19+
ok_acc.use();
20+
});
21+
}

0 commit comments

Comments
 (0)