]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Fix sizeof for dynamic types other than arrays
authorAndrew Burgess <andrew.burgess@embecosm.com>
Sun, 29 Jul 2018 21:14:33 +0000 (22:14 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 30 Jul 2018 18:51:53 +0000 (19:51 +0100)
In commit:

   commit 37cc0caeca4c9a8552370040f4cfeaeceaa03369
   Date:   Wed Jul 18 13:38:35 2018 +0200
   [gdb/exp] Interpret size of vla with unknown size as <optimized out>

All dynamic types are treated as arrays in the 'sizeof' code path,
which means that structures can incorrectly be treated as arrays.
This can cause a failure in the gdb.base/vla-datatypes.exp test
script.

This commit adds a check that we do have an array before checking the
array bounds, and I also check that the array index type is dynamic
too.  This second check probably isn't strictly necessary, but
shouldn't hurt, a non-dynamic index type shouldn't have undefined high
bound.

gdb/ChangeLog:

* eval.c (evaluate_subexp_for_sizeof): Check for array type before
checking array bounds are defined.

gdb/ChangeLog
gdb/eval.c

index 24ffeecda11b37028a9bea0d98b800d3d0150b90..6d5b24c1e11fbba04514e462d5f3295a32a9c86b 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-30  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * eval.c (evaluate_subexp_for_sizeof): Check for array type before
+       checking array bounds are defined.
+
 2018-07-30  Tom Tromey  <tom@tromey.com>
 
        * nat/linux-osdata.c (pid_pgid_entry::operator<): Fix
index 0495a11bfd785f5279e9933db8b6060582a6b304..2e08e9355f5e1ba8bf0ec9818e2291e23676100c 100644 (file)
@@ -3145,7 +3145,9 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
        {
          val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
          type = value_type (val);
-         if (TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type)))
+         if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+              && is_dynamic_type (TYPE_INDEX_TYPE (type))
+              && TYPE_HIGH_BOUND_UNDEFINED (TYPE_INDEX_TYPE (type)))
            return allocate_optimized_out_value (size_type);
        }
       else