[clang] Add Clang attribute to ensure that fields are initialized explicitly (PR #102040)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 11:35:15 PST 2024
================
@@ -5214,9 +5215,10 @@ unsigned RecordDecl::getODRHash() {
// Only calculate hash on first call of getODRHash per record.
ODRHash Hash;
Hash.AddRecordDecl(this);
- // For RecordDecl the ODRHash is stored in the remaining 26
- // bit of RecordDeclBits, adjust the hash to accomodate.
- setODRHash(Hash.CalculateHash() >> 6);
+ // For RecordDecl the ODRHash is stored in the remaining
+ // bits of RecordDeclBits, adjust the hash to accommodate.
+ static_assert(sizeof(Hash.CalculateHash()) * CHAR_BIT == 32);
+ setODRHash(Hash.CalculateHash() >> (32 - NumOdrHashBits));
----------------
AaronBallman wrote:
Does anyone have a good intuition for how much this increases the chances of ODR hash collisions? I know we're only stealing one bit, but those bits add up.
https://github.com/llvm/llvm-project/pull/102040
More information about the cfe-commits
mailing list