brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · e24510e Raw
110 lines · c
1// RUN: rm -rf %t && mkdir %t2// RUN: mkdir -p %t/ctudir23// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \4// RUN:   -emit-pch -o %t/ctudir2/ctu-other.c.ast %S/Inputs/ctu-other.c5// RUN: cp %S/Inputs/ctu-other.c.externalDefMap.ast-dump.txt %t/ctudir2/externalDefMap.txt6 7// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -std=c89 \8// RUN:   -analyzer-checker=core,debug.ExprInspection \9// RUN:   -analyzer-config eagerly-assume=false \10// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \11// RUN:   -analyzer-config ctu-dir=%t/ctudir2 \12// RUN:   -analyzer-config ctu-phase1-inlining=none \13// RUN:   -verify=newctu %s14 15// Simulate the behavior of the previous CTU implementation by inlining all16// functions during the first phase. This way, the second phase is a noop.17// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -std=c89 \18// RUN:   -analyzer-checker=core,debug.ExprInspection \19// RUN:   -analyzer-config eagerly-assume=false \20// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \21// RUN:   -analyzer-config ctu-dir=%t/ctudir2 \22// RUN:   -analyzer-config ctu-phase1-inlining=all \23// RUN:   -verify=oldctu %s24 25void clang_analyzer_eval(int);26 27// A function that's definition is unknown both for single-tu (stu) and ctu28// mode.29int unknown(int);30void test_unknown() {31  int res = unknown(6);32  clang_analyzer_eval(res == 6); // newctu-warning{{UNKNOWN}}33                                 // oldctu-warning@-1{{UNKNOWN}}34}35 36// Test typedef and global variable in function.37typedef struct {38  int a;39  int b;40} FooBar;41extern FooBar fb;42int f(int);43void testGlobalVariable() {44  clang_analyzer_eval(f(5) == 1);         // newctu-warning{{TRUE}} ctu45                                          // newctu-warning@-1{{UNKNOWN}} stu46                                          // oldctu-warning@-2{{TRUE}}47}48 49// Test enums.50int enumCheck(void);51enum A { x,52         y,53         z };54void testEnum(void) {55  clang_analyzer_eval(x == 0);            // newctu-warning{{TRUE}}56                                          // oldctu-warning@-1{{TRUE}}57  clang_analyzer_eval(enumCheck() == 42); // newctu-warning{{TRUE}} ctu58                                          // newctu-warning@-1{{UNKNOWN}} stu59                                          // oldctu-warning@-2{{TRUE}}60}61 62// Test that asm import does not fail.63int inlineAsm(void);64int testInlineAsm(void) {65  return inlineAsm();66}67 68// Test reporting error in a macro.69struct S;70int g(struct S *);71void testMacro(void) {72  g(0); // newctu-warning@Inputs/ctu-other.c:29 {{Access to field 'a' results in a dereference of a null pointer (loaded from variable 'ctx')}}73        // oldctu-warning@Inputs/ctu-other.c:29 {{Access to field 'a' results in a dereference of a null pointer (loaded from variable 'ctx')}}74}75 76// The external function prototype is incomplete.77// warning:implicit functions are prohibited by c9978void testImplicit(void) {79  int res = identImplicit(6);   // external implicit functions are not inlined80  clang_analyzer_eval(res == 6); // newctu-warning{{TRUE}} ctu81                                 // newctu-warning@-1{{UNKNOWN}} stu82                                 // oldctu-warning@-2{{TRUE}}83  // Call something with uninitialized from the same function in which the implicit was called.84  // This is necessary to reproduce a special bug in NoStoreFuncVisitor.85  int uninitialized;86  h(uninitialized); // newctu-warning{{1st function call argument is an uninitialized value}}87                    // oldctu-warning@-1{{1st function call argument is an uninitialized value}}88}89 90// Tests the import of functions that have a struct parameter91// defined in its prototype.92struct DataType {93  int a;94  int b;95};96int structInProto(struct DataType *d);97void testStructDefInArgument(void) {98  struct DataType d;99  d.a = 1;100  d.b = 0;101  // Not imported, thus remains unknown both in stu and ctu.102  clang_analyzer_eval(structInProto(&d) == 0); // newctu-warning{{UNKNOWN}}103                                               // oldctu-warning@-1{{UNKNOWN}}104}105 106int switchWithoutCases(int);107void testSwitchStmtCrash(int x) {108  switchWithoutCases(x);109}110