Skip to content

Commit

Permalink
[analyzer] Fixit for r158136.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AnnaZaks committed Jun 7, 2012
1 parent ec22f56 commit 783f008
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions test/Analysis/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 783f008

Please sign in to comment.