|
1 | | -// RUN: %clang_analyze_cc1 -std=c++23 -analyzer-checker=core,debug.ExprInspection -verify %s |
| 1 | +// RUN: %clang_analyze_cc1 -std=c++23 -triple x86_64-pc-linux-gnu \ |
| 2 | +// RUN: -analyzer-checker=core,debug.ExprInspection -verify %s |
2 | 3 |
|
3 | 4 | template <typename T> void clang_analyzer_dump(T); |
4 | 5 | template <typename T> void clang_analyzer_value(T); |
5 | 6 |
|
6 | 7 | int ternary_in_builtin_assume(int a, int b) { |
7 | | - |
8 | 8 | __builtin_assume(a > 10 ? b == 4 : b == 10); |
9 | 9 |
|
10 | | - clang_analyzer_value(a); // we should have 2 dumps here. expected-warning{{[-2147483648, 10]}} expected-warning{{[11, 2147483647]}} |
11 | | - clang_analyzer_dump(b); // This should be either 4 or 10. expected-warning{{4}} expected-warning{{10}} |
| 10 | + clang_analyzer_value(a); |
| 11 | + // expected-warning@-1 {{[-2147483648, 10]}} |
| 12 | + // expected-warning@-2 {{[11, 2147483647]}} |
| 13 | + |
| 14 | + clang_analyzer_dump(b); // expected-warning{{4}} expected-warning{{10}} |
| 15 | + |
12 | 16 | if (a > 20) { |
13 | | - clang_analyzer_dump(b + 100); // expecting 104 expected-warning{{104}} |
| 17 | + clang_analyzer_dump(b + 100); // expected-warning {{104}} |
14 | 18 | return 2; |
15 | 19 | } |
16 | 20 | if (a > 10) { |
17 | | - clang_analyzer_dump(b + 200); // expecting 204 expected-warning{{204}} |
| 21 | + clang_analyzer_dump(b + 200); // expected-warning {{204}} |
18 | 22 | return 1; |
19 | 23 | } |
20 | | - clang_analyzer_dump(b + 300); // expecting 310 expected-warning{{310}} |
| 24 | + clang_analyzer_dump(b + 300); // expected-warning {{310}} |
21 | 25 | return 0; |
22 | 26 | } |
23 | 27 |
|
24 | 28 | // From: https://github.com/llvm/llvm-project/pull/116462#issuecomment-2517853226 |
25 | 29 | int ternary_in_assume(int a, int b) { |
26 | 30 | // FIXME notes |
27 | 31 | // Currently, if this test is run without the core.builtin.Builtin checker, the above function with the __builtin_assume behaves identically to the following test |
28 | | - // i.e. calls to `clang_analyzer_dump` result in "extraneous" prints of the SVal(s) `reg_$2<int > b ...` |
| 32 | + // i.e. calls to `clang_analyzer_dump` result in "extraneous" prints of the SVal(s) `reg<int b> ...` |
29 | 33 | // as opposed to 4 or 10 |
30 | 34 | // which likely implies the Program State(s) did not get narrowed. |
31 | 35 | // A new checker is likely needed to be implemented to properly handle the expressions within `[[assume]]` to eliminate the states where `b` is not narrowed. |
32 | 36 |
|
33 | 37 | [[assume(a > 10 ? b == 4 : b == 10)]]; |
34 | | - clang_analyzer_value(a); // we should have 2 dumps here. expected-warning{{[-2147483648, 10]}} expected-warning{{[11, 2147483647]}} |
35 | | - clang_analyzer_dump(b); // This should be either 4 or 10. expected-warning{{4}} expected-warning{{10}} FIXME: expected-warning{{reg_$2<int b>}} |
| 38 | + clang_analyzer_value(a); |
| 39 | + // expected-warning@-1 {{[-2147483648, 10]}} |
| 40 | + // expected-warning@-2 {{[11, 2147483647]}} |
| 41 | + |
| 42 | + clang_analyzer_dump(b); // expected-warning {{4}} expected-warning {{10}} |
| 43 | + // expected-warning-re@-1 {{reg_${{[0-9]+}}<int b>}} FIXME: We shouldn't have this dump. |
| 44 | + |
36 | 45 | if (a > 20) { |
37 | | - clang_analyzer_dump(b + 100); // expecting 104 expected-warning{{104}} FIXME: expected-warning{{(reg_$2<int b>) + 100}} |
| 46 | + clang_analyzer_dump(b + 100); // expected-warning {{104}} |
| 47 | + // expected-warning-re@-1 {{(reg_${{[0-9]+}}<int b>) + 100}} FIXME: We shouldn't have this dump. |
38 | 48 | return 2; |
39 | 49 | } |
40 | 50 | if (a > 10) { |
41 | | - clang_analyzer_dump(b + 200); // expecting 204 expected-warning{{204}} FIXME: expected-warning{{(reg_$2<int b>) + 200}} |
| 51 | + clang_analyzer_dump(b + 200); // expected-warning {{204}} |
| 52 | + // expected-warning-re@-1 {{(reg_${{[0-9]+}}<int b>) + 200}} FIXME: We shouldn't have this dump. |
42 | 53 | return 1; |
43 | 54 | } |
44 | | - clang_analyzer_dump(b + 300); // expecting 310 expected-warning{{310}} FIXME: expected-warning{{(reg_$2<int b>) + 300}} |
| 55 | + clang_analyzer_dump(b + 300); // expected-warning {{310}} |
| 56 | + // expected-warning-re@-1 {{(reg_${{[0-9]+}}<int b>) + 300}} FIXME: We shouldn't have this dump. |
45 | 57 | return 0; |
46 | 58 | } |
0 commit comments