3 // RUN: cp "%s" "%t/ctu-on-demand-parsing.c"
4 // RUN: cp "%S/Inputs/ctu-other.c" "%t/ctu-other.c"
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
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: -verify ctu-on-demand-parsing.c
21 // FIXME: Path handling should work on all platforms.
22 // REQUIRES: system-linux
24 void clang_analyzer_eval(int);
26 // Test typedef and global variable in function.
33 void testGlobalVariable() {
34 clang_analyzer_eval(f(5) == 1); // expected-warning{{TRUE}}
43 clang_analyzer_eval(x
== 0); // expected-warning{{TRUE}}
44 clang_analyzer_eval(enumCheck() == 42); // expected-warning{{TRUE}}
47 // Test that asm import does not fail.
49 int testInlineAsm() { return inlineAsm(); }
51 // Test reporting error in a macro.
54 void testMacro(void) {
56 // expected-warning@ctu-other.c:29 {{Access to field 'a' results in a dereference of a null pointer (loaded from variable 'ctx')}}
59 // The external function prototype is incomplete.
60 // warning:implicit functions are prohibited by c99
62 int res
= identImplicit(6); // external implicit functions are not inlined
63 clang_analyzer_eval(res
== 6); // expected-warning{{TRUE}}
64 // Call something with uninitialized from the same function in which the
65 // implicit was called. This is necessary to reproduce a special bug in
66 // NoStoreFuncVisitor.
68 h(uninitialized
); // expected-warning{{1st function call argument is an uninitialized value}}
71 // Tests the import of functions that have a struct parameter
72 // defined in its prototype.
77 int structInProto(struct DataType
*d
);
78 void testStructDefInArgument() {
82 clang_analyzer_eval(structInProto(&d
) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}