google / amber

Amber is a multi-API shader test framework
Apache License 2.0
193 stars 65 forks source link

Workaround for GCC 11 uninit variable warnings #946

Closed mvainola closed 3 years ago

mvainola commented 3 years ago

Release builds of Amber (and the CTS) with GCC 11.0.1 produce some uninitialized variable warnings:

external/amber/src/src/float16_helper.cc: In function ‘float amber::float16::{anonymous}::HexFloat16ToFloat(const uint8_t*)’:
external/amber/src/src/float16_helper.cc:79:11: error: ‘hex’ is used uninitialized [-Werror=uninitialized]
   79 |   return *hex_float;
      |           ^~~~~~~~~
external/amber/src/src/float16_helper.cc:77:12: note: ‘hex’ declared here
   77 |   uint32_t hex = sign | exponent | mantissa;
      |            ^~~

I'm not sure if this is a bug in GCC. This commit works around the warnings by replacing reinterpret_cast with memcpy when type punning unsigned integers to floats. At least on GCC the generated code should be unchanged compared to the current approach:

There's also a new stringop-truncation warning in SPIRV-tools which affects building Amber but not the CTS.