We should track mutation of a variable within a comma operator expression.
Current code in ExprMutationAnalyzer does not handle it.
This will handle cases like:
(a, b) ++ < == b is modified
(a, b) = c < == b is modifed
Differential D58894
[analyzer] Handle modification of vars inside an expr with comma operator djtodoro on Mar 3 2019, 11:43 PM. Authored by
Details We should track mutation of a variable within a comma operator expression. This will handle cases like: (a, b) ++ < == b is modified
Diff Detail
Event TimelineComment Actions Thank you for working on this! Is there any way to model this more generically? Comment Actions @lebedev.ri Thanks for your comment!
Hmm, I am not sure if there is a place for that, since this is very specific to comma operators. Any suggestions ?
This needs to be extended to support function/method calls. I guess ExprMutationAnalyzer::findFunctionArgMutation requires an improvement. Comment Actions Well, given // LHS of any assignment operators. const auto AsAssignmentLhs = binaryOperator(isAssignmentOperator(), hasLHS(equalsNode(Exp))); The problem is that hasLHS() may get , op. Now, i don't know the final solution, but have you considered adding something like: AST_MATCHER_P(Expr, skipCommaOps, ast_matchers::internal::Matcher<Expr>, InnerMatcher) { const Expr* Result = Node; while (const auto *BOComma = dyn_cast_or_null<BinaryOperator>(Result->IgnoreParens())) { if (!BOComma->isCommaOp()) break; Result = BOComma->getRHS(); } return Result; } and then simply changing // LHS of any assignment operators. const auto AsAssignmentLhs = binaryOperator(isAssignmentOperator(), hasLHS(equalsNode(Exp))); to // LHS of any assignment operators. const auto AsAssignmentLhs = binaryOperator(isAssignmentOperator(), hasLHS(skipCommaOps(equalsNode(Exp)))); ? Comment Actions @lebedev.ri I agree, thank you! I needed to be more precise in my previous reply, sorry for that. I thought it will be (somehow) overhead if I change existing, very basic, matchers. I already implemented a static function that skips comma operands, and extended this to support member calls, functions, etc. Thanks! Comment Actions I indeed don't think the existing matchers should be changed to ignore these , ops (or implicit casts, like some issue reports propose).
Yes. I think this matcher will be very baseline, and can just be added where needed
Thanks for working on this. Comment Actions -add AST matcher that skips operands in comma expression Comment Actions
@lebedev.ri I agree, we are on the same page! Thanks! Comment Actions Nice, i like this!
Comment Actions
@lebedev.ri Thanks!
For sure some of them (maybe all of them) needs usage of the new comma matcher.
Comment Actions Anyways, this looks good in this state. If you don't intend to immediately work on fixing the rest of , cases here,
Comment Actions
Thanks!
I already extended this in order to support the rest of direct mutations.
Comment Actions Still LG. |