https://gcc.gnu.org/g:cad2693096cd2395409aada5c26b56e3aeb6e849
commit r14-10565-gcad2693096cd2395409aada5c26b56e3aeb6e849 Author: Jakub Jelinek <ja...@redhat.com> Date: Thu Aug 1 20:23:15 2024 +0200 fortran: Fix up pasto in gfc_get_array_descr_info A static analyzer found a pasto in gfc_get_array_descr_info. The code does t = base_decl; if (!integer_zerop (dtype_off)) t = fold_build_pointer_plus (t, dtype_off); dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ()); field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK); rank_off = byte_position (field); if (!integer_zerop (dtype_off)) t = fold_build_pointer_plus (t, rank_off); i.e. uses the same !integer_zerop check between both, while it should be checking rank_off in the latter case. This actually doesn't change anything on the generated code, because both the dtype_off and rank_off aren't zero, typedef struct dtype_type { size_t elem_len; int version; signed char rank; signed char type; signed short attribute; } dtype_type; struct { type *base_addr; size_t offset; dtype_type dtype; index_type span; descriptor_dimension dim[]; }; dtype_off is 16 on 64-bit arches and 8 on 32-bit ones and rank_off is 12 on 64-bit arches and 8 on 32-bit arches, so this patch is just to pacify those static analyzers or be prepared if the ABI changes in the future. Because in the current ABI both of those are actually non-zero, doing if (!integer_zerop (something)) t = fold_build_pointer_plus (t, something); actually isn't an optimization, it will consume more compile time. If the ABI changes and we forget to readd it, nothing bad happens, fold_build_pointer_plus handles 0 addends fine, just takes some compile time to handle that. I've kept this if (!integer_zerop (data_off)) guard earlier because data_off is 0 in the current ABI, so it is an optimization there. 2024-08-01 Jakub Jelinek <ja...@redhat.com> * trans-types.cc (gfc_get_array_descr_info): Don't test if !integer_zerop (dtype_off), use fold_build_pointer_plus unconditionally. (cherry picked from commit 90fe402a89910d4fbe0efc15cf05cf6c0306586a) Diff: --- gcc/fortran/trans-types.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc index 8466c595e065..61523c7d162b 100644 --- a/gcc/fortran/trans-types.cc +++ b/gcc/fortran/trans-types.cc @@ -3527,14 +3527,11 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info) { rank = 1; info->ndimensions = 1; - t = base_decl; - if (!integer_zerop (dtype_off)) - t = fold_build_pointer_plus (t, dtype_off); + t = fold_build_pointer_plus (base_decl, dtype_off); dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ()); field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK); rank_off = byte_position (field); - if (!integer_zerop (dtype_off)) - t = fold_build_pointer_plus (t, rank_off); + t = fold_build_pointer_plus (t, rank_off); t = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (field)), t); t = build1 (INDIRECT_REF, TREE_TYPE (field), t);