Handle volatile array types in dwarf2read.c.
authorMark Wielaard <mjw@redhat.com>
Mon, 30 Jun 2014 21:21:52 +0000 (23:21 +0200)
committerMark Wielaard <mjw@redhat.com>
Tue, 1 Jul 2014 20:11:53 +0000 (22:11 +0200)
read_tag_const_type propagates the cv-qualifier to the array element type,
but read_tag_volatile_type didn't. Make sure that both cv-qualifiers that
apply to array types are handled the same.

gdb/ChangeLog

* dwarf2read.c (add_array_cv_type): New function.
(read_tag_const_type): Call add_array_cv_type for TYPE_CODE_ARRAY.
(read_tag_volatile_type): Likewise.

gdb/testsuite/ChangeLog

* gdb.base/constvars.c (violent, violet, vips, virgen, vulgar,
vulture, vilify, villar): New volatile array constants.
(vindictive, vegetation): New const volatile array constants.
* gdb.base/volatile.exp: Test volatile and const volatile array
types.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/constvars.c
gdb/testsuite/gdb.base/volatile.exp

index f6b4d30..984fc5c 100644 (file)
@@ -1,3 +1,9 @@
+2014-07-01  Mark Wielaard  <mjw@redhat.com>
+
+       * dwarf2read.c (add_array_cv_type): New function.
+       (read_tag_const_type): Call add_array_cv_type for TYPE_CODE_ARRAY.
+       (read_tag_volatile_type): Likewise.
+
 2014-07-01  Tom Tromey  <tromey@redhat.com>
 
        * breakpoint.c (add_catch_command): Use cmd_sfunc_ftype.
index 2563418..276d2f1 100644 (file)
@@ -14098,6 +14098,36 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
   return set_die_type (die, type, cu);
 }
 
+/* Add the given cv-qualifiers to the element type of the array.  GCC
+   outputs DWARF type qualifiers that apply to an array, not the
+   element type.  But GDB relies on the array element type to carry
+   the cv-qualifiers.  This mimics section 6.7.3 of the C99
+   specification.  */
+
+static struct type *
+add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu,
+                  struct type *base_type, int cnst, int voltl)
+{
+  struct type *el_type, *inner_array;
+
+  base_type = copy_type (base_type);
+  inner_array = base_type;
+
+  while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
+    {
+      TYPE_TARGET_TYPE (inner_array) =
+       copy_type (TYPE_TARGET_TYPE (inner_array));
+      inner_array = TYPE_TARGET_TYPE (inner_array);
+    }
+
+  el_type = TYPE_TARGET_TYPE (inner_array);
+  cnst |= TYPE_CONST (el_type);
+  voltl |= TYPE_VOLATILE (el_type);
+  TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL);
+
+  return set_die_type (die, base_type, cu);
+}
+
 static struct type *
 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
 {
@@ -14113,25 +14143,7 @@ read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
   /* In case the const qualifier is applied to an array type, the element type
      is so qualified, not the array type (section 6.7.3 of C99).  */
   if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
-    {
-      struct type *el_type, *inner_array;
-
-      base_type = copy_type (base_type);
-      inner_array = base_type;
-
-      while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
-       {
-         TYPE_TARGET_TYPE (inner_array) =
-           copy_type (TYPE_TARGET_TYPE (inner_array));
-         inner_array = TYPE_TARGET_TYPE (inner_array);
-       }
-
-      el_type = TYPE_TARGET_TYPE (inner_array);
-      TYPE_TARGET_TYPE (inner_array) =
-       make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
-
-      return set_die_type (die, base_type, cu);
-    }
+    return add_array_cv_type (die, cu, base_type, 1, 0);
 
   cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
   return set_die_type (die, cv_type, cu);
@@ -14149,6 +14161,12 @@ read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
   if (cv_type)
     return cv_type;
 
+  /* In case the volatile qualifier is applied to an array type, the
+     element type is so qualified, not the array type (section 6.7.3
+     of C99).  */
+  if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
+    return add_array_cv_type (die, cu, base_type, 0, 1);
+
   cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
   return set_die_type (die, cv_type, cu);
 }
index 751848f..90be171 100644 (file)
@@ -1,3 +1,11 @@
+2014-06-30  Mark Wielaard  <mjw@redhat.com>
+
+       * gdb.base/constvars.c (violent, violet, vips, virgen, vulgar,
+       vulture, vilify, villar): New volatile array constants.
+       (vindictive, vegetation): New const volatile array constants.
+       * gdb.base/volatile.exp: Test volatile and const volatile array
+       types.
+
 2014-06-30  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * gdb.base/watchpoint-reuse-slot.exp: Handle the case that the
index 4228822..60cca2a 100644 (file)
@@ -127,6 +127,16 @@ main (void)
   volatile float          * volatile vitality = &vacuity;
   volatile double         * volatile voracity = &vertigo;
 
+  /* volatile arrays */
+  volatile char violent[2] = {vox, vox};
+  volatile unsigned char violet[2] = {victuals, victuals};
+  volatile short vips[2] = {vixen, vixen};
+  volatile unsigned short virgen[2] = {vitriol, vitriol};
+  volatile long vulgar[2] = {vellum, vellum};
+  volatile unsigned long vulture[2] = {valve, valve};
+  volatile float vilify[2] = {vacuity, vacuity};
+  volatile double villar[2] = {vertigo, vertigo};
+
   /* const volatile vars */
 
   const volatile char           victor = 'Y';
@@ -177,6 +187,10 @@ main (void)
   const volatile char              * const volatile vagary = &victor;
   const volatile unsigned char     * const volatile vendor = &vicar;
   
+  /* const volatile arrays */
+  const volatile char vindictive[2] = {victor, victor};
+  const volatile unsigned char vegetation[2] = {vicar, vicar};
+
   /* various structs with const members */
 
   struct crass { char * const ptr; } crass = { lamprey };
index 7cd7254..0e106fc 100644 (file)
@@ -229,6 +229,30 @@ gdb_test "ptype vagary" "type = const volatile char \\* const volatile.*"
 local_compiler_xfail_check
 gdb_test "ptype vendor" "type = const volatile unsigned char \\* const volatile.*"
 
+# volatile arrays
+local_compiler_xfail_check
+gdb_test "ptype violent" "type = volatile char \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype violet" "type = volatile unsigned char \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype vips" "type = volatile short( int)? \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype virgen" "type = volatile (unsigned short|short unsigned)( int)? \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype vulgar" "type = volatile long( int)? \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype vulture" "type = volatile (unsigned long|long unsigned)( int)? \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype vilify" "type = volatile float \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype villar" "type = volatile double \\\[2\\\]"
+
+# const volatile arrays
+local_compiler_xfail_check
+gdb_test "ptype vindictive" "type = const volatile char \\\[2\\\]"
+local_compiler_xfail_check
+gdb_test "ptype vegetation" "type = const volatile unsigned char \\\[2\\\]"
+
 # test function parameters
 local_compiler_xfail_check
 local_compiler_xfail_check_2