This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Handle null pointers of type std::nullptr_t
ClosedPublic

Authored by li.zhe.hua on Jul 4 2022, 1:48 PM.

Details

Summary

Treat std::nullptr_t as a regular scalar type to avoid tripping
assertions when analyzing code that uses std::nullptr_t.

Diff Detail

Event Timeline

li.zhe.hua created this revision.Jul 4 2022, 1:48 PM
Herald added a project: Restricted Project. · View Herald Transcript
li.zhe.hua requested review of this revision.Jul 4 2022, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 4 2022, 1:48 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 accepted this revision.Jul 5 2022, 5:47 AM
gribozavr2 added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
61

Could you add a comment to the header that a caller may pass a null PointeeType as a "pointee" of a nullptr_t?

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
2216–2226
This revision is now accepted and ready to land.Jul 5 2022, 5:47 AM
li.zhe.hua updated this revision to Diff 442291.Jul 5 2022, 6:48 AM
li.zhe.hua marked 2 inline comments as done.

Address comments.

This revision was landed with ongoing or failed builds.Jul 5 2022, 6:51 AM
This revision was automatically updated to reflect the committed changes.
sgatev added a subscriber: sgatev.Aug 2 2022, 1:34 PM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
96

This is inconsistent with the change introduced by this patch.

clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
27–28

What does that mean? We are analyzing an incomplete translation unit? Why would the type ever be null here?

li.zhe.hua marked an inline comment as done.Aug 3 2022, 9:57 AM
li.zhe.hua added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
96

Ah, you're correct. I can mail a fix out later today.

clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
27–28

See the motivating test case:

// Alternatively, use `std::nullptr_t` instead of `my_nullptr_t`.
using my_nullptr_t = decltype(nullptr);
my_nullptr_t Null = 0;

This triggers getOrCreateNullPointerValue to be called with a null pointee type.