[PATCH] D52390: [analyzer] StackSizeChecker
Máté Tóth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 22 04:04:38 PDT 2018
mate1214 created this revision.
mate1214 added reviewers: NoQ, george.karpenkov, dcoughlin.
Herald added subscribers: cfe-commits, Szelethus, mikhail.ramalho, a.sidorin, szepet, mgorny.
Add StackSizeChecker to StaticAnalyzer
This checker can be used to warn about potential stack overflows
or be used to estimate the size of used stack space.
Both a clang static analyzer and a clang-tidy version exist.
The clang-tidy version references the StackUsageMeasuringVisitor
class included in this commit so it can only come after this.
Both versions work by examining function bodies via the AST,
the static analyzer version can follow and summarize the space
used by call chains, while the calng-tidy version can analyze
function bodies faster, one by one.
This version emits warnings if the estimated stack size surpasses
the StackUsageLimit parameter, which is measured in bytes and
defaults to 100000. Setting it to some small value can be used
to turn the checker into a statistical tool since the calculated
values are included in the warning messages.
The calculations used for the size estimations do not take into
account potential compile-time optimizations and contain some
minor simplifications. Only the information stored in the AST
is used and variable lifetime rules are respected. The
calculations in a particular function body are carried out by the
StackUsageMeasuringVisitor class, which gives a composite result
about a piece of the AST containing the maximal estimated space,
the space that remain in use after the execution of those lines
and flags about encountered variable length arrays or special
nodes that satisfy a given predicate (e.g.: templates).
The current version takes no special actions upon encountering
variable length arrays, the tidy version has a simple extra logic
for them. The tests are divided between the two versions, the
static analyzer ones are about the ability to calculate the size
of a complete call stack and the clang-tidy ones focus on
particular statements and expression types, this is referenced
in one of the comments of the test files for those who want
to use the test cases to understand the checker a little bit more.
The code favors readability and maintainability over performance
in some places.
Repository:
rC Clang
https://reviews.llvm.org/D52390
Files:
include/clang/StaticAnalyzer/Checkers/Checkers.td
include/clang/StaticAnalyzer/Checkers/StackUsageMeasuringVisitor.h
lib/StaticAnalyzer/Checkers/CMakeLists.txt
lib/StaticAnalyzer/Checkers/StackSizeChecker.cpp
lib/StaticAnalyzer/Checkers/StackUsageMeasuringVisitor.cpp
test/Analysis/stack-size-callchain.cpp
test/Analysis/stack-size.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52390.166601.patch
Type: text/x-patch
Size: 33401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180922/b199271a/attachment-0001.bin>
More information about the cfe-commits
mailing list