From 7ea0c538e3d387ac00c3b1be00a0a7a6e6ebff95 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 20 Jun 2024 13:34:10 -0700 Subject: [PATCH] anv/grl: add some validation that we're not going to overflow Coverity has spotted a place where we could in theory overflow. In reality it wont happen as the potential overflow is a bitfield with a maximum of two values. Add an `assume()` statement to help out the compiler and document our assumption. fixes: dc1aedef2bd054884685ad971a3ef5be07ecd101 Reviewed-by: Kenneth Graunke Part-of: (cherry picked from commit dc604f340a78e093946c3d89a884440c0cb6abba) --- .pick_status.json | 2 +- src/intel/vulkan/grl/grl_metakernel_gen.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index cc0a6c73585..50b753ac7b1 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -134,7 +134,7 @@ "description": "anv/grl: add some validation that we're not going to overflow", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "dc1aedef2bd054884685ad971a3ef5be07ecd101", "notes": null diff --git a/src/intel/vulkan/grl/grl_metakernel_gen.py b/src/intel/vulkan/grl/grl_metakernel_gen.py index 6c416bd3d5d..8fb00f63f20 100644 --- a/src/intel/vulkan/grl/grl_metakernel_gen.py +++ b/src/intel/vulkan/grl/grl_metakernel_gen.py @@ -239,8 +239,13 @@ class Expression(SSAStatement): def write_c(self, w): if self.zone == 'cpu': - w.write('uint64_t {} = ', self.c_name) c_cpu_vals = [s.c_cpu_val() for s in self.srcs] + # There is one bitfield that is a uint64_t, but only holds 2 bits. + # In practice we won't overflow, but let's help the compiler (and + # coverity) out here. + if self.op == '<<': + w.write(f'assume({c_cpu_vals[0]} < (1 << 8));') + w.write('uint64_t {} = ', self.c_name) if len(self.srcs) == 1: w.write('({} {})', self.op, c_cpu_vals[0]) elif len(self.srcs) == 2: