[Mesa-dev] [PATCH 6/9] gallium: fix various undefined left shifts into sign bit

Nicolai Hähnle nhaehnle at gmail.com
Sat Apr 30 07:24:34 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Funnily enough, some of these were turned into a compile-time error by gcc
with -fsanitize=undefined ("initializer is not a constant").
---
 src/gallium/auxiliary/tgsi/tgsi_ureg.c         | 2 +-
 src/gallium/auxiliary/util/u_pack_color.h      | 2 +-
 src/gallium/auxiliary/util/u_pstipple.c        | 2 +-
 src/gallium/drivers/softpipe/sp_quad_stipple.c | 4 ++--
 src/mesa/state_tracker/st_mesa_to_tgsi.c       | 2 +-
 src/mesa/state_tracker/st_program.c            | 4 ++--
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 021b81f..43b8bb1 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -1735,7 +1735,7 @@ static void emit_decls( struct ureg_program *ureg )
 
    if (ureg->processor == PIPE_SHADER_VERTEX) {
       for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
-         if (ureg->vs_inputs[i/32] & (1 << (i%32))) {
+         if (ureg->vs_inputs[i/32] & (1u << (i%32))) {
             emit_decl_range( ureg, TGSI_FILE_INPUT, i, 1 );
          }
       }
diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h
index b882502..f9f4160 100644
--- a/src/gallium/auxiliary/util/u_pack_color.h
+++ b/src/gallium/auxiliary/util/u_pack_color.h
@@ -367,7 +367,7 @@ util_pack_color(const float rgba[4], enum pipe_format format, union util_color *
       return;
    case PIPE_FORMAT_BGRX8888_UNORM:
       {
-         uc->ui[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
+         uc->ui[0] = (0xffu << 24) | (r << 16) | (g << 8) | b;
       }
       return;
    case PIPE_FORMAT_ARGB8888_UNORM:
diff --git a/src/gallium/auxiliary/util/u_pstipple.c b/src/gallium/auxiliary/util/u_pstipple.c
index 3ae8923..f6ea535 100644
--- a/src/gallium/auxiliary/util/u_pstipple.c
+++ b/src/gallium/auxiliary/util/u_pstipple.c
@@ -63,7 +63,7 @@ util_pstipple_update_stipple_texture(struct pipe_context *pipe,
                                      struct pipe_resource *tex,
                                      const uint32_t pattern[32])
 {
-   static const uint bit31 = 1 << 31;
+   static const uint bit31 = 1u << 31;
    struct pipe_transfer *transfer;
    ubyte *data;
    int i, j;
diff --git a/src/gallium/drivers/softpipe/sp_quad_stipple.c b/src/gallium/drivers/softpipe/sp_quad_stipple.c
index a0527a5..4b29c2e 100644
--- a/src/gallium/drivers/softpipe/sp_quad_stipple.c
+++ b/src/gallium/drivers/softpipe/sp_quad_stipple.c
@@ -16,8 +16,8 @@
 static void
 stipple_quad(struct quad_stage *qs, struct quad_header *quads[], unsigned nr)
 {
-   static const uint bit31 = 1 << 31;
-   static const uint bit30 = 1 << 30;
+   static const uint bit31 = 1u << 31;
+   static const uint bit30 = 1u << 30;
    unsigned pass = nr;
 
    struct softpipe_context *softpipe = qs->softpipe;
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index d73a4b3..c89d003 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -1159,7 +1159,7 @@ st_translate_mesa_program(
 
    /* texture samplers */
    for (i = 0; i < ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; i++) {
-      if (program->SamplersUsed & (1 << i)) {
+      if (program->SamplersUsed & (1u << i)) {
          unsigned target =
             translate_texture_index(program->TexturesUsed[i],
                                     !!(program->ShadowSamplers & (1 << i)));
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 32ada9f..444e5aa 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1121,7 +1121,7 @@ st_translate_program_common(struct st_context *st,
 
    /* Also add patch inputs. */
    for (attr = 0; attr < 32; attr++) {
-      if (prog->PatchInputsRead & (1 << attr)) {
+      if (prog->PatchInputsRead & (1u << attr)) {
          GLuint slot = num_inputs++;
          GLuint patch_attr = VARYING_SLOT_PATCH0 + attr;
 
@@ -1240,7 +1240,7 @@ st_translate_program_common(struct st_context *st,
 
    /* Also add patch outputs. */
    for (attr = 0; attr < 32; attr++) {
-      if (prog->PatchOutputsWritten & (1 << attr)) {
+      if (prog->PatchOutputsWritten & (1u << attr)) {
          GLuint slot = num_outputs++;
          GLuint patch_attr = VARYING_SLOT_PATCH0 + attr;
 
-- 
2.7.4



More information about the mesa-dev mailing list