From c6dc157ee223fd090aefe4416638de9ad3c758d0 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Sun, 7 Jan 2024 13:12:14 +0000 Subject: [PATCH] [HIPIFY][#1267][#1266][fix] Correctly delete the last argument from the function call for `e_remove_argument` transformation + [TODO] Add a synthetic test for a single argument deletion --- src/HipifyAction.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/HipifyAction.cpp b/src/HipifyAction.cpp index 34e517b1..b8b3eb1f 100644 --- a/src/HipifyAction.cpp +++ b/src/HipifyAction.cpp @@ -1883,10 +1883,18 @@ bool HipifyAction::cudaHostFuncCall(const mat::MatchFinder::MatchResult &Result) case e_remove_argument: { OS << ""; - if (argNum < call->getNumArgs()) + if (argNum < call->getNumArgs() - 1) { e = call->getArg(argNum + 1)->getBeginLoc(); - else + } + else { e = call->getEndLoc(); + if (call->getNumArgs() > 1) { + auto prevComma = clang::Lexer::findNextToken(call->getArg(argNum - 1)->getSourceRange().getEnd(), *SM, DefaultLangOptions); + if (!prevComma) + s = call->getEndLoc(); + s = prevComma->getLocation(); + } + } length = SM->getCharacterData(e) - SM->getCharacterData(s); break; }