From a0877c132c3ff955717ae7f5fcaca34ca6deba54 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 31 May 2024 13:34:57 -0700 Subject: [PATCH] glsl: Fix warning related to tg4_offsets in release mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compiler can't know that array_size() of the offsets parameter in textureGatherOffsets is (at most) 4, so use a MIN2() to make the limit visible. Just adding an assert() gets ignored in Release builds. This fixes the following warning in Release compilation: ``` ../src/compiler/glsl/glsl_to_nir.cpp: In member function ‘virtual void {anonymous}::nir_visitor::visit(ir_texture*)’: ../src/compiler/glsl/glsl_to_nir.cpp:2453:41: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 2453 | instr->tg4_offsets[i][j] = val; | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ In file included from ../src/compiler/glsl/glsl_to_nir.h:31, from ../src/compiler/glsl/glsl_to_nir.cpp:29: ../src/compiler/nir/nir.h:2470:11: note: at offset 8 into destination object ‘nir_tex_instr::tg4_offsets’ of size 8 2470 | int8_t tg4_offsets[4][2]; | ^~~~~~~~~~~ ../src/compiler/glsl/glsl_to_nir.cpp:2453:41: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 2453 | instr->tg4_offsets[i][j] = val; | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ ../src/compiler/nir/nir.h:2470:11: note: at offset 9 into destination object ‘nir_tex_instr::tg4_offsets’ of size 8 2470 | int8_t tg4_offsets[4][2]; | ^~~~~~~~~~~ ``` This is from: `gcc (GCC) 14.1.1 20240522 (Red Hat 14.1.1-4)`. Reviewed-by: Jordan Justen Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index cb185760fb4..fb7444f2c11 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -2430,7 +2430,8 @@ nir_visitor::visit(ir_texture *ir) if (ir->offset != NULL) { if (glsl_type_is_array(ir->offset->type)) { - for (int i = 0; i < glsl_array_size(ir->offset->type); i++) { + const int size = MIN2(glsl_array_size(ir->offset->type), 4); + for (int i = 0; i < size; i++) { const ir_constant *c = ir->offset->as_constant()->get_array_element(i);