[PATCH] D142334: [Clang[NFC] Fix bitmask for NullabilityPayload in Types.h

Shivam Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 23 01:44:13 PST 2023


xgupta created this revision.
xgupta added reviewers: aaron.ballman, usaxena95.
Herald added a project: All.
xgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

The code you 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142334

Files:
  clang/include/clang/APINotes/Types.h


Index: clang/include/clang/APINotes/Types.h
===================================================================
--- clang/include/clang/APINotes/Types.h
+++ clang/include/clang/APINotes/Types.h
@@ -532,7 +532,7 @@
 
     // Mask the bits.
     NullabilityPayload &=
-        ~(NullabilityKindMask << (index * NullabilityKindSize));
+        ~(static_cast<uint64_t>NullabilityKindMask << (index * NullabilityKindSize));
 
     // Set the value.
     unsigned kindValue = (static_cast<unsigned>(kind))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142334.491261.patch
Type: text/x-patch
Size: 500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230123/f76fb6c8/attachment.bin>


More information about the cfe-commits mailing list