]> granicus.if.org Git - clang/commitdiff
[analyzer] Fixit for r158136.
authorAnna Zaks <ganna@apple.com>
Thu, 7 Jun 2012 20:18:08 +0000 (20:18 +0000)
committerAnna Zaks <ganna@apple.com>
Thu, 7 Jun 2012 20:18:08 +0000 (20:18 +0000)
I falsely assumed that the memory spaces are equal when we reach this
point, they might not be when memory space of one or more is stack or
Unknown. We don't want a region from Heap space alias something with
another memory space.

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

lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
test/Analysis/malloc.c

index 9cbbece98e73d27b8aa9c58de02cbf1a0c16ea43..ad58a07c784ed0bae83960351cc5ca884a9ae277 100644 (file)
@@ -701,7 +701,7 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
     // on each invocation.
     if (LeftBase != RightBase &&
         ((!isa<SymbolicRegion>(LeftBase) && !isa<SymbolicRegion>(RightBase)) ||
-         isa<HeapSpaceRegion>(LeftMS)) ){
+         (isa<HeapSpaceRegion>(LeftMS) || isa<HeapSpaceRegion>(RightMS))) ){
       switch (op) {
       default:
         return UnknownVal();
index bdbd96e2be4e4b15474fa9d060ac20c3aebfb6d0..7be29301fe6f7f99f20bd27fe018fa32a531721b 100644 (file)
@@ -902,6 +902,23 @@ int HeapAssignment() {
   return 0;
 }
 
+int *retPtr();
+int *retPtrMightAlias(int *x);
+int cmpHeapAllocationToUnknown() {
+  int zero = 0;
+  int *yBefore = retPtr();
+  int *m = malloc(8);
+  int *yAfter = retPtrMightAlias(m);
+  if (yBefore == m) {
+    return 5/zero; // expected-warning {{This statement is never executed}}
+  }
+  if (yAfter == m) {
+    return 5/zero; // expected-warning {{This statement is never executed}}
+  }
+  free(m);
+  return 0;
+}
+
 // ----------------------------------------------------------------------------
 // False negatives.