[PATCH] D125318: [analyzer] Add UnarySymExpr

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 13 03:40:38 PDT 2022


steakhal added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:107
+    return makeNonLoc(X.castAs<nonloc::SymbolVal>().getSymbol(), UO_Not,
+                      X.getType(Context));
   default:
----------------
martong wrote:
> steakhal wrote:
> > I'm not sure if we should rely on `SVal::getType()`. I think the calling context should pass the type along here.
> Good point. One example where the type of the SVal is different than the type of the UnaryExpr is here:
> ```
> void test_x(int x, long y) {
>   x = y;  // $x has `long` type
>   -x;     // the UnaryExpr `-x` has `int` type
> }
> ```
> Note that if we use `support-symbolic-integer-casts=true` then there is no such type mismatch because there is in implicit cast modeled at `x = y`, thus $x type is correctly `int`.
> 
> Anyway, I am going to update evalMinus and evalComplement to take an additional QualType parameter.
Please add this test with both scenarios with `support-symbolic-integer-casts`. D125532 will help in demonstrating this.


================
Comment at: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp:73-76
+void UnarySymExpr::dumpToStream(raw_ostream &os) const {
+  os << UnaryOperator::getOpcodeStr(Op);
+  Operand->dumpToStream(os);
+}
----------------
martong wrote:
> Would be better to add parenthesis around for compound expressions. So expressions like -x where x = a + b should look like `-($a + $b)` instead of the wrong format `-$a + $b`. I am going to update.
Good point!


================
Comment at: clang/test/Analysis/unary-sym-expr.c:35
+    return;
+  clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
+}
----------------
Does it work if you swap x and y?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125318



More information about the cfe-commits mailing list