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: dc1aedef2b
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29825>
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user