From 0162211c2823195d7c07430dc6a656ee71638d07 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 12 Oct 2017 20:05:42 +0300 Subject: [PATCH] [HIPIFY][#199][Partial fix] Fix for cudaLaunchKernel transformation [Synopsis] If any of kernel arguments is a MACRO its location calculation is wrong (location of its definition is actually calculated). Thus garbage code is being produced on the place of such a MACRO starting from the end of its actual definition. [Solution] Add isMacroBodyExpansion and isMacroArgExpansion checks on kernel arguments. [ROCm/hip commit: 7ee8e2d51b2167de7d24f0e64f21a063d874570d] --- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 1f49313b56..a1af37bf7c 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -3314,7 +3314,17 @@ private: for (unsigned argno = 0; argno < launchKernel->getNumArgs(); argno++) { const Expr *arg = launchKernel->getArg(argno); SourceLocation sl(arg->getLocStart()); + if (SM->isMacroBodyExpansion(sl)) { + sl = SM->getExpansionLoc(sl); + } else if (SM->isMacroArgExpansion(sl)) { + sl = SM->getImmediateSpellingLoc(sl); + } SourceLocation el(arg->getLocEnd()); + if (SM->isMacroBodyExpansion(el)) { + el = SM->getExpansionLoc(el); + } else if (SM->isMacroArgExpansion(el)) { + el = SM->getImmediateSpellingLoc(el); + } SourceLocation stop = Lexer::getLocForEndOfToken(el, 0, *SM, DefaultLangOptions); std::string outs(SM->getCharacterData(sl), SM->getCharacterData(stop) - SM->getCharacterData(sl)); DEBUG(dbgs() << outs << "\n");