[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 14 08:00:05 PDT 2020
balazske updated this revision to Diff 257330.
balazske added a comment.
- Added tests.
- Updated a comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77809/new/
https://reviews.llvm.org/D77809
Files:
clang/lib/Analysis/CFG.cpp
clang/test/Analysis/cfg.cpp
Index: clang/test/Analysis/cfg.cpp
===================================================================
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -568,6 +568,25 @@
return 2;
}
+// CHECK-LABEL: void vla_simple(int x)
+// CHECK: [B1]
+// CHECK-NEXT: 1: x
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT: 3: int vla[x];
+void vla_simple(int x) {
+ int vla[x];
+}
+
+// CHECK-LABEL: void vla_typedef(int x)
+// CHECK: [B1]
+// CHECK-NEXT: 1: x
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT: 3: VLA vla;
+void vla_typedef(int x) {
+ typedef int VLA[x];
+ VLA vla;
+}
+
// CHECK-LABEL: template<> int *PR18472<int>()
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT: Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===================================================================
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,11 +2839,24 @@
/// 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) {
- // Of everything that can be declared in a DeclStmt, only VarDecls impact
- // runtime semantics.
+ // Of everything that can be declared in a DeclStmt, only VarDecls and the
+ // exceptions above impact runtime semantics.
return Block;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77809.257330.patch
Type: text/x-patch
Size: 1963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200414/35359506/attachment.bin>
More information about the cfe-commits
mailing list