[PATCH] D136423: [clang][Interp] Implement inc/dec postfix and prefix operators

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 24 08:05:08 PDT 2022


tbaeder added inline comments.


================
Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1237-1240
+    if (DiscardResult)
+      return this->emitIncPop(*T, E);
+
+    return this->emitInc(*T, E);
----------------
aaron.ballman wrote:
> Style question: should we prefer doing something like: `return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);` to discourage accidentally adding code between the two increment operations? (And applying this style more generally for discarded results?)
> 
> Alternatively, do we want to add a helper function to `ByteCodeExprGen` called `doEmitInc()` that hides the discarded result behavior so the `Visit*` functions don't have to keep doing that dance?
Yeah I think the ternary makes sense here, like it's done in the `Discard()` function in `VisitBinaryOperator()`.

For a function, I'll hold off for now, but it might make sense later (there's still a TODO comment for array initialization, which compiles to tons of code right now and we should use a loop there).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136423/new/

https://reviews.llvm.org/D136423



More information about the cfe-commits mailing list