[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / ctu-on-demand-parsing.c
blob815921060350ee2f3a91610e04636869999917cb
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: cp "%s" "%t/ctu-on-demand-parsing.c"
4 // RUN: cp "%S/Inputs/ctu-other.c" "%t/ctu-other.c"
5 //
6 // Path substitutions on Windows platform could contain backslashes. These are escaped in the json file.
7 // compile_commands.json is only needed for extdef_mapping, not for the analysis itself.
8 // RUN: echo '[{"directory":"%t","command":"gcc -std=c89 -Wno-visibility ctu-other.c","file":"ctu-other.c"}]' | sed -e 's/\\/\\\\/g' > %t/compile_commands.json
9 //
10 // RUN: echo '"%t/ctu-other.c": ["gcc", "-std=c89", "-Wno-visibility", "ctu-other.c"]' | sed -e 's/\\/\\\\/g' > %t/invocations.yaml
12 // RUN: cd "%t" && %clang_extdef_map "%t/ctu-other.c" > externalDefMap.txt
14 // RUN: cd "%t" && %clang_cc1 -fsyntax-only -std=c89 -analyze \
15 // RUN: -analyzer-checker=core,debug.ExprInspection \
16 // RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
17 // RUN: -analyzer-config ctu-dir=. \
18 // RUN: -analyzer-config ctu-invocation-list=invocations.yaml \
19 // RUN: -analyzer-config ctu-phase1-inlining=all \
20 // RUN: -verify ctu-on-demand-parsing.c
22 // FIXME: On-demand ctu should be tested in the same file that we have for the
23 // PCH version, but with a different verify prefix (e.g. -verfiy=on-demand-ctu)
25 // FIXME: Path handling should work on all platforms.
26 // REQUIRES: system-linux
28 void clang_analyzer_eval(int);
30 // Test typedef and global variable in function.
31 typedef struct {
32 int a;
33 int b;
34 } FooBar;
35 extern FooBar fb;
36 int f(int);
37 void testGlobalVariable() {
38 clang_analyzer_eval(f(5) == 1); // expected-warning{{TRUE}}
41 // Test enums.
42 int enumCheck(void);
43 enum A { x,
45 z };
46 void testEnum() {
47 clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
48 clang_analyzer_eval(enumCheck() == 42); // expected-warning{{TRUE}}
51 // Test that asm import does not fail.
52 int inlineAsm();
53 int testInlineAsm() { return inlineAsm(); }
55 // Test reporting error in a macro.
56 struct S;
57 int g(struct S *);
58 void testMacro(void) {
59 g(0);
60 // expected-warning@ctu-other.c:29 {{Access to field 'a' results in a dereference of a null pointer (loaded from variable 'ctx')}}
63 // The external function prototype is incomplete.
64 // warning:implicit functions are prohibited by c99
65 void testImplicit() {
66 int res = identImplicit(6); // external implicit functions are not inlined
67 clang_analyzer_eval(res == 6); // expected-warning{{TRUE}}
68 // Call something with uninitialized from the same function in which the
69 // implicit was called. This is necessary to reproduce a special bug in
70 // NoStoreFuncVisitor.
71 int uninitialized;
72 h(uninitialized); // expected-warning{{1st function call argument is an uninitialized value}}
75 // Tests the import of functions that have a struct parameter
76 // defined in its prototype.
77 struct DataType {
78 int a;
79 int b;
81 int structInProto(struct DataType *d);
82 void testStructDefInArgument() {
83 struct DataType d;
84 d.a = 1;
85 d.b = 0;
86 clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}