aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@osandov.com>2018-09-13 10:27:12 +0000
committerTom de Vries <vries@gcc.gnu.org>2018-09-13 10:27:12 +0000
commit67295b68372f0dd13d44556e2f48a370c5d75119 (patch)
treee3c1d2f4989f85b7e96c34cf47cd13023c9f6fa6
parent231c52ae41a335649013f9fbfabca337d1ea98fa (diff)
downloadgcc-67295b68372f0dd13d44556e2f48a370c5d75119.zip
gcc-67295b68372f0dd13d44556e2f48a370c5d75119.tar.gz
gcc-67295b68372f0dd13d44556e2f48a370c5d75119.tar.bz2
[debug] DWARF: add DW_AT_count to zero-length arrays
2018-09-13 Omar Sandoval <osandov@osandov.com> Tom de Vries <tdevries@suse.de> PR debug/86985 * dwarf2out.c (is_c): New function. (add_subscript_info): Add DW_AT_count of 0 for C zero-length arrays. * gcc.dg/guality/zero-length-array.c: New test. Co-Authored-By: Tom de Vries <tdevries@suse.de> From-SVN: r264267
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/dwarf2out.c26
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/guality/zero-length-array.c21
4 files changed, 58 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 99b894b..e62f461 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2018-09-13 Omar Sandoval <osandov@osandov.com>
+ Tom de Vries <tdevries@suse.de>
+
+ PR debug/86985
+ * dwarf2out.c (is_c): New function.
+ (add_subscript_info): Add DW_AT_count of 0 for C zero-length arrays.
+
2018-09-13 Sam Tebbs <sam.tebbs@arm.com>
PR target/85628
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 9e9da30..48c5037 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -3679,6 +3679,7 @@ static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
+static bool is_c (void);
static bool is_cxx (void);
static bool is_cxx (const_tree);
static bool is_fortran (void);
@@ -5443,6 +5444,19 @@ get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
return a ? AT_file (a) : NULL;
}
+/* Return TRUE if the language is C. */
+
+static inline bool
+is_c (void)
+{
+ unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+ return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_C99
+ || lang == DW_LANG_C11 || lang == DW_LANG_ObjC);
+
+
+}
+
/* Return TRUE if the language is C++. */
static inline bool
@@ -21000,8 +21014,16 @@ add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
if (!get_AT (subrange_die, DW_AT_lower_bound))
add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL);
- if (upper && !get_AT (subrange_die, DW_AT_upper_bound))
- add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
+ if (!get_AT (subrange_die, DW_AT_upper_bound)
+ && !get_AT (subrange_die, DW_AT_count))
+ {
+ if (upper)
+ add_bound_info (subrange_die, DW_AT_upper_bound, upper, NULL);
+ else if ((is_c () || is_cxx ()) && COMPLETE_TYPE_P (type))
+ /* Zero-length array. */
+ add_bound_info (subrange_die, DW_AT_count,
+ build_int_cst (TREE_TYPE (lower), 0), NULL);
+ }
}
/* Otherwise we have an array type with an unspecified length. The
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 08915bb..be1e8b5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-13 Omar Sandoval <osandov@osandov.com>
+ Tom de Vries <tdevries@suse.de>
+
+ PR debug/86985
+ * gcc.dg/guality/zero-length-array.c: New test.
+
2018-09-13 Sam Tebbs <sam.tebbs@arm.com>
PR target/85628
diff --git a/gcc/testsuite/gcc.dg/guality/zero-length-array.c b/gcc/testsuite/gcc.dg/guality/zero-length-array.c
new file mode 100644
index 0000000..33f34d9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/guality/zero-length-array.c
@@ -0,0 +1,21 @@
+/* PR debug/86985 */
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+struct {
+ int foo;
+ int bar[0];
+} zla; /* Zero length array. */
+
+struct {
+ int foo;
+ int bar[];
+} fam; /* Flexible array member. */
+
+int
+main ()
+{
+ /* { dg-final { gdb-test . "type:zla" "struct { int foo; int bar[0]; }" } } */
+ /* { dg-final { gdb-test . "type:fam" "struct { int foo; int bar[]; }" } } */
+ return 0;
+}