Skip to content

Commit 26f02f3

Browse files
committed
Revert "Use the eager assumption tags only if the decision was ambiguous"
This reverts commit c429df6.
1 parent 6e6ed6f commit 26f02f3

File tree

5 files changed

+40
-29
lines changed

5 files changed

+40
-29
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,29 +3771,24 @@ void ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst,
37713771
SVal V = state->getSVal(Ex, Pred->getLocationContext());
37723772
std::optional<nonloc::SymbolVal> SEV = V.getAs<nonloc::SymbolVal>();
37733773
if (SEV && SEV->isExpression()) {
3774+
const std::pair<const ProgramPointTag *, const ProgramPointTag*> &tags =
3775+
geteagerlyAssumeBinOpBifurcationTags();
3776+
37743777
ProgramStateRef StateTrue, StateFalse;
37753778
std::tie(StateTrue, StateFalse) = state->assume(*SEV);
37763779

3777-
const ProgramPointTag *EagerTrueTag = nullptr;
3778-
const ProgramPointTag *EagerFalseTag = nullptr;
3779-
3780-
// Use the eager assumption tags if the choice was ambiguous.
3781-
if (StateTrue && StateFalse)
3782-
std::tie(EagerTrueTag, EagerFalseTag) =
3783-
geteagerlyAssumeBinOpBifurcationTags();
3784-
37853780
// First assume that the condition is true.
37863781
if (StateTrue) {
37873782
SVal Val = svalBuilder.makeIntVal(1U, Ex->getType());
37883783
StateTrue = StateTrue->BindExpr(Ex, Pred->getLocationContext(), Val);
3789-
Bldr.generateNode(Ex, Pred, StateTrue, EagerTrueTag);
3784+
Bldr.generateNode(Ex, Pred, StateTrue, tags.first);
37903785
}
37913786

37923787
// Next, assume that the condition is false.
37933788
if (StateFalse) {
37943789
SVal Val = svalBuilder.makeIntVal(0U, Ex->getType());
37953790
StateFalse = StateFalse->BindExpr(Ex, Pred->getLocationContext(), Val);
3796-
Bldr.generateNode(Ex, Pred, StateFalse, EagerFalseTag);
3791+
Bldr.generateNode(Ex, Pred, StateFalse, tags.second);
37973792
}
37983793
}
37993794
}

clang/test/Analysis/assuming-unsigned-ge-0.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// RUN: -analyzer-checker=core -verify %s
33

44
int assuming_unsigned_ge_0(unsigned arg) {
5-
// expected-note@+2 {{'arg' is >= 0}}
5+
// TODO This testcase demonstrates the current incorrect behavior of Clang
6+
// Static Analyzer: here 'arg' is unsigned, so "arg >= 0" is not a fresh
7+
// assumption, but it still appears in the diagnostics as if it's fresh:
8+
// expected-note@+2 {{Assuming 'arg' is >= 0}}
69
// expected-note@+1 {{Taking false branch}}
710
if (arg < 0)
811
return 0;

clang/test/Analysis/cast-value-notes.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ void evalNonNullParamNonNullReturnReference(const Shape &S) {
168168
// expected-note@-2 {{Taking true branch}}
169169

170170
(void)(1 / !C);
171-
// expected-note@-1 {{Division by zero}}
172-
// expected-warning@-2 {{Division by zero}}
171+
// expected-note@-1 {{'C' is non-null}}
172+
// expected-note@-2 {{Division by zero}}
173+
// expected-warning@-3 {{Division by zero}}
173174
}
174175
}
175176

@@ -225,8 +226,9 @@ void evalNonNullParamNonNullReturn(const Shape *S) {
225226
// expected-note@-2 {{Taking true branch}}
226227

227228
(void)(1 / !C);
228-
// expected-note@-1 {{Division by zero}}
229-
// expected-warning@-2 {{Division by zero}}
229+
// expected-note@-1 {{'C' is non-null}}
230+
// expected-note@-2 {{Division by zero}}
231+
// expected-warning@-3 {{Division by zero}}
230232
}
231233
}
232234

@@ -241,8 +243,9 @@ void evalNonNullParamNullReturn(const Shape *S) {
241243
// expected-note@-4 {{Taking true branch}}
242244

243245
(void)(1 / !T);
244-
// expected-note@-1 {{Division by zero}}
245-
// expected-warning@-2 {{Division by zero}}
246+
// expected-note@-1 {{'T' is non-null}}
247+
// expected-note@-2 {{Division by zero}}
248+
// expected-warning@-3 {{Division by zero}}
246249
}
247250
}
248251

@@ -262,8 +265,9 @@ void evalZeroParamNonNullReturnPointer(const Shape *S) {
262265
// expected-note@-2 {{'C' initialized here}}
263266

264267
(void)(1 / !C);
265-
// expected-note@-1 {{Division by zero}}
266-
// expected-warning@-2 {{Division by zero}}
268+
// expected-note@-1 {{'C' is non-null}}
269+
// expected-note@-2 {{Division by zero}}
270+
// expected-warning@-3 {{Division by zero}}
267271
}
268272

