This is an archive of the discontinued LLVM Phabricator instance.

[clang][analyzer][NFC] Replace dyn_cast with cast in MemRegion::getMemorySpace
ClosedPublic

Authored by gribozavr on May 30 2023, 8:47 AM.

Details

Summary

MemRegion::getMemorySpace() is annotated with
LLVM_ATTRIBUTE_RETURNS_NONNULL (which triggers instant UB if a null
pointer is returned), and callers indeed don't check the return value
for null. Thus, even though llvm::dyn_cast is called, it can never
return null in this context. Therefore, we can safely call llvm::cast.

Diff Detail

Event Timeline

gribozavr created this revision.May 30 2023, 8:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 8:47 AM
gribozavr requested review of this revision.May 30 2023, 8:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2023, 8:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steakhal accepted this revision.May 30 2023, 8:52 AM

Correct.

This revision is now accepted and ready to land.May 30 2023, 8:52 AM
gribozavr2 retitled this revision from [clang] Replace dyn_cast with cast in MemRegion::getMemorySpace to [clang][analyzer][NFC] Replace dyn_cast with cast in MemRegion::getMemorySpace.May 30 2023, 9:01 AM
This revision was landed with ongoing or failed builds.May 30 2023, 9:30 AM
This revision was automatically updated to reflect the committed changes.