From cbf786a8fd2f3ed82da789837b72b0806bb591f6 Mon Sep 17 00:00:00 2001 From: Chris Kitching Date: Wed, 18 Oct 2017 11:25:17 +0100 Subject: [PATCH] Don't special-case source locations for calls in macros The source location for a call that's inside a macro body will, by default, point into the macro definition itself. The original logic was causing macro invocations to be overwritten, as I explain here: https://github.com/ROCm-Developer-Tools/HIP/issues/207#issuecomment-337521851 The existing PPCallbacks code is correctly rewriting macro definitions, so the practical effect of this change is that AST rewrites on code that's expanded from macros are no-ops. It might be a performance optimisation to put a short-circiut at the top of the AST callbacks to abort when faced with code that was expanded from macros. It might yet prove wise to do absolutely everything at lex-time... [ROCm/hip commit: 4a794ed8c091df88565e0d2cc1b937083b2c509f] --- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 26 ++++------------------ 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 046b3823ec..a3ec11ff1a 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -531,28 +531,10 @@ private: } size_t length = name.size(); - bool bReplace = true; - if (SM->isMacroArgExpansion(sl)) { - sl = SM->getImmediateSpellingLoc(sl); - } else if (SM->isMacroBodyExpansion(sl)) { - LangOptions DefaultLangOptions; - SourceLocation sl_macro = SM->getExpansionLoc(sl); - SourceLocation sl_end = Lexer::getLocForEndOfToken(sl_macro, 0, *SM, DefaultLangOptions); - length = SM->getCharacterData(sl_end) - SM->getCharacterData(sl_macro); - StringRef macroName = StringRef(SM->getCharacterData(sl_macro), length); - if (CUDA_EXCLUDES.end() != CUDA_EXCLUDES.find(macroName)) { - bReplace = false; - } else { - sl = sl_macro; - } - } - - if (bReplace) { - updateCounters(found->second, name); - Replacement Rep(*SM, sl, length, hipCtr.hipName); - FullSourceLoc fullSL(sl, *SM); - insertReplacement(Rep, fullSL); - } + updateCounters(found->second, name); + Replacement Rep(*SM, sl, length, hipCtr.hipName); + FullSourceLoc fullSL(sl, *SM); + insertReplacement(Rep, fullSL); return true; }