]> granicus.if.org Git - clang/commitdiff
Revert "[analyzer] Quickfix: do not overflow in calculating offset in RegionManager"
authorGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 26 Feb 2018 21:32:57 +0000 (21:32 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 26 Feb 2018 21:32:57 +0000 (21:32 +0000)
This reverts commit df306c4c5ab4a6b8d3c47432346d1f9b90c328b4.

Reverting until I can figured out the reasons for failures.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326131 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/MemRegion.cpp
test/Analysis/region-store.cpp
test/Analysis/region_store_overflow.c [deleted file]

index 2f77524f68a5b1642e34b811326372258a041a93..aa54544fa7ddc092265ef0719eccbcf78171278d 100644 (file)
 #include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Debug.h"
-
-#include<functional>
-
-#define DEBUG_TYPE "MemRegion"
 
 using namespace clang;
 using namespace ento;
@@ -1154,36 +1149,6 @@ const SymbolicRegion *MemRegion::getSymbolicBase() const {
   return nullptr;
 }
 
-/// Perform a given operation on two integers, return whether it overflows.
-/// Optionally write the resulting output into \p Res.
-static bool checkedOp(
-    int64_t LHS,
-    int64_t RHS,
-    std::function<llvm::APInt(llvm::APInt *, const llvm::APInt &, bool &)> Op,
-    int64_t *Res = nullptr) {
-  llvm::APInt ALHS(/*BitSize=*/64, LHS, /*Signed=*/true);
-  llvm::APInt ARHS(/*BitSize=*/64, RHS, /*Signed=*/true);
-  bool Overflow;
-  llvm::APInt Out = Op(&ALHS, ARHS, Overflow);
-  if (!Overflow && Res)
-    *Res = Out.getSExtValue();
-  return Overflow;
-}
-
-static bool checkedAdd(
-    int64_t LHS,
-    int64_t RHS,
-    int64_t *Res=nullptr) {
-  return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov, Res);
-}
-
-static bool checkedMul(
-    int64_t LHS,
-    int64_t RHS,
-    int64_t *Res=nullptr) {
-  return checkedOp(LHS, RHS, &llvm::APInt::smul_ov, Res);
-}
-
 RegionRawOffset ElementRegion::getAsArrayOffset() const {
   CharUnits offset = CharUnits::Zero();
   const ElementRegion *ER = this;
@@ -1211,17 +1176,6 @@ RegionRawOffset ElementRegion::getAsArrayOffset() const {
         }
 
         CharUnits size = C.getTypeSizeInChars(elemType);
-
-        int64_t Mult;
-        bool Overflow = checkedAdd(i, size.getQuantity(), &Mult);
-        Overflow |= checkedMul(Mult, offset.getQuantity());
-        if (Overflow) {
-          DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
-                             << "offset overflowing, returning unknown\n");
-
-          return nullptr;
-        }
-
         offset += (i * size);
       }
 
index ab179ceb1acc89dc06df7f7d82b300a0ea56fcff..cb49f4837d813a3ba4fb210ea563d7d61ca6f0e4 100644 (file)
@@ -25,4 +25,4 @@ int radar13445834(Derived *Builder, Loc l) {
   Builder->setLoc(l);
   return Builder->accessBase();
   
-}
+}
\ No newline at end of file
diff --git a/test/Analysis/region_store_overflow.c b/test/Analysis/region_store_overflow.c
deleted file mode 100644 (file)
index 81acd41..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-// REQUIRES: asserts
-// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -mllvm -debug %s 2>&1 | FileCheck %s
-
-int **h;
-int overflow_in_memregion(long j) {
-  for (int l = 0;; ++l) {
-    if (j - l > 0)
-      return h[j - l][0]; // no-crash
-  }
-  return 0;
-}
-// CHECK: {{.*}}
-// CHECK: MemRegion::getAsArrayOffset: offset overflowing, returning unknown