brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · 0c0128f Raw
117 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir -p %t/Inputs3// RUN: cp %s %t/ctu-on-demand-parsing.cpp4// RUN: cp %S/ctu-hdr.h %t/ctu-hdr.h5// RUN: cp %S/Inputs/ctu-chain.cpp %t/Inputs/ctu-chain.cpp6// RUN: cp %S/Inputs/ctu-other.cpp %t/Inputs/ctu-other.cpp7//8// Path substitutions on Windows platform could contain backslashes. These are escaped in the json file.9// compile_commands.json is only needed for the extdef_mapping, not for the analysis itself.10// RUN: echo '[{"directory":"%t/Inputs","command":"clang++ ctu-chain.cpp","file":"ctu-chain.cpp"},{"directory":"%t/Inputs","command":"clang++ ctu-other.cpp","file":"ctu-other.cpp"}]' | sed -e 's/\\/\\\\/g' > %t/compile_commands.json11//12// RUN: echo '{"%t/Inputs/ctu-chain.cpp": ["g++", "%t/Inputs/ctu-chain.cpp"], "%t/Inputs/ctu-other.cpp": ["g++", "%t/Inputs/ctu-other.cpp"]}' | sed -e 's/\\/\\\\/g' > %t/invocations.yaml13//14// RUN: cd "%t" && %clang_extdef_map Inputs/ctu-chain.cpp Inputs/ctu-other.cpp > externalDefMap.txt15//16// RUN: cd "%t" && %clang_analyze_cc1 \17// RUN:   -analyzer-checker=core,debug.ExprInspection \18// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \19// RUN:   -analyzer-config ctu-dir=. \20// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \21// RUN:   -analyzer-config ctu-phase1-inlining=all \22// RUN:   -verify ctu-on-demand-parsing.cpp23// RUN: cd "%t" && %clang_analyze_cc1 \24// RUN:   -analyzer-checker=core,debug.ExprInspection \25// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \26// RUN:   -analyzer-config ctu-dir=. \27// RUN:   -analyzer-config ctu-invocation-list=invocations.yaml \28// RUN:   -analyzer-config display-ctu-progress=true ctu-on-demand-parsing.cpp 2>&1 | FileCheck %t/ctu-on-demand-parsing.cpp29//30// CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp31// CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp32 33// FIXME: On-demand ctu should be tested in the same file that we have for the34// PCH version, but with a different verify prefix (e.g. -verfiy=on-demand-ctu)35//36// FIXME: Path handling should work on all platforms.37// REQUIRES: system-linux38// UNSUPPORTED: target={{.*}}-zos{{.*}}39 40#include "ctu-hdr.h"41 42void clang_analyzer_eval(int);43 44int f(int);45int g(int);46int h(int);47 48int callback_to_main(int x) { return x + 1; }49 50namespace myns {51int fns(int x);52 53namespace embed_ns {54int fens(int x);55}56 57class embed_cls {58public:59  int fecl(int x);60};61} // namespace myns62 63class mycls {64public:65  int fcl(int x);66  virtual int fvcl(int x);67  static int fscl(int x);68 69  class embed_cls2 {70  public:71    int fecl2(int x);72  };73};74 75class derived : public mycls {76public:77  virtual int fvcl(int x) override;78};79 80namespace chns {81int chf1(int x);82}83 84int fun_using_anon_struct(int);85int other_macro_diag(int);86 87void test_virtual_functions(mycls *obj) {88  // The dynamic type is known.89  clang_analyzer_eval(mycls().fvcl(1) == 8);   // expected-warning{{TRUE}}90  clang_analyzer_eval(derived().fvcl(1) == 9); // expected-warning{{TRUE}}91  // We cannot decide about the dynamic type.92  clang_analyzer_eval(obj->fvcl(1) == 8); // expected-warning{{FALSE}} expected-warning{{TRUE}}93  clang_analyzer_eval(obj->fvcl(1) == 9); // expected-warning{{FALSE}} expected-warning{{TRUE}}94}95 96int main() {97  clang_analyzer_eval(f(3) == 2); // expected-warning{{TRUE}}98  clang_analyzer_eval(f(4) == 3); // expected-warning{{TRUE}}99  clang_analyzer_eval(f(5) == 3); // expected-warning{{FALSE}}100  clang_analyzer_eval(g(4) == 6); // expected-warning{{TRUE}}101  clang_analyzer_eval(h(2) == 8); // expected-warning{{TRUE}}102 103  clang_analyzer_eval(myns::fns(2) == 9);                   // expected-warning{{TRUE}}104  clang_analyzer_eval(myns::embed_ns::fens(2) == -1);       // expected-warning{{TRUE}}105  clang_analyzer_eval(mycls().fcl(1) == 6);                 // expected-warning{{TRUE}}106  clang_analyzer_eval(mycls::fscl(1) == 7);                 // expected-warning{{TRUE}}107  clang_analyzer_eval(myns::embed_cls().fecl(1) == -6);     // expected-warning{{TRUE}}108  clang_analyzer_eval(mycls::embed_cls2().fecl2(0) == -11); // expected-warning{{TRUE}}109 110  clang_analyzer_eval(chns::chf1(4) == 12);           // expected-warning{{TRUE}}111  clang_analyzer_eval(fun_using_anon_struct(8) == 8); // expected-warning{{TRUE}}112 113  clang_analyzer_eval(other_macro_diag(1) == 1); // expected-warning{{TRUE}}114  // expected-warning@Inputs/ctu-other.cpp:93{{REACHABLE}}115  MACRODIAG(); // expected-warning{{REACHABLE}}116}117