Skip to content

Commit 4e8c5b0

Browse files
committed
[SYCL] Fix integration header generator to handle anonymous namespace.
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent ee585e9 commit 4e8c5b0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,15 @@ static void populateIntHeader(SYCLIntegrationHeader &H, const StringRef Name,
659659
visitKernelLambdaCaptures(Lambda, Vis);
660660
}
661661

662+
// Removes all "(anonymous namespace)::" substrings from given string
663+
static std::string eraseAnonNamespace(std::string S) {
664+
const char S1[] = "(anonymous namespace)::";
665+
666+
for (auto Pos = S.find(S1); Pos != StringRef::npos; Pos = S.find(S1, Pos))
667+
S.erase(Pos, sizeof(S1)-1);
668+
return S;
669+
}
670+
662671
// Creates a kernel name for given kernel name type which is unique across all
663672
// instantiations of the type if it is templated. If it is not templated,
664673
// uniqueueness is prescribed by the SYCL spec. 'class' and 'struct' keywords
@@ -670,10 +679,10 @@ static std::string constructKernelName(QualType KernelNameType) {
670679
std::string TStr = KernelNameType.getAsString();
671680

672681
for (const std::string &Kwd : Kwds) {
673-
for (size_t Pos = TStr.find(Kwd); Pos != StringRef::npos;
682+
for (auto Pos = TStr.find(Kwd); Pos != StringRef::npos;
674683
Pos = TStr.find(Kwd, Pos)) {
675684

676-
size_t EndPos = Pos + Kwd.length();
685+
auto EndPos = Pos + Kwd.length();
677686
if ((Pos == 0 || !llvm::isAlnum(TStr[Pos - 1])) &&
678687
(EndPos == TStr.length() || !llvm::isAlnum(TStr[EndPos]))) {
679688
// keyword is a separate word - erase
@@ -682,7 +691,7 @@ static std::string constructKernelName(QualType KernelNameType) {
682691
Pos = EndPos;
683692
}
684693
}
685-
return StringRef(TStr).trim().str();
694+
return StringRef(eraseAnonNamespace(TStr)).trim();
686695
}
687696

688697
void Sema::ConstructSYCLKernel(FunctionDecl *KernelCallerFunc) {
@@ -961,8 +970,8 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
961970

962971
for (const KernelDesc &K : KernelDescs) {
963972
const size_t N = K.Params.size();
964-
O << "template <> struct KernelInfo<" << K.NameType.getAsString()
965-
<< "> {\n";
973+
O << "template <> struct KernelInfo<"
974+
<< eraseAnonNamespace(K.NameType.getAsString()) << "> {\n";
966975
O << " static constexpr const char* getName() { return \"" << K.Name
967976
<< "\"; }\n";
968977
O << " static constexpr unsigned getNumParams() { return " << N << "; }\n";

0 commit comments

Comments
 (0)