From d6e8596c91dd21a320b2d49861f01204f79093bf Mon Sep 17 00:00:00 2001 From: atimofee Date: Wed, 24 Feb 2016 21:22:32 +0300 Subject: [PATCH] String literal bug fixed + string literal processing refactoring [ROCm/hip commit: 0438f7959e2a2140a1a2f2311e7eb6654d20d868] --- projects/hip/src/Cuda2Hip.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/projects/hip/src/Cuda2Hip.cpp b/projects/hip/src/Cuda2Hip.cpp index 83df1c95b1..5a1432a185 100644 --- a/projects/hip/src/Cuda2Hip.cpp +++ b/projects/hip/src/Cuda2Hip.cpp @@ -453,26 +453,22 @@ class Cuda2HipCallback : public MatchFinder::MatchCallback { if (const StringLiteral * stringLiteral = Result.Nodes.getNodeAs("stringLiteral")) { StringRef s = stringLiteral->getString(); - std::pair split = s.split("cuda"); - StringRef cuda = split.second; - while (!cuda.empty()) { - size_t byteNum = split.first.size(); - cuda = cuda.data() - 4; - std::pair name_pair = cuda.split(' '); - StringRef name = name_pair.first; + size_t begin = 0; + while ((begin = s.find("cuda", begin)) != StringRef::npos) { + const size_t end = s.find_first_of(" ", begin + 4); + StringRef name = s.slice(begin, end); llvm::outs() << "\nToken: <" << name << "> found in string literal " << s << "\n"; StringRef repName = N.cuda2hipRename[name]; - if (!repName.empty()) - { - llvm::outs() << "\nWill be replaced with: <" << repName << ">\n"; - SourceLocation sl = stringLiteral->getLocationOfByte(byteNum, *SM, - Result.Context->getLangOpts(), Result.Context->getTargetInfo()); - Replacement Rep(*SM, SM->isMacroArgExpansion(sl) ? - SM->getImmediateSpellingLoc(sl) : sl, name.size(), repName); + if (!repName.empty()) { + llvm::outs() << "\nWill be replaced with: <" << repName << "\n"; + SourceLocation sl = stringLiteral->getLocationOfByte(begin, *SM, + Result.Context->getLangOpts(), Result.Context->getTargetInfo()); + Replacement Rep(*SM, SM->isMacroArgExpansion(sl) ? + SM->getImmediateSpellingLoc(sl) : sl, name.size(), repName); Replace->insert(Rep); } - split = name_pair.second.split("cuda"); - cuda = split.second; + if (end == StringRef::npos) break; + begin = end + 1; } } }