[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 15:40:05 PDT 2024


================
@@ -316,10 +316,15 @@ class TrivialFunctionAnalysisVisitor
 
     if (UO->isIncrementOp() || UO->isDecrementOp()) {
       // Allow increment or decrement of a POD type.
-      if (auto *RefExpr = dyn_cast<DeclRefExpr>(UO->getSubExpr())) {
+      auto *SubExpr = UO->getSubExpr();
+      if (auto *RefExpr = dyn_cast<DeclRefExpr>(SubExpr)) {
----------------
haoNoQ wrote:

Hmm. You're jumping two steps at a time here: exploring `UnaryOperator` and the inner `DeclRefExrpr`/`MemberExpr` together simultaneously, as opposed to fully relying on the `Visit()` method which already has slightly different behavior.

For example, it looks like an access to a global variable is considered trivial _unless it's an increment_. In particular, `global += 1` is still considered trivial but `++global` isn't. (This has actually already been the case before your patch, you just added more similar behavior.)

Is this intended? Maybe it's better to check for these extra conditions by default?

https://github.com/llvm/llvm-project/pull/91102


More information about the cfe-commits mailing list