This is an archive of the discontinued LLVM Phabricator instance.

[NFC][Clang] Fix static analyzer concern about null value dereference
ClosedPublic

Authored by eandrews on Aug 14 2023, 8:38 AM.

Diff Detail

Event Timeline

eandrews created this revision.Aug 14 2023, 8:38 AM
Herald added a project: Restricted Project. · View Herald Transcript
eandrews requested review of this revision.Aug 14 2023, 8:38 AM
tahonermann accepted this revision.Aug 14 2023, 8:50 AM

Looks good to me!

This revision is now accepted and ready to land.Aug 14 2023, 8:50 AM

Hmm. I guess the assertion is to silence some tool. And I think actually that function might very well also return null in some cases.
Why do you think it cannot or at least should not return null in your context? I couldn't infer this from the context, neither from the description of this patch.

Without that, I would prefer an if to guard the code, instead of asserting this.

clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
657

I think there is a typo in the word statement.

If getStmtForDiagnostics() in general, never returns null, then shouldn't we mark the API with an appropriate attribute?

Hmm. I guess the assertion is to silence some tool. And I think actually that function might very well also return null in some cases.
Why do you think it cannot or at least should not return null in your context? I couldn't infer this from the context, neither from the description of this patch.

Without that, I would prefer an if to guard the code, instead of asserting this.

createBegin() has a call to getValidSourceLocation() which dereferences this Statement. So in this context Statement cannot be null.

If getStmtForDiagnostics() in general, never returns null, then shouldn't we mark the API with an appropriate attribute?

getStmtForDiagnostics() explicitly returns nullptr when none of the cases for ProgramPoint listed in the function are met. So I am not sure if we can just assume this function should never return null.

steakhal accepted this revision.Aug 15 2023, 11:15 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2023, 2:10 PM
eandrews added inline comments.Aug 16 2023, 2:10 PM
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
657

Thanks for the review. I corrected this in the commit.