269273
void evalZeroParamNonNullReturn(const Shape &S) {

clang/test/Analysis/cast-value-state-dump.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ void evalNonNullParamNonNullReturn(const Shape *S) {
4040
// CHECK-NEXT: ] }
4141

4242
(void)(1 / !C);
43-
// expected-note@-1 {{Division by zero}}
44-
// expected-warning@-2 {{Division by zero}}
43+
// expected-note@-1 {{'C' is non-null}}
44+
// expected-note@-2 {{Division by zero}}
45+
// expected-warning@-3 {{Division by zero}}
4546
}
4647

clang/test/Analysis/std-c-library-functions-arg-constraints.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void test_alnum_symbolic(int x) {
4242
// report-warning{{TRUE}} \
4343
// bugpath-warning{{TRUE}} \
4444
// bugpath-note{{TRUE}} \
45-
// bugpath-note{{Left side of '&&' is true}}
45+
// bugpath-note{{Left side of '&&' is true}} \
46+
// bugpath-note{{'x' is <= 255}}
4647
}
4748

4849
void test_alnum_symbolic2(int x) {
@@ -75,7 +76,8 @@ void test_toupper_symbolic(int x) {
7576
// report-warning{{TRUE}} \
7677
// bugpath-warning{{TRUE}} \
7778
// bugpath-note{{TRUE}} \
78-
// bugpath-note{{Left side of '&&' is true}}
79+
// bugpath-note{{Left side of '&&' is true}} \
80+
// bugpath-note{{'x' is <= 255}}
7981
}
8082

8183
void test_toupper_symbolic2(int x) {
@@ -108,7 +110,8 @@ void test_tolower_symbolic(int x) {
108110
// report-warning{{TRUE}} \
109111
// bugpath-warning{{TRUE}} \
110112
// bugpath-note{{TRUE}} \
111-
// bugpath-note{{Left side of '&&' is true}}
113+
// bugpath-note{{Left side of '&&' is true}} \
114+
// bugpath-note{{'x' is <= 255}}
112115
}
113116

114117
void test_tolower_symbolic2(int x) {
@@ -141,7 +144,8 @@ void test_toascii_symbolic(int x) {
141144
// report-warning{{TRUE}} \
142145
// bugpath-warning{{TRUE}} \
143146
// bugpath-note{{TRUE}} \
144-
// bugpath-note{{Left side of '&&' is true}}
147+
// bugpath-note{{Left side of '&&' is true}} \
148+
// bugpath-note{{'x' is <= 255}}
145149
}
146150

147151
void test_toascii_symbolic2(int x) {
@@ -169,7 +173,8 @@ void test_notnull_symbolic(FILE *fp, int *buf) {
169173
clang_analyzer_eval(buf != 0); // \
170174
// report-warning{{TRUE}} \
171175
// bugpath-warning{{TRUE}} \
172-
// bugpath-note{{TRUE}}
176+
// bugpath-note{{TRUE}} \
177+
// bugpath-note{{'buf' is not equal to null}}
173178
}
174179
void test_notnull_symbolic2(FILE *fp, int *buf) {
175180
if (!buf) // bugpath-note{{Assuming 'buf' is null}} \
@@ -213,7 +218,8 @@ void test_notnull_buffer_3(void *buf) {
213218
clang_analyzer_eval(buf != 0); // \
214219
// report-warning{{TRUE}} \
215220
// bugpath-warning{{TRUE}} \
216-
// bugpath-note{{TRUE}}
221+
// bugpath-note{{TRUE}} \
222+
// bugpath-note{{'buf' is not equal to null}}
217223
}
218224

219225
void test_no_node_after_bug(FILE *fp, size_t size, size_t n, void *buf) {
@@ -293,15 +299,17 @@ void test_buf_size_symbolic(int s) {
293299
clang_analyzer_eval(s <= 3); // \
294300
// report-warning{{TRUE}} \
295301
// bugpath-warning{{TRUE}} \
296-
// bugpath-note{{TRUE}}
302+
// bugpath-note{{TRUE}} \
303+
// bugpath-note{{'s' is <= 3}}
297304
}
298305
void test_buf_size_symbolic_and_offset(int s) {
299306
char buf[3];
300307
__buf_size_arg_constraint(buf + 1, s);
301308
clang_analyzer_eval(s <= 2); // \
302309
// report-warning{{TRUE}} \
303310
// bugpath-warning{{TRUE}} \
304-
// bugpath-note{{TRUE}}
311+
// bugpath-note{{TRUE}} \
312+
// bugpath-note{{'s' is <= 2}}
305313
}
306314

307315
int __buf_size_arg_constraint_mul(const void *, size_t, size_t);

0 commit comments

Comments
 (0)