The branches protecting the static initializers have a DeclStmt as last Stmt. Since it is not an expression that will trigger an assertion failure in CFGBlock::getLastCondition.
This is triggered by the lifetime analysis that is currently in a fork. I am not sure what would be the best way to test this change here.
Details
Diff Detail
Event Timeline
clang/lib/Analysis/CFG.cpp | ||
---|---|---|
5923 | What about the following?: if (const auto *E = dyn_cast<Expr>(StmtElem->getStmt())) return E->IgnoreParens(); return nullptr; |
I am not sure what would be the best way to test this change here.
I'll admit, I'm a bit out of touch with Clang and will unfortunately be for a while, but the short answer is that the unit tests we have for the CFG are kinda bad. The constructed CFG has a longer lifetime than the AST its based on (see: D63538), so we would need to rewrite the BuildCFG() function that creates it. I have some memories digging into it but always got distracted :)
Until then, could you please include the crash you mentioned through a regular lit test?
clang/lib/Analysis/CFG.cpp | ||
---|---|---|
5925–5926 | I guess its time to update and/or move this comment a few lines up, maybe even add a descriptive assert. |
Wait, i didn't real @Szelethus's reply :)
In any case, i'd love to see an example of such CFG and whether control dependency tracking can expose the crash.
I decided to fix the unittests. Having CFGs full of dangling pointers to the AST does not look fun at all, so I think this change was long overdue.
Woohoo tests!~~
clang/unittests/Analysis/CFGBuildResult.h | ||
---|---|---|
69 | It should be slightly more visually appealing to construct the AST before the callback and pass it into the constructor of the callback. |
What about the following?: