From 68cb76de5ddadf5cd72f456b8e864f63e044d2c1 Mon Sep 17 00:00:00 2001 From: Nick Hamilton Date: Fri, 9 Jan 2026 10:27:01 +0000 Subject: [PATCH] pco: Fix encoding of branch to an empty block When calculating the relative offset for a branch the pco_first_igrp function is used to find the first instruction of a block. However if the block is empty the function does not return NULL as it description implies but returns a pointer to the list head which is not a valid node. Using this leads to a garbage relative offset been calculated which leads to unexpected behaviour. Fix is to add a check for the list been empty and return NULL (the same issue also exists in pco_last_igrp). This leads to the calling function, pco_cf_node_offset, searching for the next none empty block which is the expected behaviour. Fix deqp: dEQP-VK.graphicsfuzz.cov-two-nested-loops-switch-case-matrix-array-increment dEQP-VK.graphicsfuzz.stable-binarysearch-tree-false-if-discard-loop Signed-off-by: Nick Hamilton Reviewed-by: Simon Perretta Part-of: --- src/imagination/pco/pco_internal.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/imagination/pco/pco_internal.h b/src/imagination/pco/pco_internal.h index e6d8b26f495..50d42566e49 100644 --- a/src/imagination/pco/pco_internal.h +++ b/src/imagination/pco/pco_internal.h @@ -1534,6 +1534,9 @@ static inline pco_instr *pco_prev_instr(pco_instr *instr) */ static inline pco_igrp *pco_first_igrp(pco_block *block) { + if (list_is_empty(&block->instrs)) + return NULL; + return list_first_entry(&block->instrs, pco_igrp, link); } @@ -1545,6 +1548,9 @@ static inline pco_igrp *pco_first_igrp(pco_block *block) */ static inline pco_igrp *pco_last_igrp(pco_block *block) { + if (list_is_empty(&block->instrs)) + return NULL; + return list_first_entry(&block->instrs, pco_igrp, link); }