]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
vla: enable sizeof operator for indirection
authorSanimir Agovic <sanimir.agovic@intel.com>
Sat, 12 Oct 2013 11:36:16 +0000 (12:36 +0100)
committerSanimir Agovic <sanimir.agovic@intel.com>
Fri, 11 Apr 2014 12:43:50 +0000 (13:43 +0100)
This patch enables the sizeof operator for indirections:

1| void foo (size_t n) {
2|   int vla[n];
3|   int *vla_ptr = &vla;
4| }

(gdb) p sizeof(*vla_ptr)

yields sizeof (size_t) * n.

* eval.c (evaluate_subexp_for_sizeof) <UNOP_IND>: Create an indirect
value and retrieve the dynamic type size.

gdb/ChangeLog
gdb/eval.c

index ebeb2ef3a58185c218dc55127f6f99f20d88f1b6..1b989aec1d4541d68ee03024201b6ea6cf3a2b5b 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-11  Sanimir Agovic  <sanimir.agovic@intel.com>
+
+       * eval.c (evaluate_subexp_for_sizeof) <UNOP_IND>: Create an indirect
+       value and retrieve the dynamic type size.
+
 2014-04-11  Sanimir Agovic  <sanimir.agovic@intel.com>
 
        * eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
index 26454f60a2aca2ca9b81156a3571e96701a63fc8..1f4c8697e0b02f8bc2d67d4a86275afa4bb3c917 100644 (file)
@@ -3026,6 +3026,8 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
          && TYPE_CODE (type) != TYPE_CODE_ARRAY)
        error (_("Attempt to take contents of a non-pointer value."));
       type = check_typedef (TYPE_TARGET_TYPE (type));
+      if (is_dynamic_type (type))
+       type = value_type (value_ind (val));
       return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
 
     case UNOP_MEMVAL: