[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 08:52:25 PDT 2020
balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.
Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
(Type-alias is not handled.)
I am not familiar with the CFGBuilder, the new code
only seems to work. Maybe somebody can tell how to
make a better solution (if needed) for the problem.
The fix is useful to have the values used at VLA sizes
available for the analyzer and checkers.
The code works similar as `CodeGenFunction::emitDecl`
that processes typedef and type-alias VLA size expressions
at place of the typedef or type-alias statement.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77809
Files:
clang/lib/Analysis/CFG.cpp
Index: clang/lib/Analysis/CFG.cpp
===================================================================
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,6 +2839,19 @@
/// DeclStmts and initializers in them.
CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
assert(DS->isSingleDecl() && "Can handle single declarations only.");
+
+ if (const auto *TDD = dyn_cast<TypedefDecl>(DS->getSingleDecl())) {
+ // If we encounter a VLA in typedef, then process its size expressions.
+ CFGBlock *LastBlock = Block;
+ for (const VariableArrayType *VA =
+ FindVA(TDD->getUnderlyingType().getTypePtr());
+ VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) {
+ if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
+ LastBlock = newBlock;
+ }
+ return LastBlock;
+ }
+
VarDecl *VD = dyn_cast<VarDecl>(DS->getSingleDecl());
if (!VD) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77809.256322.patch
Type: text/x-patch
Size: 918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200409/b096fa98/attachment-0001.bin>
More information about the cfe-commits
mailing list