| 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 |
| 11 |
// |
| 12 |
// RUN: cd "%t" && %clang_extdef_map "%t/ctu-other.c" > externalDefMap.txt |
| 13 |
// |
| 14 |
// RUN: cd "%t" && %clang_analyze_cc1 -std=c89 \ |
| 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 |
| 21 |
// |
| 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) |
| 24 |
// |
| 25 |
// FIXME: Path handling should work on all platforms. |
| 26 |
// REQUIRES: system-linux |
| 27 |
// UNSUPPORTED: target={{.*}}-zos{{.*}} |
| 28 |
|
| 29 |
void clang_analyzer_eval(int); |
| 30 |
|
| 31 |
// Test typedef and global variable in function. |
| 32 |
typedef struct { |
| 33 |
int a; |
| 34 |
int b; |
| 35 |
} FooBar; |
| 36 |
extern FooBar fb; |
| 37 |
int f(int); |
| 38 |
void testGlobalVariable() { |
| 39 |
clang_analyzer_eval(f(5) == 1); // expected-warning{{TRUE}} |
| 40 |
} |
| 41 |
|
| 42 |
// Test enums. |
| 43 |
int enumCheck(void); |
| 44 |
enum A { x, |
| 45 |
y, |
| 46 |
z }; |
| 47 |
void testEnum() { |
| 48 |
clang_analyzer_eval(x == 0); // expected-warning{{TRUE}} |
| 49 |
clang_analyzer_eval(enumCheck() == 42); // expected-warning{{TRUE}} |
| 50 |
} |
| 51 |
|
| 52 |
// Test that asm import does not fail. |
| 53 |
int inlineAsm(); |
| 54 |
int testInlineAsm() { return inlineAsm(); } |
| 55 |
|
| 56 |
// Test reporting error in a macro. |
| 57 |
struct S; |
| 58 |
int g(struct S *); |
| 59 |
void testMacro(void) { |
| 60 |
g(0); |
| 61 |
// [email protected]:29 {{Access to field 'a' results in a dereference of a null pointer (loaded from variable 'ctx')}} |
| 62 |
} |
| 63 |
|
| 64 |
// The external function prototype is incomplete. |
| 65 |
// warning:implicit functions are prohibited by c99 |
| 66 |
void testImplicit() { |
| 67 |
int res = identImplicit(6); // external implicit functions are not inlined |
| 68 |
clang_analyzer_eval(res == 6); // expected-warning{{TRUE}} |
| 69 |
// Call something with uninitialized from the same function in which the |
| 70 |
// implicit was called. This is necessary to reproduce a special bug in |
| 71 |
// NoStoreFuncVisitor. |
| 72 |
int uninitialized; |
| 73 |
h(uninitialized); // expected-warning{{1st function call argument is an uninitialized value}} |
| 74 |
} |
| 75 |
|
| 76 |
// Tests the import of functions that have a struct parameter |
| 77 |
// defined in its prototype. |
| 78 |
struct DataType { |
| 79 |
int a; |
| 80 |
int b; |
| 81 |
}; |
| 82 |
int structInProto(struct DataType *d); |
| 83 |
void testStructDefInArgument() { |
| 84 |
struct DataType d; |
| 85 |
d.a = 1; |
| 86 |
d.b = 0; |
| 87 |
clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}} |
| 88 |
} |