[PATCH] D63538: [CFG] Add a new function to get the proper condition of a CFGBlock

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 11:19:10 PDT 2019


NoQ added inline comments.


================
Comment at: clang/lib/Analysis/CFG.cpp:5619-5625
+  // If the terminator is a temporary dtor or a virtual base, etc, we can't
+  // retrieve a meaningful condition, bail out.
+  if (rbegin()->getKind() != CFGElement::Kind::Statement)
+    return nullptr;
+
+  // This should be the condition of the terminator block.
+  const Stmt *S = rbegin()->castAs<CFGStmt>().getStmt();
----------------
I don't think you're looking at the terminator here, as `CFGTerminator` isn't a sub-class of `CFGElement`. So this if doesn't avoid temporary dtor branches or virtual base branches; instead, it avoids various other `CFGElement` sub-classes such as `CFGInitializer` or `CFGImplicitDtor` (not sure how many of those may appear last in a block).

Therefore the following code would be a bit more LLVM-y:
```lang=c++
auto StmtElem = rbegin()->getAs<CFGStmt>();
if (!StmtElem)
  return nullptr;

const Stmt *S = StmtElem->getStmt();
```

Also, are you sure that the last expression is always a condition? Like, what about
```lang=c++
void foo(int x, int y) {
  (void)(x + y);
}
```
?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63538/new/

https://reviews.llvm.org/D63538





More information about the cfe-commits mailing list