This is quite useful for IDE's or other tools which would like to recover as
much as possible even if there are a few errors in the code, and discarding
the full 'if' bodies is unfortunate.
Details
Diff Detail
Event Timeline
Is there still an error reported for the invalid condition?
Anyhow, from my POV this is excellent and should fix a bunch of issues I've seen when using clang-c in KDevelop. I never got around to investigating it, but it always was related to conditionals. I'm pretty sure this patch fixes it then.
@ogoffart: For Manuel to see the difference, could you share the before/after screenshots of your code browser? That makes the impact of this patch pretty clear.
lib/Sema/SemaStmt.cpp | ||
---|---|---|
508–509 | This will create an IfStmt with no ConditionExpr. That is not a valid AST construct, and it's not reasonable to expect all the downstream consumers of the AST to be able to cope with it. It's not hard to find parts of the codebase that will crash when presented with this: lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp:1133 lib/Analysis/Consumed.cpp:1265 lib/Sema/AnalysisBasedWarnings.cpp:740 ... and so on. As the comment above suggests, you could create some sort of placeholder expression node here instead (either use something like an OpaqueValueExpr, or add a new Expr subclass to represent an erroneous expression -- the latter would probably be useful in many cases where we hit parse errors but can still produce some useful information to tools). |
Are the analysis run if there is an error? I think the consumer should expect null condition anyway.
But i'll try to add an ErrorExpr anyway.
lib/Sema/SemaStmt.cpp | ||
---|---|---|
505–506 | Please add a comment here saying that we're creating this node for error recovery. Also, the type of the expression should be BoolTy, not VoidTy. Other than that, this looks fine to me. |
commited as r249982. (I forgot to add the link to reviews.llvm.org in the commit message. I'll do it next time)
Please add a comment here saying that we're creating this node for error recovery. Also, the type of the expression should be BoolTy, not VoidTy. Other than that, this looks fine to me.