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<nonloc::ConcreteInt>().evalMinus(*this);
-  default:
-    return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalMinus(NonLoc V) {
+  if (auto C = V.getAs<nonloc::ConcreteInt>())
+    return makeIntVal(-C->getValue());
+  return UnknownVal();
 }
 
-SVal SimpleSValBuilder::evalComplement(NonLoc X) {
-  switch (X.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-    return X.castAs<nonloc::ConcreteInt>().evalComplement(*this);
-  default:
-    return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalComplement(NonLoc V) {
+  if (auto C = V.getAs<nonloc::ConcreteInt>())
+    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 &svalBuilder) const {
-  return svalBuilder.makeIntVal(~getValue());
-}
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalMinus(SValBuilder &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 &svalBuilder, BinaryOperator::Opcode Op,
                  const ConcreteInt& R) const;
 
-  ConcreteInt evalComplement(SValBuilder &svalBuilder) const;
-
-  ConcreteInt evalMinus(SValBuilder &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<nonloc::ConcreteInt>().evalMinus(*this);
-  default:
-    return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalMinus(NonLoc V) {
+  if (auto C = V.getAs<nonloc::ConcreteInt>())
+    return makeIntVal(-C->getValue());
+  return UnknownVal();
 }
 
-SVal SimpleSValBuilder::evalComplement(NonLoc X) {
-  switch (X.getSubKind()) {
-  case nonloc::ConcreteIntKind:
-    return X.castAs<nonloc::ConcreteInt>().evalComplement(*this);
-  default:
-    return UnknownVal();
-  }
+SVal SimpleSValBuilder::evalComplement(NonLoc V) {
+  if (auto C = V.getAs<nonloc::ConcreteInt>())
+    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 &svalBuilder) const {
-  return svalBuilder.makeIntVal(~getValue());
-}
-
-nonloc::ConcreteInt
-nonloc::ConcreteInt::evalMinus(SValBuilder &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 &svalBuilder, BinaryOperator::Opcode Op,
                  const ConcreteInt& R) const;
 
-  ConcreteInt evalComplement(SValBuilder &svalBuilder) const;
-
-  ConcreteInt evalMinus(SValBuilder &svalBuilder) const;
-
 private:
   friend class SVal;
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to