[PATCH] D115932: [Analyzer] Create and handle SymbolCast for pointer to integral conversion

Denys Petrov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 10 04:46:44 PST 2022


ASDenysPetrov added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:415-423
+  // FIXME This should be done in getAsSymbol. But then getAsSymbol should be
+  // the member function of SValBuilder (?)
+  if (symRHS)
+    if (auto RLocAsInt = RHS.getAs<nonloc::LocAsInteger>()) {
+      auto FromTy = symRHS->getType();
+      auto ToTy = RLocAsInt->getType(this->Context);
+      symRHS = this->getSymbolManager().getCastSymbol(symRHS, FromTy, ToTy);
----------------
IMO this is not the right place for producing `SymbolCast` because we can meet `(type)x`-like semantics in a different contexts and expressions.


================
Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:419-420
+    if (auto RLocAsInt = RHS.getAs<nonloc::LocAsInteger>()) {
+      auto FromTy = symRHS->getType();
+      auto ToTy = RLocAsInt->getType(this->Context);
+      symRHS = this->getSymbolManager().getCastSymbol(symRHS, FromTy, ToTy);
----------------
According to https://llvm.org/docs/CodingStandards.html#id28


================
Comment at: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:471-478
+  if (Optional<Loc> RV = rhs.getAs<Loc>()) {
+    // Support pointer arithmetic where the addend is on the left
+    // and the pointer on the right.
 
-    if (IsCommutative(op)) {
-      // Swap operands.
-      return evalBinOpLN(state, op, *RV, lhs.castAs<NonLoc>(), type);
-    }
+    assert(op == BO_Add);
 
+    // Commute the operands.
----------------
This can be carried out to the separate revert revision as it is not related to this one directly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115932



More information about the cfe-commits mailing list