This is an archive of the discontinued LLVM Phabricator instance.

[CLANG]Fix potential null pointer dereference bugs
ClosedPublic

Authored by Manna on Jun 15 2023, 7:56 AM.

Details

Summary

This patch uses castAs instead of getAs which will assert if the type doesn't match and adds nullptr check if needed.

Diff Detail

Event Timeline

Manna created this revision.Jun 15 2023, 7:56 AM
Herald added a project: Restricted Project. · View Herald Transcript
Manna requested review of this revision.Jun 15 2023, 7:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2023, 7:56 AM
Manna updated this revision to Diff 531766.Jun 15 2023, 8:21 AM

Fix build error

Manna updated this revision to Diff 531773.Jun 15 2023, 8:40 AM

Update patch

aaronpuchert added inline comments.
clang/lib/Analysis/ThreadSafety.cpp
505–509

Can't we just take I.getData() instead of doing a lookup? After all we're iterating over the same map.

Manna updated this revision to Diff 531976.Jun 15 2023, 8:50 PM
Manna retitled this revision from [NFC][CLANG] Fix potential null pointer dereference bugs to [CLANG]Fix potential null pointer dereference bugs.

Address review comment and update patch

Manna added inline comments.Jun 15 2023, 8:52 PM
clang/lib/Analysis/ThreadSafety.cpp
505–509

Thank you @aaronpuchert for review and comment.

Can't we just take I.getData() instead of doing a lookup? After all we're iterating over the same map.

Makes sense to me! I have updated patch

Manna set the repository for this revision to rG LLVM Github Monorepo.
aaron.ballman added inline comments.Jun 16 2023, 4:47 AM
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
3368

This is unnecessary, getCanonicalDecl() can never return a null pointer (it will return this, at the very least)

Manna updated this revision to Diff 532138.Jun 16 2023, 7:08 AM

Address review comment.

Manna marked an inline comment as done.Jun 16 2023, 7:09 AM
Manna added inline comments.
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
3368

Thank you @aaron.ballman for reviews! I agree with you. My previous analysis was wrong. I have removed this change.

Manna marked an inline comment as done.Jun 22 2023, 6:31 AM
This revision is now accepted and ready to land.Jun 22 2023, 6:32 AM

Thank you for reviews @aaron.ballman!

This revision was automatically updated to reflect the committed changes.