Skip to content

Commit

Permalink
Clean up -Wbitfield-conversion warnings
Browse files Browse the repository at this point in the history
Clang has recently introduced a new warning -Wbitfield-conversion which
warns when a conversion from an integral type to a bit-field may change
the value. To suppress this warning, we use a bitmask to ensure that the
value is within the specified range.

Change-Id: Ie771475e17e37d73256532decde15445752a0e3d
  • Loading branch information
petrhosek committed Oct 25, 2023
1 parent 1352131 commit 45d008f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/perfetto/ext/tracing/core/shared_memory_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class SharedMemoryABI {
ChunkHeader* chunk_header = header();
auto packets = chunk_header->packets.load(std::memory_order_relaxed);
if (packets.count < packet_count)
packets.count = packet_count;
packets.count = packet_count & ChunkHeader::Packets::kMaxCount;
chunk_header->packets.store(packets, std::memory_order_release);
return packets.count;
}
Expand Down
2 changes: 1 addition & 1 deletion include/perfetto/protozero/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Field {
uint8_t type,
uint64_t int_value,
uint32_t size) {
id_ = id;
id_ = id & kMaxId;
type_ = type;
int_value_ = int_value;
size_ = size;
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/core/trace_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void TraceBuffer::CopyChunkUntrusted(ProducerID producer_id_trusted,
record.chunk_id = chunk_id;
record.writer_id = writer_id;
record.num_fragments = num_fragments;
record.flags = chunk_flags;
record.flags = chunk_flags & ChunkRecord::kFlagsBitMask;
ChunkMeta::Key key(record);

// Check whether we have already copied the same chunk previously. This may
Expand Down Expand Up @@ -452,7 +452,7 @@ bool TraceBuffer::TryPatchChunkContents(ProducerID producer_id,
stats_.set_patches_succeeded(stats_.patches_succeeded() + patches_size);
if (!other_patches_pending) {
chunk_meta.flags &= ~kChunkNeedsPatching;
chunk_record->flags = chunk_meta.flags;
chunk_record->flags = chunk_meta.flags & ChunkRecord::kFlagsBitMask;
}
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/tracing/core/trace_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ class TraceBuffer {
uint16_t size;

uint8_t flags : 6; // See SharedMemoryABI::ChunkHeader::flags.
static constexpr size_t kFlagsBitMask = (1 << 6) - 1;

uint8_t is_padding : 1;
uint8_t unused_flag : 1;

Expand Down

0 comments on commit 45d008f

Please sign in to comment.