Re: [Mesa-dev] [PATCH] mesa: fix MSVC bitshift overflow warnings
Am 30.03.2018 um 17:09 schrieb Brian Paul: > In the BITFIELD_MASK() macro, if b==32 the expression evaluates to > ~0u, but the compiler still sees the expression (1 << 32) in the > unused part and issues a warning about integer bitshift overflow. > > Fix that by using (b) % 32 to ensure the max shift is 31 bits. > > This issue has been present for a while, but shows up much more > often because of the recent VBO changes. > --- > src/mesa/main/mtypes.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h > index 801bd17..b7a7b34 100644 > --- a/src/mesa/main/mtypes.h > +++ b/src/mesa/main/mtypes.h > @@ -59,7 +59,7 @@ extern "C" { > #define BITFIELD_BIT(b) ((GLbitfield)1 << (b)) > /** Set all bits up to excluding bit b */ > #define BITFIELD_MASK(b) \ > - ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT(b) - 1) > + ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT((b) % 32) - 1) > /** Set count bits starting from bit b */ > #define BITFIELD_RANGE(b, count) \ > (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b)) > Looks reasonable to me. Reviewed-by: Roland Scheidegger___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] mesa: fix MSVC bitshift overflow warnings
On Friday, 30 March 2018 17:09:40 CEST Brian Paul wrote: > In the BITFIELD_MASK() macro, if b==32 the expression evaluates to > ~0u, but the compiler still sees the expression (1 << 32) in the > unused part and issues a warning about integer bitshift overflow. > > Fix that by using (b) % 32 to ensure the max shift is 31 bits. > > This issue has been present for a while, but shows up much more > often because of the recent VBO changes. > --- > src/mesa/main/mtypes.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h > index 801bd17..b7a7b34 100644 > --- a/src/mesa/main/mtypes.h > +++ b/src/mesa/main/mtypes.h > @@ -59,7 +59,7 @@ extern "C" { > #define BITFIELD_BIT(b) ((GLbitfield)1 << (b)) > /** Set all bits up to excluding bit b */ > #define BITFIELD_MASK(b) \ > - ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT(b) - 1) > + ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT((b) % 32) - 1) > /** Set count bits starting from bit b */ > #define BITFIELD_RANGE(b, count) \ > (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b)) > Definitely: Reviewed-by: Mathias Fröhlichbest Mathias ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] mesa: fix MSVC bitshift overflow warnings
In the BITFIELD_MASK() macro, if b==32 the expression evaluates to ~0u, but the compiler still sees the expression (1 << 32) in the unused part and issues a warning about integer bitshift overflow. Fix that by using (b) % 32 to ensure the max shift is 31 bits. This issue has been present for a while, but shows up much more often because of the recent VBO changes. --- src/mesa/main/mtypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 801bd17..b7a7b34 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -59,7 +59,7 @@ extern "C" { #define BITFIELD_BIT(b) ((GLbitfield)1 << (b)) /** Set all bits up to excluding bit b */ #define BITFIELD_MASK(b) \ - ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT(b) - 1) + ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT((b) % 32) - 1) /** Set count bits starting from bit b */ #define BITFIELD_RANGE(b, count) \ (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b)) -- 2.7.4 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev