llvm-capstone/clang/test/Analysis/inline-if-constexpr.cpp
Artem Dergachev ab7747b727 [analyzer] Treat functions without run-time branches as "small".
Currently we always inline functions that have no branches, i.e. have exactly
three CFG blocks: ENTRY, some code, EXIT. This makes sense because when there
are no branches, it means that there's no exponential complexity introduced
by inlining such function. Such functions also don't trigger various fundamental
problems with our inlining mechanism, such as the problem of inlined
defensive checks.

Sometimes the CFG may contain more blocks, but in practice it still has
linear structure because all directions (except, at most, one) of all branches
turned out to be unreachable. When this happens, still treat the function
as "small". This is useful, in particular, for dealing with C++17 if constexpr.

Differential Revision: https://reviews.llvm.org/D61051

llvm-svn: 359531
2019-04-30 03:01:02 +00:00

19 lines
742 B
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
// RUN: -analyzer-inline-max-stack-depth=5 -w -std=c++17 -verify %s
void clang_analyzer_eval(bool);
namespace inline_large_functions_with_if_constexpr {
bool f0() { if constexpr (true); return true; }
bool f1() { if constexpr (true); return f0(); }
bool f2() { if constexpr (true); return f1(); }
bool f3() { if constexpr (true); return f2(); }
bool f4() { if constexpr (true); return f3(); }
bool f5() { if constexpr (true); return f4(); }
bool f6() { if constexpr (true); return f5(); }
bool f7() { if constexpr (true); return f6(); }
void bar() {
clang_analyzer_eval(f7()); // expected-warning{{TRUE}}
}
} // namespace inline_large_functions_with_if_constexpr