================
@@ -173,22 +200,27 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag,
const CallExpr &Call,
for (unsigned Index : Sorted) {
const Expr *Arg = Call.getArg(Index);
if (Commas[Index]) {
- if (Index >= Commas.size()) {
- Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
- } else {
+ if (Index + 1 < Call.getNumArgs()) {
// Remove the next comma
- Commas[Index + 1] = true;
- Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
- {Arg->getBeginLoc(),
- Lexer::getLocForEndOfToken(
- Arg->getEndLoc(), 0, Ctx.getSourceManager(),
Ctx.getLangOpts())
- .getLocWithOffset(1)}));
+ const Expr *NextArg = Call.getArg(Index + 1);
+ auto CommaLoc = GetCommaLoc(Arg->getEndLoc().getLocWithOffset(1),
+ NextArg->getBeginLoc());
+ if (CommaLoc) {
+ Commas[Index + 1] = true;
+ Diag << FixItHint::CreateRemoval(*CommaLoc);
+ }
}
} else {
- Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
- Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc()));
- Commas[Index] = true;
+ // At this point we know Index > 0 because `Commas[0] = true` earlier
+ const Expr *PrevArg = Call.getArg(Index - 1);
+ auto CommaLoc = GetCommaLoc(PrevArg->getEndLoc().getLocWithOffset(1),
----------------
EugeneZelenko wrote:
Ditto.
https://github.com/llvm/llvm-project/pull/118568
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits