From: Francisco Jerez Date: Fri, 26 Jan 2018 19:48:02 +0000 (-0800) Subject: intel/ir: Fix invalid type aliasing with undefined behavior in test_eu_compact. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cb309d27c52e9a6eeeedbddb82a0f6eb75a6f263;p=mesa.git intel/ir: Fix invalid type aliasing with undefined behavior in test_eu_compact. test_fuzz_compact_instruction() was attempting to modify the uint64_t data array of a brw_inst through a pointer to uint32_t, which has undefined behavior. This was causing the test_eu_compact unit test to fail mysteriously for me on GCC 7 with some additional harmless-looking changes I had applied to my tree, which happened to affect the order instructions are emitted by GCC causing the bit twiddling to be done after the clear_pad_bits() call which is supposed to overwrite the same data through a pointer of different type, leading to data corruption. A similar failure has been reported by Vinson Lee on the master branch built with GCC 8. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105052 Tested-by: Vinson Lee Reviewed-by: Matt Turner --- diff --git a/src/intel/compiler/test_eu_compact.cpp b/src/intel/compiler/test_eu_compact.cpp index 1532e3b9840..f6924abd368 100644 --- a/src/intel/compiler/test_eu_compact.cpp +++ b/src/intel/compiler/test_eu_compact.cpp @@ -149,13 +149,13 @@ test_fuzz_compact_instruction(struct brw_codegen *p, brw_inst src) for (int bit1 = 0; bit1 < 128; bit1++) { brw_inst instr = src; - uint32_t *bits = (uint32_t *)&instr; + uint64_t *bits = instr.data; if (skip_bit(p->devinfo, &src, bit1)) continue; - bits[bit0 / 32] ^= (1 << (bit0 & 31)); - bits[bit1 / 32] ^= (1 << (bit1 & 31)); + bits[bit0 / 64] ^= (1ull << (bit0 & 63)); + bits[bit1 / 64] ^= (1ull << (bit1 & 63)); clear_pad_bits(p->devinfo, &instr);