mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 14:16:44 +00:00

This new CTU implementation is the natural extension of the normal single TU analysis. The approach consists of two analysis phases. During the first phase, we do a normal single TU analysis. During this phase, if we find a foreign function (that could be inlined from another TU) then we don’t inline that immediately, we rather mark that to be analysed later. When the first phase is finished then we start the second phase, the CTU phase. In this phase, we continue the analysis from that point (exploded node) which had been enqueued during the first phase. We gradually extend the exploded graph of the single TU analysis with the new node that was created by the inlining of the foreign function. We count the number of analysis steps of the first phase and we limit the second (ctu) phase with this number. This new implementation makes it convenient for the users to run the single-TU and the CTU analysis in one go, they don't need to run the two analysis separately. Thus, we name this new implementation as "onego" CTU. Discussion: https://discourse.llvm.org/t/rfc-much-faster-cross-translation-unit-ctu-analysis-implementation/61728 Differential Revision: https://reviews.llvm.org/D123773
55 lines
2.1 KiB
C++
55 lines
2.1 KiB
C++
// RUN: rm -rf %t && mkdir %t
|
|
// RUN: mkdir -p %t/ctudir
|
|
// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
|
|
// RUN: -emit-pch -o %t/ctudir/ctu-onego-toplevel-other.cpp.ast %S/Inputs/ctu-onego-toplevel-other.cpp
|
|
// RUN: cp %S/Inputs/ctu-onego-toplevel-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
|
|
|
|
// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
|
|
// RUN: -analyzer-checker=core,debug.ExprInspection \
|
|
// RUN: -analyzer-config eagerly-assume=false \
|
|
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
|
|
// RUN: -analyzer-config ctu-dir=%t/ctudir \
|
|
// RUN: -analyzer-config ctu-phase1-inlining=none \
|
|
// RUN: -verify=ctu %s
|
|
|
|
// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
|
|
// RUN: -analyzer-checker=core,debug.ExprInspection \
|
|
// RUN: -analyzer-config eagerly-assume=false \
|
|
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
|
|
// RUN: -analyzer-config ctu-dir=%t/ctudir \
|
|
// RUN: -analyzer-config ctu-phase1-inlining=none \
|
|
// RUN: -analyzer-config display-ctu-progress=true \
|
|
// RUN: -analyzer-display-progress \
|
|
// RUN: -verify=ctu %s 2>&1 | FileCheck %s
|
|
|
|
// CallGraph: c->b
|
|
// topological sort: c, b
|
|
// Note that `other` calls into `b` but that is not visible in the CallGraph
|
|
// because that happens in another TU.
|
|
|
|
// During the onego CTU analysis, we start with c() as top level function.
|
|
// Then we visit b() as non-toplevel during the processing of the FWList, thus
|
|
// that would not be visited as toplevel without special care.
|
|
|
|
// `c` is analyzed as toplevel and during that the other TU is loaded:
|
|
// CHECK: ANALYZE (Path, Inline_Regular): {{.*}} c(int){{.*}}CTU loaded AST file
|
|
// next, `b` is analyzed as toplevel:
|
|
// CHECK: ANALYZE (Path, Inline_Regular): {{.*}} b(int)
|
|
|
|
void b(int x);
|
|
void other(int y);
|
|
void c(int y) {
|
|
other(y);
|
|
return;
|
|
// The below call is here to form the proper CallGraph, but will not be
|
|
// analyzed.
|
|
b(1);
|
|
}
|
|
|
|
void b(int x) {
|
|
if (x == 0)
|
|
(void)(1 / x);
|
|
// ctu-warning@-1{{Division by zero}}
|
|
// We receive the above warning only if `b` is analyzed as top-level.
|
|
}
|