[PATCH] D126126: [analyzer][NFC] Inline and simplify nonloc::ConcreteInt functions

2022-05-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal abandoned this revision.
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:90
-SVal SimpleSValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
-  case nonloc::ConcreteIntKind:

martong wrote:
> I'd rather keep the `switch` because in D125318 we are going to extend with 
> `nonloc::SymbolValKind` so, soon it will no longer be  a standalone case.
Okay, let's postpone this until things get settled with the unary ops stuff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126126

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126126: [analyzer][NFC] Inline and simplify nonloc::ConcreteInt functions

2022-05-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:90
-SVal SimpleSValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
-  case nonloc::ConcreteIntKind:

I'd rather keep the `switch` because in D125318 we are going to extend with 
`nonloc::SymbolValKind` so, soon it will no longer be  a standalone case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126126

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126126: [analyzer][NFC] Inline and simplify nonloc::ConcreteInt functions

2022-05-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: martong, NoQ.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126126

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp


Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -86,22 +86,16 @@
 // Transfer function for unary operators.
 
//===--===//
 
-SVal SimpleSValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-return val.castAs().evalMinus(*this);
-  default:
-return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalMinus(NonLoc V) {
+  if (auto C = V.getAs())
+return makeIntVal(-C->getValue());
+  return UnknownVal();
 }
 
-SVal SimpleSValBuilder::evalComplement(NonLoc X) {
-  switch (X.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-return X.castAs().evalComplement(*this);
-  default:
-return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalComplement(NonLoc V) {
+  if (auto C = V.getAs())
+return makeIntVal(~C->getValue());
+  return UnknownVal();
 }
 
 // Checks if the negation the value and flipping sign preserve
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -288,16 +288,6 @@
 return UndefinedVal();
 }
 
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalComplement(SValBuilder ) const {
-  return svalBuilder.makeIntVal(~getValue());
-}
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalMinus(SValBuilder ) const {
-  return svalBuilder.makeIntVal(-getValue());
-}
-
 
//===--===//
 // Transfer function dispatch for Locs.
 
//===--===//
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -394,10 +394,6 @@
   SVal evalBinOp(SValBuilder , BinaryOperator::Opcode Op,
  const ConcreteInt& R) const;
 
-  ConcreteInt evalComplement(SValBuilder ) const;
-
-  ConcreteInt evalMinus(SValBuilder ) const;
-
 private:
   friend class SVal;
 


Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -86,22 +86,16 @@
 // Transfer function for unary operators.
 //===--===//
 
-SVal SimpleSValBuilder::evalMinus(NonLoc val) {
-  switch (val.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-return val.castAs().evalMinus(*this);
-  default:
-return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalMinus(NonLoc V) {
+  if (auto C = V.getAs())
+return makeIntVal(-C->getValue());
+  return UnknownVal();
 }
 
-SVal SimpleSValBuilder::evalComplement(NonLoc X) {
-  switch (X.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-return X.castAs().evalComplement(*this);
-  default:
-return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalComplement(NonLoc V) {
+  if (auto C = V.getAs())
+return makeIntVal(~C->getValue());
+  return UnknownVal();
 }
 
 // Checks if the negation the value and flipping sign preserve
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -288,16 +288,6 @@
 return UndefinedVal();
 }
 
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalComplement(SValBuilder ) const {
-  return svalBuilder.makeIntVal(~getValue());
-}
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalMinus(SValBuilder ) const {
-  return svalBuilder.makeIntVal(-getValue());
-}
-
 //===--===//
 // Transfer function dispatch for Locs.
 //===--===//
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h