re PR c/79969 (C FE emits locus of forward enum declaration rather than definition...
authorJakub Jelinek <jakub@redhat.com>
Thu, 9 Mar 2017 16:42:45 +0000 (17:42 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Mar 2017 16:42:45 +0000 (17:42 +0100)
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
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c [new file with mode: 0644]

index 588fe73f66037d72a6508028739a94b68a612d1b..e6da629882f1f796d2b35a79d2f098bda6069184 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/79969
+       * c-decl.c (start_enum): Adjust DECL_SOURCE_LOCATION of
+       TYPE_STUB_DECL.
+
 2017-03-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/79834
index 645304a7e47ce558a787ac817d35225367dfc0ae..130ffa6704b1da765bb5205d9068dc968863969b 100644 (file)
@@ -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 %<enum %E%>", name);
index cad76f21eed079e21a1a8eaf42f18e2c5890556e..48fba4842f6b4326be1e6f4746676e2fa0cd75fb 100644 (file)
@@ -1,3 +1,8 @@
+2017-03-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/79969
+       * gcc.dg/debug/dwarf2/enum-loc1.c: New test.
+
 2017-03-09  Marek Polacek  <polacek@redhat.com>
 
        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 (file)
index 0000000..7394313
--- /dev/null
@@ -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" } } */