]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Do not reuse 'attr' in read_array_type
authorTom Tromey <tromey@adacore.com>
Wed, 11 Mar 2026 13:46:11 +0000 (07:46 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 11 Mar 2026 17:46:43 +0000 (11:46 -0600)
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 <simon.marchi@efficios.com>
gdb/dwarf2/read.c

index 2f27a9ac75f78a101cc2a64b322814c16ae791f9..f61b09f3138c2b17b4b17abad343228dbcf5735c 100644 (file)
@@ -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 ());