This is an archive of the discontinued LLVM Phabricator instance.

[Clang[NFC] Fix bitmask for NullabilityPayload in Types.h
ClosedPublic

Authored by xgupta on Jan 23 2023, 1:44 AM.

Details

Summary

The code is using the bit mask NullabilityKindMask which is 0x3
(00000011 in binary) to clear the bits in the NullabilityPayload variable.
Since NullabilityPayload is a 64-bit variable and NullabilityKindMask is
only a 8-bit variable(0x3), it will only affect the last 8 bits of the
variable. The higher 56 bits will remain unchanged.

Found by PVS-Studio - https://pvs-studio.com/en/blog/posts/cpp/1003/, N37.

Diff Detail

Event Timeline

xgupta created this revision.Jan 23 2023, 1:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 1:44 AM
xgupta requested review of this revision.Jan 23 2023, 1:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 1:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Jan 23 2023, 4:44 AM
clang/include/clang/APINotes/Types.h
535

I think a cleaner way to solve this is to make NullabilityKindMask be 64-bits. None of the other operations need this change, but it seems like it will be a bit more future-proof that way. WDYT?

xgupta updated this revision to Diff 491312.Jan 23 2023, 4:54 AM

address comments

xgupta marked an inline comment as done.Jan 23 2023, 4:55 AM
xgupta added inline comments.
clang/include/clang/APINotes/Types.h
535

Yeah, I do agree. Thanks for the suggestion.

xgupta edited the summary of this revision. (Show Details)Jan 23 2023, 4:56 AM
This revision is now accepted and ready to land.Jan 23 2023, 6:43 AM
This revision was landed with ongoing or failed builds.Jan 23 2023, 6:48 AM
This revision was automatically updated to reflect the committed changes.
xgupta marked an inline comment as done.