From eb4618b1b5b8079ad71a7acd4d81b2d0a983426d Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 7 Apr 2026 09:46:27 +0100 Subject: [PATCH] util: fix UBSan error with _mesa_bfloat16_bits_to_float runtime error: left shift of 65535 by 16 places cannot be represented in type 'int' This fixes nir_opt_algebraic_pattern_test.bf2f. Signed-off-by: Rhys Perry Fixes: ecd2d2cf46df ("util: Add functions to convert float to/from bfloat16") Reviewed-by: Georg Lehmann (cherry picked from commit 72f2b8a034235ff0942fcca8646ad2bb66c8b454) Part-of: --- .pick_status.json | 2 +- src/util/bfloat.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index b39cb0a02f7..0a46b318698 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3324,7 +3324,7 @@ "description": "util: fix UBSan error with _mesa_bfloat16_bits_to_float", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "ecd2d2cf46dfc3305a6dc1497815b7b54eef513e", "notes": null diff --git a/src/util/bfloat.h b/src/util/bfloat.h index 886d55fb8ba..013c38e7e24 100644 --- a/src/util/bfloat.h +++ b/src/util/bfloat.h @@ -63,7 +63,7 @@ static inline float _mesa_bfloat16_bits_to_float(uint16_t bf) { union fi x; - x.ui = bf << 16; + x.ui = (uint32_t)bf << 16; return x.f; }