gallium/util: Cast to target type before shifting left
authorMichel Dänzer <mdaenzer@redhat.com>
Wed, 25 Sep 2019 09:37:49 +0000 (11:37 +0200)
committerMichel Dänzer <michel@daenzer.net>
Thu, 24 Oct 2019 14:20:31 +0000 (16:20 +0200)
commit65e376a7218ca05e89baca8a845ece9abf54735e
treeba6e7f2e915f5f637c0cb07b1310efb6da14bdaf
parent2b1b56cb3ae9672ad56930a10ea61f91905bc958
gallium/util: Cast to target type before shifting left

Otherwise a smaller type may be promoted to int, which can hit undefined
behaviour:

../src/gallium/auxiliary/util/u_half.h:126:29: runtime error: left shift of 32768 by 16 places cannot be represented in type 'int'
    #0 0x5646ff63d488 in util_half_to_float ../src/gallium/auxiliary/util/u_half.h:126
    #1 0x5646ff63d749 in _mesa_half_to_float ../src/util/half_float.c:145
    #2 0x5646ff54d557 in nir_const_value_negative_equal ../src/compiler/nir/nir_instr_set.c:372
    #3 0x5646ff44d29a in const_value_negative_equal_test_nir_type_float16_trivially_true_Test::TestBody() ../src/compiler/nir/tests/negative_equal_tests.cpp:121
    #4 0x5646ff505c05 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../src/gtest/src/gtest.cc:2402
    #5 0x5646ff4f1513 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ../src/gtest/src/gtest.cc:2438
    #6 0x5646ff4979b5 in testing::Test::Run() ../src/gtest/src/gtest.cc:2474
    #7 0x5646ff49a08e in testing::TestInfo::Run() ../src/gtest/src/gtest.cc:2656
    #8 0x5646ff49c81c in testing::TestCase::Run() ../src/gtest/src/gtest.cc:2774
    #9 0x5646ff4b81f6 in testing::internal::UnitTestImpl::RunAllTests() ../src/gtest/src/gtest.cc:4649
    #10 0x5646ff50981e in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../src/gtest/src/gtest.cc:2402
    #11 0x5646ff4f4eeb in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) ../src/gtest/src/gtest.cc:2438
    #12 0x5646ff4af818 in testing::UnitTest::Run() ../src/gtest/src/gtest.cc:4257
    #13 0x5646ff52e639 in RUN_ALL_TESTS() ../src/gtest/include/gtest/gtest.h:2233
    #14 0x5646ff52e4f9 in main ../src/gtest/src/gtest_main.cc:37
    #15 0x7f6bacb78bba in __libc_start_main ../csu/libc-start.c:308
    #16 0x5646ff448019 in _start (/home/daenzer/src/mesa-git/mesa/build-amd64-sanitize/src/compiler/nir/negative_equal+0x17c019)

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
src/gallium/auxiliary/util/u_half.h