Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / plist-macros.cpp
blob94f8e514c8b39a2d382def0c83090f4147b4fb08
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-output=plist-multi-file %s -o %t.plist
3 // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/plist-macros.cpp.plist -
6 typedef __typeof(sizeof(int)) size_t;
7 void *malloc(size_t);
9 #define mallocmemory int *x = (int*)malloc(12);
10 void noteOnMacro(int y) {
11 y++;
12 y--;
13 mallocmemory
14 y++;
15 y++;
16 delete x; // expected-warning {{Memory allocated by malloc() should be deallocated by free(), not 'delete'}}
19 void macroIsFirstInFunction(int y) {
20 mallocmemory
21 y++; // expected-warning {{Potential leak of memory pointed to by 'x'}}
24 #define checkmacro p==0
25 void macroInExpressionAux(bool b);
26 int macroInExpression(int *p, int y) {;
27 y++;
28 macroInExpressionAux(checkmacro);
30 return *p; // expected-warning {{Dereference of null pointer}}
33 #define noPathNoteMacro y+y
34 int macroInExpressionNoNote(int *p, int y) {;
35 y++;
36 if (5 + noPathNoteMacro)
37 if (p)
39 return *p; // expected-warning {{Dereference of null pointer}}
42 #define macroWithArg(mp) mp==0
43 int macroWithArgInExpression(int *p, int y) {;
44 y++;
45 if (macroWithArg(p))
47 return *p; // expected-warning {{Dereference of null pointer}}
50 #define multiNoteMacroWithError \
51 if (p) \
53 *p = 5;
54 int useMultiNoteMacroWithError(int *p, int y) {;
55 y++;
56 multiNoteMacroWithError // expected-warning {{Dereference of null pointer}}
58 return *p;
61 #define multiNoteMacro \
62 if (p) \
64 if (y) \
66 int useMultiNote(int *p, int y) {;
67 y++;
68 if (p) {}
69 multiNoteMacro
71 return *p; // expected-warning {{Dereference of null pointer}}
74 #define CALL_FN(a) null_deref(a)
76 void null_deref(int *a) {
77 if (a)
78 return;
79 *a = 1; // expected-warning {{Dereference of null pointer}}
82 void test1() {
83 CALL_FN(0);
86 void test2(int *p) {
87 CALL_FN(p);