This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Avoid potential dereferencing of nullptr.
ClosedPublic

Authored by schittir on Jul 25 2023, 4:23 PM.

Diff Detail

Event Timeline

schittir created this revision.Jul 25 2023, 4:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 4:23 PM
schittir requested review of this revision.Jul 25 2023, 4:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 4:23 PM
aaron.ballman added inline comments.
clang/lib/AST/ItaniumMangle.cpp
1659

This seems incorrect -- if the declaration name is a destructor, then ND should always be null, right?

clang/lib/CodeGen/CGObjCMac.cpp
1806 ↗(On Diff #544140)

Hmmm, is assert the correct approach here? It seems to me that a Complex rvalue will trigger this assertion. I think this deserves some additional thinking rather than silencing the static analysis warning. CC @efriedma @rjmccall who might have ideas.

efriedma added inline comments.Jul 26 2023, 11:31 AM
clang/lib/AST/ItaniumMangle.cpp
1659

Seems okay to me? ND is the destructor declaration.

clang/lib/CodeGen/CGObjCMac.cpp
1806 ↗(On Diff #544140)

Yes, if a complex value hit this codepath with a null contBB, it would just crash, so the analysis is flagging a real issue.

I'm not sure how to write ObjC code to actually trigger this codepath, though. Probably involves a _Complex _BitInt(128) or something like that.

aaron.ballman added inline comments.Jul 26 2023, 11:34 AM
clang/lib/AST/ItaniumMangle.cpp
1659

Yeah, you're correct -- I was thinking CXXDestructorDecl was not a NamedDecl, but it's a CXXMethodDecl without a name, so this is fine.

Thank you for the review, @aaron.ballman and @efriedma
Do you recommend any changes here?

Thank you for the review, @aaron.ballman and @efriedma
Do you recommend any changes here?

The changes to SemaCodeComplete.cpp and ItaniumMangle.cpp are good, the changes in CGObjCMac.cpp require some more work because the static analysis tool found a real bug and we should fix the bug rather than assert it won't be hit. I'd recommend landing the good changes now (they're NFC) and start a new review for the codegen changes.

schittir updated this revision to Diff 545410.Jul 30 2023, 12:00 AM

Remove changes in CGObjCMac.cpp

aaron.ballman accepted this revision.Jul 30 2023, 5:37 AM

LGTM! Are you planning to work on the ObjC issues separately? (Not suggesting you have to! But if you don't intend to, can you file an issue in GitHub so we don't lose track of the problem?)

This revision is now accepted and ready to land.Jul 30 2023, 5:37 AM

Test failure seems unrelated to change. Driver/fsanitize.c lit test passes in my local testing. Restarting build.

LGTM! Are you planning to work on the ObjC issues separately? (Not suggesting you have to! But if you don't intend to, can you file an issue in GitHub so we don't lose track of the problem?)

Hi Aaron,
I will make sure to file a bug report.
Thank you!

Test failure seems unrelated to change. Driver/fsanitize.c lit test passes in my local testing. Restarting build.

The build is now green. Landing the patch.

This revision was automatically updated to reflect the committed changes.