Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,debug.ExprInspection -analyzer-store=region -analyzer-constraints=basic -verify %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,debug.ExprInspection -analyzer-store=region -analyzer-constraints=range -verify %s |
| 3 | |
| 4 | void clang_analyzer_eval(int); |
Jordy Rose | 23b736e | 2010-07-29 07:11:59 +0000 | [diff] [blame] | 5 | |
| 6 | int string_literal_init() { |
| 7 | char a[] = "abc"; |
| 8 | char b[2] = "abc"; // expected-warning{{too long}} |
| 9 | char c[5] = "abc"; |
| 10 | |
Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 11 | clang_analyzer_eval(a[1] == 'b'); // expected-warning{{TRUE}} |
| 12 | clang_analyzer_eval(b[1] == 'b'); // expected-warning{{TRUE}} |
| 13 | clang_analyzer_eval(c[1] == 'b'); // expected-warning{{TRUE}} |
Jordy Rose | 23b736e | 2010-07-29 07:11:59 +0000 | [diff] [blame] | 14 | |
Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 15 | clang_analyzer_eval(a[3] == 0); // expected-warning{{TRUE}} |
| 16 | clang_analyzer_eval(c[3] == 0); // expected-warning{{TRUE}} |
Jordy Rose | 23b736e | 2010-07-29 07:11:59 +0000 | [diff] [blame] | 17 | |
Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 18 | clang_analyzer_eval(c[4] == 0); // expected-warning{{TRUE}} |
Jordy Rose | 23b736e | 2010-07-29 07:11:59 +0000 | [diff] [blame] | 19 | |
| 20 | return 42; |
| 21 | } |
Jordy Rose | 59b6dca | 2010-08-20 01:05:59 +0000 | [diff] [blame] | 22 | |
| 23 | void nested_compound_literals(int rad) { |
David Blaikie | be0ee87 | 2012-05-15 16:56:36 +0000 | [diff] [blame] | 24 | int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, // expected-warning 6 {{implicit conversion from 'double' to 'int' changes value from}} |
| 25 | {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; // expected-warning 6 {{implicit conversion from 'double' to 'int' changes value from}} |
Jordy Rose | 59b6dca | 2010-08-20 01:05:59 +0000 | [diff] [blame] | 26 | int a; |
| 27 | |
| 28 | for (a = 0; a < 6; ++a) { |
| 29 | vec[a][0] *= rad; // no-warning |
| 30 | vec[a][1] *= rad; // no-warning |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | void nested_compound_literals_float(float rad) { |
| 35 | float vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, |
| 36 | {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; |
| 37 | int a; |
| 38 | |
| 39 | for (a = 0; a < 6; ++a) { |
| 40 | vec[a][0] *= rad; // no-warning |
| 41 | vec[a][1] *= rad; // no-warning |
| 42 | } |
| 43 | } |
Jordy Rose | f113940 | 2012-05-12 17:32:59 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | void struct_as_array() { |
Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 47 | struct simple { int x; int y; }; |
Jordy Rose | f113940 | 2012-05-12 17:32:59 +0000 | [diff] [blame] | 48 | struct simple a; |
| 49 | struct simple *p = &a; |
Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 50 | |
Jordy Rose | f113940 | 2012-05-12 17:32:59 +0000 | [diff] [blame] | 51 | p->x = 5; |
Jordy Rose | 43d9f0d | 2012-05-16 16:01:10 +0000 | [diff] [blame^] | 52 | clang_analyzer_eval(a.x == 5); // expected-warning{{TRUE}} |
| 53 | clang_analyzer_eval(p[0].x == 5); // expected-warning{{TRUE}} |
| 54 | |
| 55 | p[0].y = 5; |
| 56 | clang_analyzer_eval(a.y == 5); // expected-warning{{TRUE}} |
| 57 | clang_analyzer_eval(p->y == 5); // expected-warning{{TRUE}} |
Jordy Rose | f113940 | 2012-05-12 17:32:59 +0000 | [diff] [blame] | 58 | } |
| 59 | |