[PATCH] D153236: [NFC] Fix potential dereferencing of nullptr.

Sindhu Chittireddy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 21 13:55:48 PDT 2023


schittir added inline comments.


================
Comment at: clang/lib/Parse/ParseStmt.cpp:886-887
         TopLevelCase = Case;
-      else
+      else {
+        assert(DeepestParsedCaseStmt && "DeepestParsedCaseStmt cannot be null");
         Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
----------------
aaron.ballman wrote:
> The `assert` doesn't add much value, this seems to be a false positive in the analysis.
> 
> If we have no top-level case statement yet, then we get into the `if` branch on line 884, but that then sets `DeepestParsedCaseStmt` on line 890, and that must be non-null because we verified that `Case` is valid above on line 876. So by the time we get into the `else` branch, `DeepestParsedCaseStmt` must be nonnull.
> 
> I don't think changes are needed here at all; WDYT?
This makes sense. I didn't thoroughly consider the Case.isInvalid() check above in my analysis. Thank you for catching this! I removed this change. 


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

https://reviews.llvm.org/D153236



More information about the cfe-commits mailing list