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.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); |
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 }; |
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(); |
37 | int testInlineAsm() { |
38 | return inlineAsm(); |
39 | } |
40 | |
41 | // Test reporting error in a macro. |
42 | struct S; |
43 | int g(struct S *); |
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 |
50 | void testImplicit() { |
51 | int res = identImplicit(6); // external implicit functions are not inlined |
52 | clang_analyzer_eval(res == 6); // expected-warning{{TRUE}} |
53 | } |
54 | |
55 | // Tests the import of functions that have a struct parameter |
56 | // defined in its prototype. |
57 | struct DataType { |
58 | int a; |
59 | int b; |
60 | }; |
61 | int structInProto(struct DataType *d); |
62 | void testStructDefInArgument() { |
63 | struct DataType d; |
64 | d.a = 1; |
65 | d.b = 0; |
66 | clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}} |
67 | } |
68 | |