From 01e5af5a2f5fa4813e359bc03d42e98d091c7a2d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 9 Mar 2017 17:42:45 +0100 Subject: [PATCH] re PR c/79969 (C FE emits locus of forward enum declaration rather than definition into debug info) PR c/79969 * c-decl.c (start_enum): Adjust DECL_SOURCE_LOCATION of TYPE_STUB_DECL. * gcc.dg/debug/dwarf2/enum-loc1.c: New test. From-SVN: r246009 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 588fe73f660..e6da629882f 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-03-09 Jakub Jelinek + + PR c/79969 + * c-decl.c (start_enum): Adjust DECL_SOURCE_LOCATION of + TYPE_STUB_DECL. + 2017-03-07 Jakub Jelinek PR c/79834 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 645304a7e47..130ffa6704b 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -8201,6 +8201,10 @@ start_enum (location_t loc, struct c_enum_contents *the_enum, tree name) enumtype = make_node (ENUMERAL_TYPE); pushtag (loc, name, enumtype); } + /* Update type location to the one of the definition, instead of e.g. + a forward declaration. */ + else if (TYPE_STUB_DECL (enumtype)) + DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc; if (C_TYPE_BEING_DEFINED (enumtype)) error_at (loc, "nested redefinition of %", name); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cad76f21eed..48fba4842f6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-03-09 Jakub Jelinek + + PR c/79969 + * gcc.dg/debug/dwarf2/enum-loc1.c: New test. + 2017-03-09 Marek Polacek PR c++/79687 diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c new file mode 100644 index 00000000000..73943130360 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c @@ -0,0 +1,19 @@ +/* PR c/79969 */ +/* { dg-do compile } */ +/* { dg-options "-gdwarf -dA -fno-merge-debug-strings" } */ + +enum ENUMTAG; + +enum ENUMTAG +{ + B = 1, + C = 2 +}; + +void +bar (void) +{ + enum ENUMTAG a = C; +} + +/* { dg-final { scan-assembler "DW_TAG_enumeration_type\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\"ENUMTAG\[^\\r\\n\]*DW_AT_name(\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*DW_AT_)*\[^\\r\\n\]*\[\\r\\n\]+\[^\\r\\n\]*\[^0-9a-fA-FxX](0x)?7\[^0-9a-fA-FxX]\[^\\r\\n\]*DW_AT_decl_line" } } */ -- 2.30.2