From f3ef9424078677fa8983935660af141105f3bb98 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. --- hipamd/hipify-clang/src/Cuda2Hip.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hipamd/hipify-clang/src/Cuda2Hip.cpp b/hipamd/hipify-clang/src/Cuda2Hip.cpp index 1f49313b56..a1af37bf7c 100644 --- a/hipamd/hipify-clang/src/Cuda2Hip.cpp +++ b/hipamd/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");