1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 06:52:44 +01:00
RIOT/pkg/flatbuffers/patches/0001-Silence-Wcast-align-in-public-headers.patch

132 lines
5.6 KiB
Diff
Raw Normal View History

From 89ecddee041efc5065b6ec015ac273dff5231b57 Mon Sep 17 00:00:00 2001
From: Kasper Hjort Berthelsen <khjo@itu.dk>
Date: Tue, 21 May 2024 15:07:30 +0200
2022-04-08 09:14:17 +02:00
Subject: [PATCH 1/1] Silence Wcast-align in public headers
2021-11-12 19:26:30 +01:00
---
include/flatbuffers/buffer.h | 3 +++
include/flatbuffers/flatbuffer_builder.h | 12 ++++++++++++
include/flatbuffers/table.h | 6 ++++++
include/flatbuffers/vector_downward.h | 6 ++++++
4 files changed, 27 insertions(+)
2021-11-12 19:26:30 +01:00
diff --git a/include/flatbuffers/buffer.h b/include/flatbuffers/buffer.h
index 94d4f790..4f163f6e 100644
--- a/include/flatbuffers/buffer.h
+++ b/include/flatbuffers/buffer.h
@@ -119,9 +119,12 @@ struct IndirectHelper<OffsetT<T>> {
2021-11-12 19:26:30 +01:00
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
// then determine the relative location from the offset location.
2021-11-12 19:26:30 +01:00
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
return reinterpret_cast<return_type>(
offset_location + ReadScalar<offset_type>(offset_location));
2021-11-12 19:26:30 +01:00
}
2022-04-08 09:14:17 +02:00
+#pragma GCC diagnostic pop
static mutable_return_type Read(uint8_t *const p, const offset_type i) {
// Offsets are relative to themselves, so first update the pointer to
// point to the offset location.
diff --git a/include/flatbuffers/flatbuffer_builder.h b/include/flatbuffers/flatbuffer_builder.h
index 9a2d6254..4ea23b88 100644
--- a/include/flatbuffers/flatbuffer_builder.h
+++ b/include/flatbuffers/flatbuffer_builder.h
@@ -54,7 +54,10 @@ const T *data(const std::vector<T, Alloc> &v) {
2022-04-08 09:14:17 +02:00
// Eventually the returned pointer gets passed down to memcpy, so
// we need it to be non-null to avoid undefined behavior.
static uint8_t t;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
return v.empty() ? reinterpret_cast<const T *>(&t) : &v.front();
2022-04-08 09:14:17 +02:00
+#pragma GCC diagnostic pop
}
template<typename T, typename Alloc = std::allocator<T>>
T *data(std::vector<T, Alloc> &v) {
@@ -440,7 +443,10 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
2021-11-12 19:26:30 +01:00
// Write the offsets into the table
for (auto it = buf_.scratch_end() - num_field_loc * sizeof(FieldLoc);
it < buf_.scratch_end(); it += sizeof(FieldLoc)) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
auto field_location = reinterpret_cast<FieldLoc *>(it);
+#pragma GCC diagnostic pop
const voffset_t pos =
static_cast<voffset_t>(vtable_offset_loc - field_location->off);
2021-11-12 19:26:30 +01:00
// If this asserts, it means you've set a field twice.
@@ -449,7 +455,10 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
2021-11-12 19:26:30 +01:00
WriteScalar<voffset_t>(buf_.data() + field_location->id, pos);
}
ClearOffsets();
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
auto vt1 = reinterpret_cast<voffset_t *>(buf_.data());
+#pragma GCC diagnostic pop
auto vt1_size = ReadScalar<voffset_t>(vt1);
auto vt_use = GetSizeRelative32BitRegion();
2021-11-12 19:26:30 +01:00
// See if we already have generated a vtable with this exact same
@@ -457,8 +466,11 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
2021-11-12 19:26:30 +01:00
if (dedup_vtables_) {
for (auto it = buf_.scratch_data(); it < buf_.scratch_end();
it += sizeof(uoffset_t)) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
auto vt_offset_ptr = reinterpret_cast<uoffset_t *>(it);
auto vt2 = reinterpret_cast<voffset_t *>(buf_.data_at(*vt_offset_ptr));
+#pragma GCC diagnostic pop
2022-04-08 09:14:17 +02:00
auto vt2_size = ReadScalar<voffset_t>(vt2);
2021-11-12 19:26:30 +01:00
if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue;
vt_use = *vt_offset_ptr;
diff --git a/include/flatbuffers/table.h b/include/flatbuffers/table.h
index e92d8ae8..c2400a3b 100644
--- a/include/flatbuffers/table.h
+++ b/include/flatbuffers/table.h
@@ -51,8 +51,11 @@ class Table {
P GetPointer(voffset_t field) {
2021-11-12 19:26:30 +01:00
auto field_offset = GetOptionalFieldOffset(field);
auto p = data_ + field_offset;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
return field_offset ? reinterpret_cast<P>(p + ReadScalar<OffsetSize>(p))
2021-11-12 19:26:30 +01:00
: nullptr;
+#pragma GCC diagnostic pop
}
template<typename P, typename OffsetSize = uoffset_t>
P GetPointer(voffset_t field) const {
@@ -70,7 +73,10 @@ class Table {
2021-11-12 19:26:30 +01:00
template<typename P> P GetStruct(voffset_t field) const {
auto field_offset = GetOptionalFieldOffset(field);
auto p = const_cast<uint8_t *>(data_ + field_offset);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
return field_offset ? reinterpret_cast<P>(p) : nullptr;
+#pragma GCC diagnostic pop
}
2022-04-08 09:14:17 +02:00
template<typename Raw, typename Face>
diff --git a/include/flatbuffers/vector_downward.h b/include/flatbuffers/vector_downward.h
index 2b5a92cf..dd869444 100644
--- a/include/flatbuffers/vector_downward.h
+++ b/include/flatbuffers/vector_downward.h
@@ -199,12 +199,18 @@ template<typename SizeT = uoffset_t> class vector_downward {
// Specialized version of push() that avoids memcpy call for small data.
template<typename T> void push_small(const T &little_endian_t) {
make_space(sizeof(T));
2022-04-08 09:14:17 +02:00
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
*reinterpret_cast<T *>(cur_) = little_endian_t;
2022-04-08 09:14:17 +02:00
+#pragma GCC diagnostic pop
}
template<typename T> void scratch_push_small(const T &t) {
ensure_space(sizeof(T));
2022-04-08 09:14:17 +02:00
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
*reinterpret_cast<T *>(scratch_) = t;
2022-04-08 09:14:17 +02:00
+#pragma GCC diagnostic pop
scratch_ += sizeof(T);
}
2021-11-12 19:26:30 +01:00
--
2.34.1
2021-11-12 19:26:30 +01:00