mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-10 12:28:25 +00:00
Make TokenInfo use a single 32-bit store for initialization. (#8054)
We need to zero-initialize the `token_payload_` bits in order for the normal creation to just be zeroing the whole structure. We do this only when MSan isn't enabled so we don't lose bit-accurate bug detection. Assisted-by: Antigravity with Gemini
This commit is contained in:
1 parent
07718a8329
commit
9192ee0032
1 file changed
+10
-5
@@ -162,14 +162,19 @@ class TokenInfo {
|
||||
//
|
||||
// Only used by the lexer which enforces only the correct kinds are used.
|
||||
//
|
||||
// When the payload is not being set, we leave it uninitialized. At least in
|
||||
// some cases, this will allow MSan to correctly detect erroneous attempts
|
||||
// to access the payload, as it works to track uninitialized memory
|
||||
// bit-for-bit specifically to handle complex cases like bitfields.
|
||||
// Under MSan, leave `token_payload_` uninitialized so bit-level tracking can
|
||||
// detect erroneous attempts to access a missing payload. In non-MSan builds,
|
||||
// zero-initialize it so constructing a payloadless `TokenInfo` compiles to a
|
||||
// plain 32-bit store rather than a read-modify-write preserving uninitialized
|
||||
// upper bits (which SROA otherwise promotes to loop-carried registers).
|
||||
TokenInfo(TokenKind kind, bool has_leading_space, int32_t byte_offset)
|
||||
: kind_(kind),
|
||||
has_leading_space_(has_leading_space),
|
||||
byte_offset_(byte_offset) {}
|
||||
#if !__has_feature(memory_sanitizer)
|
||||
token_payload_(0),
|
||||
#endif
|
||||
byte_offset_(byte_offset) {
|
||||
}
|
||||
|
||||
// Constructor for a TokenKind that carries a payload.
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user