Mesa (master): panfrost: Don't lose bits!

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Dec 12 15:41:56 UTC 2019


Module: Mesa
Branch: master
Commit: 99d4c71f7eb11293a402e31602e3da5b56fe1581
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=99d4c71f7eb11293a402e31602e3da5b56fe1581

Author: Tomeu Vizoso <tomeu.vizoso at collabora.com>
Date:   Thu Dec 12 14:49:57 2019 +0100

panfrost: Don't lose bits!

UBSAN complained that when alpha was 255 and we shifted it 24 positions
to the left, it didn't fit in a signed int. That's because bitwise
operations automatically promote to signed int.

../src/gallium/drivers/panfrost/pan_job.c:1130:64: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'"}
    #0 0xacf953d6 in pan_pack_color ../src/gallium/drivers/panfrost/pan_job.c:1130"}
    #1 0xacf953d6 in panfrost_batch_clear ../src/gallium/drivers/panfrost/pan_job.c:1204"}
    #2 0xaae3226a in st_Clear ../src/mesa/state_tracker/st_cb_clear.c:513"}
    #3 0x4c3d0e in deqp::gles2::TestCaseWrapper::iterate(tcu::TestCase*) (/deqp/modules/gles2/deqp-gles2+0x2ad0e)"}
    #4 0x828cf2 in tcu::TestSessionExecutor::iterateTestCase(tcu::TestCase*) (/deqp/modules/gles2/deqp-gles2+0x38fcf2)"}
    #5 0x8295f0 in tcu::TestSessionExecutor::iterate() (/deqp/modules/gles2/deqp-gles2+0x3905f0)"}
    #6 0x810aac in tcu::App::iterate() (/deqp/modules/gles2/deqp-gles2+0x377aac)"}
    #7 0x4c1d4c in main (/deqp/modules/gles2/deqp-gles2+0x28d4c)"}
    #8 0xb64b6aa8 in __libc_start_main (/lib/arm-linux-gnueabihf/libc.so.6+0x1aaa8)"}

Signed-off-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>

---

 src/gallium/drivers/panfrost/pan_job.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index 3116d294632..dbea56d2d6b 100644
--- a/src/gallium/drivers/panfrost/pan_job.c
+++ b/src/gallium/drivers/panfrost/pan_job.c
@@ -1134,10 +1134,10 @@ pan_pack_color(uint32_t *packed, const union pipe_color_union *color, enum pipe_
 
         if (util_format_is_rgba8_variant(desc)) {
                 pan_pack_color_32(packed,
-                                  (float_to_ubyte(clear_alpha) << 24) |
-                                  (float_to_ubyte(color->f[2]) << 16) |
-                                  (float_to_ubyte(color->f[1]) <<  8) |
-                                  (float_to_ubyte(color->f[0]) <<  0));
+                                  ((uint32_t) float_to_ubyte(clear_alpha) << 24) |
+                                  ((uint32_t) float_to_ubyte(color->f[2]) << 16) |
+                                  ((uint32_t) float_to_ubyte(color->f[1]) <<  8) |
+                                  ((uint32_t) float_to_ubyte(color->f[0]) <<  0));
         } else if (format == PIPE_FORMAT_B5G6R5_UNORM) {
                 /* First, we convert the components to R5, G6, B5 separately */
                 unsigned r5 = CLAMP(color->f[0], 0.0, 1.0) * 31.0;




More information about the mesa-commit mailing list