Skip to content

Commit 082e45a

Browse files
committed
dump more test details & simplify logic test expr
1 parent 19b47c6 commit 082e45a

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ProgramStateRef RangedConstraintManager::assumeSym(ProgramStateRef State,
2525
bool Assumption) {
2626
SVal SimplifiedVal = simplifyToSVal(State, Sym);
2727
if (SimplifiedVal.isConstant()) {
28-
bool Feasible = SimplifiedVal.isZeroConstant() ? !Assumption : Assumption;
28+
bool Feasible = SimplifiedVal.isZeroConstant() != Assumption;
2929
return Feasible ? State : nullptr;
3030
}
3131

clang/test/Analysis/solver-sym-simplification-on-assumption.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@
33
// RUN: -verify
44

55
void clang_analyzer_eval(int);
6+
void clang_analyzer_value(int);
67

78
void test_derived_sym_simplification_on_assume(int s0, int s1) {
89
int elem = s0 + s1 + 1;
9-
if (elem-- == 0) // elem = s0 + s1
10+
if (elem-- == 0)
1011
return;
1112

12-
if (elem-- == 0) // elem = s0 + s1 - 1
13+
if (elem-- == 0)
1314
return;
1415

15-
if (s0 < 1) // s0: [1, 2147483647]
16+
if (s0 < 1)
1617
return;
17-
if (s1 < 1) // s0: [1, 2147483647]
18+
clang_analyzer_value(s0); // expected-warning{{[1, 2147483647]}}
19+
20+
if (s1 < 1)
1821
return;
22+
clang_analyzer_value(s1); // expected-warning{{[1, 2147483647]}}
1923

20-
if (elem-- == 0) // elem = s0 + s1 - 2
24+
if (elem-- == 0)
2125
return;
2226

23-
if (s0 > 1) // s0: [-2147483648, 0] U [1, 2147483647] => s0 = 0
27+
if (s0 > 1)
2428
return;
29+
clang_analyzer_value(s0); // expected-warning{{1}}
2530

26-
if (s1 > 1) // s1: [-2147483648, 0] U [1, 2147483647] => s1 = 0
31+
if (s1 > 1)
2732
return;
33+
clang_analyzer_value(s1); // expected-warning{{1}}
2834

29-
// elem = s0 + s1 - 2 should be 0
3035
clang_analyzer_eval(elem); // expected-warning{{FALSE}}
3136
}

clang/test/Analysis/std-c-library-functions-bufsize-nocrash-with-correct-solver.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// RUN: %clang_analyze_cc1 %s \
2+
// RUN: -analyzer-max-loop 6 \
23
// RUN: -analyzer-checker=unix.StdCLibraryFunctions \
34
// RUN: -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true \
45
// RUN: -analyzer-checker=debug.ExprInspection \
56
// RUN: -triple x86_64-unknown-linux-gnu \
67
// RUN: -verify
78

8-
// expected-no-diagnostics
9-
109
#include "Inputs/std-c-library-functions-POSIX.h"
1110

11+
void clang_analyzer_value(int);
12+
void clang_analyzer_warnIfReached();
13+
void clang_analyzer_printState();
14+
1215
void _add_one_to_index_C(int *indices, int *shape) {
1316
int k = 1;
1417
for (; k >= 0; k--)
@@ -26,8 +29,15 @@ void PyObject_CopyData_sptr(char *i, char *j, int *indices, int itemsize,
2629

2730
// no contradiction after 3 iterations when 'elements' could be
2831
// simplified to 0
32+
int iterations = 0;
2933
while (elements--) {
34+
iterations++;
3035
_add_one_to_index_C(indices, shape);
31-
getnameinfo(sa, 10, i, itemsize, i, itemsize, 0);
36+
getnameinfo(sa, 10, i, itemsize, i, itemsize, 0); // no crash here
37+
}
38+
39+
if (shape[0] == 1 && shape[1] == 1 && indices[0] == 0 && indices[1] == 0) {
40+
clang_analyzer_value(iterations == 3 && elements == -1);
41+
// expected-warning@-1{{1}}
3242
}
3343
}

0 commit comments

Comments
 (0)