Kristof Umann | 7d6d9eb | 2018-10-31 14:54:27 +0000 | [diff] [blame^] | 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s |
| 2 | // |
| 3 | // RUN: %clang_analyze_cc1 -analyzer-checker=core %s \ |
| 4 | // RUN: -analyzer-output=plist -o %t.plist \ |
| 5 | // RUN: -analyzer-config expand-macros=true |
| 6 | // |
| 7 | // Check the actual plist output. |
| 8 | // RUN: cat %t.plist | %diff_plist \ |
| 9 | // RUN: %S/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist |
| 10 | // |
| 11 | // Check the macro expansions from the plist output here, to make the test more |
| 12 | // understandable. |
| 13 | // RUN: FileCheck --input-file=%t.plist %s |
| 14 | |
| 15 | void print(const void*); |
| 16 | |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | // Tests for non-function-like macro expansions. |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | |
| 21 | #define SET_PTR_VAR_TO_NULL \ |
| 22 | ptr = 0 |
| 23 | |
| 24 | void nonFunctionLikeMacroTest() { |
| 25 | int *ptr; |
| 26 | SET_PTR_VAR_TO_NULL; |
| 27 | *ptr = 5; // expected-warning{{Dereference of null pointer}} |
| 28 | } |
| 29 | |
| 30 | // CHECK: <key>name</key><string></string> |
| 31 | // CHECK-NEXT: <key>expansion</key><string></string> |
| 32 | |
| 33 | #define NULL 0 |
| 34 | #define SET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO \ |
| 35 | ptr = NULL |
| 36 | |
| 37 | void nonFunctionLikeNestedMacroTest() { |
| 38 | int *ptr; |
| 39 | SET_PTR_VAR_TO_NULL_WITH_NESTED_MACRO; |
| 40 | *ptr = 5; // expected-warning{{Dereference of null pointer}} |
| 41 | } |
| 42 | |
| 43 | // CHECK: <key>name</key><string></string> |
| 44 | // CHECK-NEXT: <key>expansion</key><string></string> |