xref: /llvm-project/clang/test/Analysis/ctu-onego-toplevel.cpp (revision 56b9b97c1ef594f218eb06d2e62daa85cc238500)
1 // RUN: rm -rf %t && mkdir %t
2 // RUN: mkdir -p %t/ctudir
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
4 // RUN:   -emit-pch -o %t/ctudir/ctu-onego-toplevel-other.cpp.ast %S/Inputs/ctu-onego-toplevel-other.cpp
5 // RUN: cp %S/Inputs/ctu-onego-toplevel-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
6 
7 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
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/ctudir \
12 // RUN:   -analyzer-config ctu-phase1-inlining=none \
13 // RUN:   -verify=ctu %s
14 
15 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
16 // RUN:   -analyzer-checker=core,debug.ExprInspection \
17 // RUN:   -analyzer-config eagerly-assume=false \
18 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
19 // RUN:   -analyzer-config ctu-dir=%t/ctudir \
20 // RUN:   -analyzer-config ctu-phase1-inlining=none \
21 // RUN:   -analyzer-config display-ctu-progress=true \
22 // RUN:   -analyzer-display-progress \
23 // RUN:   -verify=ctu %s 2>&1 | FileCheck %s
24 
25 // CallGraph: c->b
26 // topological sort: c, b
27 // Note that `other` calls into `b` but that is not visible in the CallGraph
28 // because that happens in another TU.
29 
30 // During the onego CTU analysis, we start with c() as top level function.
31 // Then we visit b() as non-toplevel during the processing of the FWList, thus
32 // that would not be visited as toplevel without special care.
33 
34 // `c` is analyzed as toplevel and during that the other TU is loaded:
35 // CHECK: ANALYZE (Path,  Inline_Regular): {{.*}} c(int){{.*}}CTU loaded AST file
36 // next, `b` is analyzed as toplevel:
37 // CHECK: ANALYZE (Path,  Inline_Regular): {{.*}} b(int)
38 
39 void b(int x);
40 void other(int y);
c(int y)41 void c(int y) {
42   other(y);
43   return;
44   // The below call is here to form the proper CallGraph, but will not be
45   // analyzed.
46   b(1);
47 }
48 
b(int x)49 void b(int x) {
50   if (x == 0)
51     (void)(1 / x);
52     // ctu-warning@-1{{Division by zero}}
53     // We receive the above warning only if `b` is analyzed as top-level.
54 }
55