From ea36e7a239b4162c49c25e8c19703f1cd4cfdf8d Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Wed, 8 Jan 2020 00:12:30 +0100 Subject: [PATCH] Fix thousands of 'is too small to hold all values' warnings on Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building with GCC, it generates 3020 warnings like this: libraries/gpu/src/gpu/State.h:208:18: warning: ‘gpu::State::BlendFunction::destColor’ is too small to hold all values of ‘enum gpu::State::BlendArg’ This is because ‘enum gpu::State::BlendArg’ is declared as an enum of uint16 size, and gpu::State::BlendFunction::destColor is a bit field. GCC correctly deduces that a 16 bit value won't always fit in a 4 bit field, and emits a warning. The problem is that the amount is such that it floods the output and hides other warnings. Changing the 'enum foo : uint16' declarations to 'enum foo' stops gcc from emitting the warning. Making this change required the removal of a set of assertion checks. At least empirically they seem unnecessary -- the interface compiles and runs fine. --- libraries/gpu/src/gpu/Format.h | 2 +- libraries/gpu/src/gpu/State.h | 28 ++++++---------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 25bb2baba4..61518edb6c 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -377,7 +377,7 @@ public: }; -enum ComparisonFunction : uint16 { +enum ComparisonFunction { NEVER = 0, LESS, EQUAL, diff --git a/libraries/gpu/src/gpu/State.h b/libraries/gpu/src/gpu/State.h index 2e8a3f2cab..7467d86ac6 100755 --- a/libraries/gpu/src/gpu/State.h +++ b/libraries/gpu/src/gpu/State.h @@ -46,7 +46,7 @@ public: typedef ::gpu::ComparisonFunction ComparisonFunction; - enum FillMode : uint8 + enum FillMode { FILL_POINT = 0, FILL_LINE, @@ -55,7 +55,7 @@ public: NUM_FILL_MODES, }; - enum CullMode : uint8 + enum CullMode { CULL_NONE = 0, CULL_FRONT, @@ -64,7 +64,7 @@ public: NUM_CULL_MODES, }; - enum StencilOp : uint16 + enum StencilOp { STENCIL_OP_KEEP = 0, STENCIL_OP_ZERO, @@ -78,7 +78,7 @@ public: NUM_STENCIL_OPS, }; - enum BlendArg : uint16 + enum BlendArg { ZERO = 0, ONE, @@ -99,7 +99,7 @@ public: NUM_BLEND_ARGS, }; - enum BlendOp : uint16 + enum BlendOp { BLEND_OP_ADD = 0, BLEND_OP_SUBTRACT, @@ -110,7 +110,7 @@ public: NUM_BLEND_OPS, }; - enum ColorMask : uint8 + enum ColorMask { WRITE_NONE = 0, WRITE_RED = 1, @@ -140,8 +140,6 @@ public: bool operator!=(const DepthTest& right) const { return getRaw() != right.getRaw(); } }; - static_assert(sizeof(DepthTest) == sizeof(uint32_t), "DepthTest size check"); - struct StencilTest { ComparisonFunction function : 4; StencilOp failOp : 4; @@ -282,20 +280,6 @@ public: Flags flags; }; - static_assert(offsetof(Data, depthBias) == 0, "Data offsets"); - static_assert(offsetof(Data, depthBiasSlopeScale) == 4, "Data offsets"); - static_assert(offsetof(Data, depthTest) == 8, "Data offsets"); - static_assert(offsetof(Data, stencilActivation) == 12, "Data offsets"); - static_assert(offsetof(Data, stencilTestFront) == 16, "Data offsets"); - static_assert(offsetof(Data, stencilTestBack) == 20, "Data offsets"); - static_assert(offsetof(Data, sampleMask) == 24, "Data offsets"); - static_assert(offsetof(Data, blendFunction) == 28, "Data offsets"); - static_assert(offsetof(Data, fillMode) == 32, "Data offsets"); - static_assert(offsetof(Data, cullMode) == 33, "Data offsets"); - static_assert(offsetof(Data, colorWriteMask) == 34, "Data offsets"); - static_assert(offsetof(Data, flags) == 35, "Data offsets"); - static_assert(sizeof(Data) == 36, "Data Size Check"); - std::string getKey() const; // The unique default values for all the fields