vla: enable sizeof operator for indirection
authorSanimir Agovic <sanimir.agovic@intel.com>
Sat, 12 Oct 2013 11:36:16 +0000 (12:36 +0100)
committerJoel Brobecker <brobecker@adacore.com>
Mon, 14 Apr 2014 16:14:11 +0000 (09:14 -0700)
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.

gdb/ChangeLog:

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

gdb/ChangeLog
gdb/eval.c

index 17556097acea6fd05c31d5e34e6f003d2be5f7ef..c7efe6298ba654a4225324860e3ee10c48f98ba0 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-14  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-14  Sanimir Agovic  <sanimir.agovic@intel.com>
 
        * eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
index 85523cd2fd3717fd1c394bc22310cc0e54480da9..22392eb4aae2d37c1ffa70055228e9788053f7e0 100644 (file)
@@ -3026,7 +3026,9 @@ 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 = TYPE_TARGET_TYPE (type);
-      break;
+      if (is_dynamic_type (type))
+       type = value_type (value_ind (val));
+      return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
 
     case UNOP_MEMVAL:
       (*pos) += 3;
This page took 0.029001 seconds and 4 git commands to generate.