| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: mkdir -p %t/Inputs |
| 3 |
// RUN: cp %s %t/ctu-on-demand-parsing.cpp |
| 4 |
// RUN: cp %S/ctu-hdr.h %t/ctu-hdr.h |
| 5 |
// RUN: cp %S/Inputs/ctu-chain.cpp %t/Inputs/ctu-chain.cpp |
| 6 |
// RUN: cp %S/Inputs/ctu-other.cpp %t/Inputs/ctu-other.cpp |
| 7 |
// |
| 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.json |
| 11 |
// |
| 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.yaml |
| 13 |
// |
| 14 |
// RUN: cd "%t" && %clang_extdef_map Inputs/ctu-chain.cpp Inputs/ctu-other.cpp > externalDefMap.txt |
| 15 |
// |
| 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.cpp |
| 23 |
// 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.cpp |
| 29 |
// |
| 30 |
// CHECK: CTU loaded AST file: {{.*}}ctu-other.cpp |
| 31 |
// CHECK: CTU loaded AST file: {{.*}}ctu-chain.cpp |
| 32 |
|
| 33 |
// FIXME: On-demand ctu should be tested in the same file that we have for the |
| 34 |
// 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-linux |
| 38 |
// UNSUPPORTED: target={{.*}}-zos{{.*}} |
| 39 |
|
| 40 |
#include "ctu-hdr.h" |
| 41 |
|
| 42 |
void clang_analyzer_eval(int); |
| 43 |
|
| 44 |
int f(int); |
| 45 |
int g(int); |
| 46 |
int h(int); |
| 47 |
|
| 48 |
int callback_to_main(int x) { return x + 1; } |
| 49 |
|
| 50 |
namespace myns { |
| 51 |
int fns(int x); |
| 52 |
|
| 53 |
namespace embed_ns { |
| 54 |
int fens(int x); |
| 55 |
} |
| 56 |
|
| 57 |
class embed_cls { |
| 58 |
public: |
| 59 |
int fecl(int x); |
| 60 |
}; |
| 61 |
} // namespace myns |
| 62 |
|
| 63 |
class mycls { |
| 64 |
public: |
| 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 |
|
| 75 |
class derived : public mycls { |
| 76 |
public: |
| 77 |
virtual int fvcl(int x) override; |
| 78 |
}; |
| 79 |
|
| 80 |
namespace chns { |
| 81 |
int chf1(int x); |
| 82 |
} |
| 83 |
|
| 84 |
int fun_using_anon_struct(int); |
| 85 |
int other_macro_diag(int); |
| 86 |
|
| 87 |
void 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 |
|
| 96 |
int 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 |
} |