Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1f30bae authored by Colin Cross's avatar Colin Cross
Browse files

Fix anonymous struct and union warnings

gui/BufferItem.h and android/sensor.h uses anymous structs and nested
anonymous unions, which are GNU extensions.  sensor.h uses them as part
of its API, so disable the warnings in libgui, the only module that
tries to use it with -Weverything.  BufferItem.h only uses the unioned
fields inside libgui, remove the union and do the 64-bit to 32-bit
slicing manually so libvulkan doesn't need the warnings disabled.

Bug: 31752268
Test: m -j
Change-Id: I92d59b1202f4d6e5419edaa6d27b6e1c50ac0042
parent c72b9a3c
Loading
Loading
Loading
Loading
+2 −14
Original line number Diff line number Diff line
@@ -74,13 +74,7 @@ class BufferItem : public Flattenable<BufferItem> {
    // to set by queueBuffer each time this slot is queued. This value
    // is guaranteed to be monotonically increasing for each newly
    // acquired buffer.
    union {
    int64_t mTimestamp;
        struct {
            uint32_t mTimestampLo;
            uint32_t mTimestampHi;
        };
    };

    // mIsAutoTimestamp indicates whether mTimestamp was generated
    // automatically when the buffer was queued.
@@ -92,13 +86,7 @@ class BufferItem : public Flattenable<BufferItem> {
    android_dataspace mDataSpace;

    // mFrameNumber is the number of the queued frame for this slot.
    union {
    uint64_t mFrameNumber;
        struct {
            uint32_t mFrameNumberLo;
            uint32_t mFrameNumberHi;
        };
    };

    // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT).
    int mSlot;
+3 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ LOCAL_CPPFLAGS += -Wno-gnu-zero-variadic-macro-arguments
# Don't warn about struct padding
LOCAL_CPPFLAGS += -Wno-padded

# android/sensors.h uses nested anonymous unions and anonymous structs
LOCAL_CPPFLAGS += -Wno-nested-anon-types -Wno-gnu-anonymous-struct

LOCAL_CPPFLAGS += -DDEBUG_ONLY_CODE=$(if $(filter userdebug eng,$(TARGET_BUILD_VARIANT)),1,0)

LOCAL_SRC_FILES := \
+32 −12
Original line number Diff line number Diff line
@@ -23,6 +23,21 @@

namespace android {

template<typename T>
static inline constexpr uint32_t low32(const T n) {
    return static_cast<uint32_t>(static_cast<uint64_t>(n));
}

template<typename T>
static inline constexpr uint32_t high32(const T n) {
    return static_cast<uint32_t>(static_cast<uint64_t>(n)>>32);
}

template<typename T>
static inline constexpr T to64(const uint32_t lo, const uint32_t hi) {
    return static_cast<T>(static_cast<uint64_t>(hi)<<32 | lo);
}

BufferItem::BufferItem() :
    mGraphicBuffer(NULL),
    mFence(NULL),
@@ -56,12 +71,12 @@ size_t BufferItem::getPodSize() const {
    addAligned(size, mCrop);
    addAligned(size, mTransform);
    addAligned(size, mScalingMode);
    addAligned(size, mTimestampLo);
    addAligned(size, mTimestampHi);
    addAligned(size, low32(mTimestamp));
    addAligned(size, high32(mTimestamp));
    addAligned(size, mIsAutoTimestamp);
    addAligned(size, mDataSpace);
    addAligned(size, mFrameNumberLo);
    addAligned(size, mFrameNumberHi);
    addAligned(size, low32(mFrameNumber));
    addAligned(size, high32(mFrameNumber));
    addAligned(size, mSlot);
    addAligned(size, mIsDroppable);
    addAligned(size, mAcquireCalled);
@@ -141,12 +156,12 @@ status_t BufferItem::flatten(
    writeAligned(buffer, size, mCrop);
    writeAligned(buffer, size, mTransform);
    writeAligned(buffer, size, mScalingMode);
    writeAligned(buffer, size, mTimestampLo);
    writeAligned(buffer, size, mTimestampHi);
    writeAligned(buffer, size, low32(mTimestamp));
    writeAligned(buffer, size, high32(mTimestamp));
    writeAligned(buffer, size, mIsAutoTimestamp);
    writeAligned(buffer, size, mDataSpace);
    writeAligned(buffer, size, mFrameNumberLo);
    writeAligned(buffer, size, mFrameNumberHi);
    writeAligned(buffer, size, low32(mFrameNumber));
    writeAligned(buffer, size, high32(mFrameNumber));
    writeAligned(buffer, size, mSlot);
    writeAligned(buffer, size, mIsDroppable);
    writeAligned(buffer, size, mAcquireCalled);
@@ -194,15 +209,20 @@ status_t BufferItem::unflatten(
        return NO_MEMORY;
    }

    uint32_t timestampLo = 0, timestampHi = 0;
    uint32_t frameNumberLo = 0, frameNumberHi = 0;

    readAligned(buffer, size, mCrop);
    readAligned(buffer, size, mTransform);
    readAligned(buffer, size, mScalingMode);
    readAligned(buffer, size, mTimestampLo);
    readAligned(buffer, size, mTimestampHi);
    readAligned(buffer, size, timestampLo);
    readAligned(buffer, size, timestampHi);
    mTimestamp = to64<int64_t>(timestampLo, timestampHi);
    readAligned(buffer, size, mIsAutoTimestamp);
    readAligned(buffer, size, mDataSpace);
    readAligned(buffer, size, mFrameNumberLo);
    readAligned(buffer, size, mFrameNumberHi);
    readAligned(buffer, size, frameNumberLo);
    readAligned(buffer, size, frameNumberHi);
    mFrameNumber = to64<uint64_t>(frameNumberLo, frameNumberHi);
    readAligned(buffer, size, mSlot);
    readAligned(buffer, size, mIsDroppable);
    readAligned(buffer, size, mAcquireCalled);