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) {
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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits