From: Tom Tromey Date: Wed, 11 Mar 2026 13:46:11 +0000 (-0600) Subject: Do not reuse 'attr' in read_array_type X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=911b63a51f2e60890198aba520fa2c8d26153ac0;p=thirdparty%2Fbinutils-gdb.git Do not reuse 'attr' in read_array_type I was looking at dwarf2/read.c:read_array_type and I thought it would be nicer if the 'attr' wasn't reused. This patch changes it to be redeclared in every 'if' where it is used, making it clear that its value is local to just the one block. Approved-By: Simon Marchi --- diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 2f27a9ac75f..f61b09f3138 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11484,7 +11484,6 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) struct objfile *objfile = cu->per_objfile->objfile; struct type *type; struct type *element_type, *range_type, *index_type; - struct attribute *attr; const char *name; struct dynamic_prop *byte_stride_prop = NULL; unsigned int bit_stride = 0; @@ -11496,8 +11495,8 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) if (type) return type; - attr = dwarf2_attr (die, DW_AT_byte_stride, cu); - if (attr != NULL) + if (attribute *attr = dwarf2_attr (die, DW_AT_byte_stride, cu); + attr != nullptr) { int stride_ok; struct type *prop_type = cu->addr_sized_int_type (false); @@ -11519,8 +11518,8 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) } } - attr = dwarf2_attr (die, DW_AT_bit_stride, cu); - if (attr != NULL) + if (attribute *attr = dwarf2_attr (die, DW_AT_bit_stride, cu); + attr != nullptr) bit_stride = attr->unsigned_constant ().value_or (0); /* Irix 6.2 native cc creates array types without children for @@ -11602,15 +11601,15 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) custom vendor extension. The main difference between a regular array and the vector variant is that vectors are passed by value to functions. */ - attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); - if (attr != nullptr) + if (attribute *attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); + attr != nullptr) make_vector_type (type); /* The DIE may have DW_AT_byte_size set. For example an OpenCL implementation may choose to implement triple vectors using this attribute. */ - attr = dwarf2_attr (die, DW_AT_byte_size, cu); - if (attr != nullptr && attr->form_is_unsigned ()) + if (attribute *attr = dwarf2_attr (die, DW_AT_byte_size, cu); + attr != nullptr && attr->form_is_unsigned ()) { if (attr->as_unsigned () >= type->length ()) type->set_length (attr->as_unsigned ());