| 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s |
| 2 | // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file %s -o %t.plist |
| 3 | // RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/undef-value-param.c.plist - |
| 4 | |
| 5 | void foo_irrelevant(int c) { |
| 6 | if (c) |
| 7 | return; |
| 8 | c++; |
| 9 | return; |
| 10 | } |
| 11 | void foo(int c, int *x) { |
| 12 | if (c) |
| 13 | //expected-note@-1{{Assuming 'c' is not equal to 0}} |
| 14 | //expected-note@-2{{Taking true branch}} |
| 15 | return; // expected-note{{Returning without writing to '*x'}} |
| 16 | *x = 5; |
| 17 | } |
| 18 | |
| 19 | int use(int c) { |
| 20 | int xx; //expected-note {{'xx' declared without an initial value}} |
| 21 | int *y = &xx; |
| 22 | foo (c, y); |
| 23 | //expected-note@-1{{Calling 'foo'}} |
| 24 | //expected-note@-2{{Returning from 'foo'}} |
| 25 | foo_irrelevant(c); |
| 26 | return xx+3; //expected-warning{{The left operand of '+' is a garbage value}} |
| 27 | //expected-note@-1{{The left operand of '+' is a garbage value}} |
| 28 | } |
| 29 | |
| 30 | void initArray(int x, double XYZ[3]) { |
| 31 | if (x <= 0) //expected-note {{Taking true branch}} |
| 32 | //expected-note@-1 {{Assuming 'x' is <= 0}} |
| 33 | return; |
| 34 | XYZ[0] = 1; |
| 35 | XYZ[1] = 1; |
| 36 | XYZ[2] = 1; |
| 37 | } |
| 38 | int testPassingParentRegionArray(int x) { |
| 39 | double XYZ[3]; |
| 40 | initArray(x, XYZ); //expected-note {{Calling 'initArray'}} |
| 41 | //expected-note@-1 {{Returning from 'initArray'}} |
| 42 | return 1 * XYZ[1]; //expected-warning {{The right operand of '*' is a garbage value}} |
| 43 | //expected-note@-1 {{The right operand of '*' is a garbage value}} |
| 44 | } |
| 45 | |
| 46 | double *getValidPtr(); |
| 47 | struct WithFields { |
| 48 | double *f1; |
| 49 | }; |
| 50 | void initStruct(int x, struct WithFields *X) { |
| 51 | if (x <= 0) //expected-note {{Taking true branch}} |
| 52 | //expected-note@-1 {{Assuming 'x' is <= 0}} |
| 53 | |
| 54 | return; //expected-note{{Returning without writing to 'X->f1'}} |
| 55 | X->f1 = getValidPtr(); |
| 56 | } |
| 57 | double testPassingParentRegionStruct(int x) { |
| 58 | struct WithFields st; |
| 59 | st.f1 = 0; // expected-note {{Null pointer value stored to 'st.f1'}} |
| 60 | initStruct(x, &st); //expected-note {{Calling 'initStruct'}} |
| 61 | //expected-note@-1 {{Returning from 'initStruct'}} |
| 62 | return (*st.f1); //expected-warning {{Dereference of null pointer}} |
| 63 | //expected-note@-1{{Dereference of null pointer (loaded from field 'f1')}} |
| 64 | } |
| 65 | |
| 66 | |