• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: rm -rf %t && mkdir %t
2 // RUN: mkdir -p %t/ctudir
3 // RUN: %clang_cc1 -emit-pch -o %t/ctudir/plist-macros-ctu.c.ast %S/Inputs/plist-macros-ctu.c
4 // RUN: cp %S/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt %t/ctudir/externalDefMap.txt
5 
6 // RUN: %clang_analyze_cc1 -analyzer-checker=core \
7 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
8 // RUN:   -analyzer-config ctu-dir=%t/ctudir \
9 // RUN:   -analyzer-config expand-macros=true \
10 // RUN:   -analyzer-output=plist-multi-file -o %t.plist -verify %s
11 
12 // Check the macro expansions from the plist output here, to make the test more
13 // understandable.
14 //   RUN: FileCheck --input-file=%t.plist %s
15 
16 extern void F1(int **);
17 extern void F2(int **);
18 extern void F3(int **);
19 extern void F_H(int **);
20 
test0()21 void test0() {
22   int *X;
23   F3(&X);
24   *X = 1; // expected-warning{{Dereference of null pointer}}
25 }
26 // CHECK: <key>name</key><string>M1</string>
27 // CHECK-NEXT: <key>expansion</key><string>*Z = (int *)0</string>
28 
29 
test1()30 void test1() {
31   int *X;
32   F1(&X);
33   *X = 1; // expected-warning{{Dereference of null pointer}}
34 }
35 // CHECK: <key>name</key><string>M</string>
36 // CHECK-NEXT: <key>expansion</key><string>*X = (int *)0</string>
37 
test2()38 void test2() {
39   int *X;
40   F2(&X);
41   *X = 1; // expected-warning{{Dereference of null pointer}}
42 }
43 // CHECK: <key>name</key><string>M</string>
44 // CHECK-NEXT: <key>expansion</key><string>*Y = (int *)0</string>
45 
46 #define M F1(&X)
47 
test3()48 void test3() {
49   int *X;
50   M;
51   *X = 1; // expected-warning{{Dereference of null pointer}}
52 }
53 // CHECK: <key>name</key><string>M</string>
54 // CHECK-NEXT: <key>expansion</key><string>F1(&amp;X)</string>
55 // CHECK: <key>name</key><string>M</string>
56 // CHECK-NEXT: <key>expansion</key><string>*X = (int *)0</string>
57 
58 #undef M
59 #define M F2(&X)
60 
test4()61 void test4() {
62   int *X;
63   M;
64   *X = 1; // expected-warning{{Dereference of null pointer}}
65 }
66 
67 // CHECK: <key>name</key><string>M</string>
68 // CHECK-NEXT: <key>expansion</key><string>F2(&amp;X)</string>
69 // CHECK: <key>name</key><string>M</string>
70 // CHECK-NEXT: <key>expansion</key><string>*Y = (int *)0</string>
71 
test_h()72 void test_h() {
73   int *X;
74   F_H(&X);
75   *X = 1; // expected-warning{{Dereference of null pointer}}
76 }
77 
78 // CHECK: <key>name</key><string>M_H</string>
79 // CHECK-NEXT: <key>expansion</key><string>*A = (int *)0</string>
80