1 // RUN: rm -rf %t && mkdir %t
2 // RUN: mkdir -p %t/ctudir2
3 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
4 // RUN:   -emit-pch -o %t/ctudir2/ctu-other.c.ast %S/Inputs/ctu-other.c
5 // RUN: cp %S/Inputs/ctu-other.c.externalDefMap.ast-dump.txt %t/ctudir2/externalDefMap.txt
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -std=c89 -analyze \
7 // RUN:   -analyzer-checker=core,debug.ExprInspection \
8 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
9 // RUN:   -analyzer-config ctu-dir=%t/ctudir2 \
10 // RUN:   -verify %s
11 
12 void clang_analyzer_eval(int);
13 
14 // Test typedef and global variable in function.
15 typedef struct {
16   int a;
17   int b;
18 } FooBar;
19 extern FooBar fb;
20 int f(int);
testGlobalVariable()21 void testGlobalVariable() {
22   clang_analyzer_eval(f(5) == 1);         // expected-warning{{TRUE}}
23 }
24 
25 // Test enums.
26 int enumCheck(void);
27 enum A { x,
28          y,
29          z };
testEnum()30 void testEnum() {
31   clang_analyzer_eval(x == 0);            // expected-warning{{TRUE}}
32   clang_analyzer_eval(enumCheck() == 42); // expected-warning{{TRUE}}
33 }
34 
35 // Test that asm import does not fail.
36 int inlineAsm();
testInlineAsm()37 int testInlineAsm() {
38   return inlineAsm();
39 }
40 
41 // Test reporting error in a macro.
42 struct S;
43 int g(struct S *);
testMacro(void)44 void testMacro(void) {
45   g(0); // expected-warning@Inputs/ctu-other.c:29 {{Access to field 'a' results in a dereference of a null pointer (loaded from variable 'ctx')}}
46 }
47 
48 // The external function prototype is incomplete.
49 // warning:implicit functions are prohibited by c99
testImplicit()50 void testImplicit() {
51   int res = identImplicit(6);   // external implicit functions are not inlined
52   clang_analyzer_eval(res == 6); // expected-warning{{TRUE}}
53   // Call something with uninitialized from the same function in which the implicit was called.
54   // This is necessary to reproduce a special bug in NoStoreFuncVisitor.
55   int uninitialized;
56   h(uninitialized); // expected-warning{{1st function call argument is an uninitialized value}}
57 }
58 
59 // Tests the import of functions that have a struct parameter
60 // defined in its prototype.
61 struct DataType {
62   int a;
63   int b;
64 };
65 int structInProto(struct DataType *d);
testStructDefInArgument()66 void testStructDefInArgument() {
67   struct DataType d;
68   d.a = 1;
69   d.b = 0;
70   clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}
71 }
72