brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 2107b98 Raw
89 lines · c
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// 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.json9//10// RUN: echo '"%t/ctu-other.c": ["gcc", "-std=c89", "-Wno-visibility", "ctu-other.c"]' | sed -e 's/\\/\\\\/g' > %t/invocations.yaml11//12// RUN: cd "%t" && %clang_extdef_map "%t/ctu-other.c" > externalDefMap.txt13//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.c21//22// FIXME: On-demand ctu should be tested in the same file that we have for the23// 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-linux27// UNSUPPORTED: target={{.*}}-zos{{.*}}28 29void clang_analyzer_eval(int);30 31// Test typedef and global variable in function.32typedef struct {33  int a;34  int b;35} FooBar;36extern FooBar fb;37int f(int);38void testGlobalVariable() {39  clang_analyzer_eval(f(5) == 1); // expected-warning{{TRUE}}40}41 42// Test enums.43int enumCheck(void);44enum A { x,45         y,46         z };47void 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.53int inlineAsm();54int testInlineAsm() { return inlineAsm(); }55 56// Test reporting error in a macro.57struct S;58int g(struct S *);59void testMacro(void) {60  g(0);61  // expected-warning@ctu-other.c: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 c9966void testImplicit() {67  int res = identImplicit(6);    // external implicit functions are not inlined68  clang_analyzer_eval(res == 6); // expected-warning{{TRUE}}69  // Call something with uninitialized from the same function in which the70  // implicit was called. This is necessary to reproduce a special bug in71  // 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 parameter77// defined in its prototype.78struct DataType {79  int a;80  int b;81};82int structInProto(struct DataType *d);83void 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}89