003890
2017-03-09  Jakub Jelinek  <jakub@redhat.com>
003890
003890
	PR c/79969
003890
	* c-decl.c (start_enum): Adjust DECL_SOURCE_LOCATION of
003890
	TYPE_STUB_DECL.
003890
003890
	* gcc.dg/debug/dwarf2/enum-loc1.c: New test.
003890
003890
--- gcc/c/c-decl.c.jj	2017-03-05 22:39:45.000000000 +0100
003890
+++ gcc/c/c-decl.c	2017-03-09 08:19:33.100042166 +0100
003890
@@ -8201,6 +8201,10 @@ start_enum (location_t loc, struct c_enu
003890
       enumtype = make_node (ENUMERAL_TYPE);
003890
       pushtag (loc, name, enumtype);
003890
     }
003890
+  /* Update type location to the one of the definition, instead of e.g.
003890
+     a forward declaration.  */
003890
+  else if (TYPE_STUB_DECL (enumtype))
003890
+    DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
003890
 
003890
   if (C_TYPE_BEING_DEFINED (enumtype))
003890
     error_at (loc, "nested redefinition of %<enum %E%>", name);
003890
--- gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c.jj	2017-03-09 08:09:30.742037844 +0100
003890
+++ gcc/testsuite/gcc.dg/debug/dwarf2/enum-loc1.c	2017-03-09 08:16:45.202268438 +0100
003890
@@ -0,0 +1,19 @@
003890
+/* PR c/79969 */
003890
+/* { dg-do compile } */
003890
+/* { dg-options "-gdwarf-2 -dA -fno-merge-debug-strings" } */
003890
+
003890
+enum ENUMTAG;
003890
+
003890
+enum ENUMTAG
003890
+{
003890
+  B = 1,
003890
+  C = 2
003890
+};
003890
+
003890
+void
003890
+bar (void)
003890
+{
003890
+  enum ENUMTAG a = C;
003890
+}
003890
+
003890
+/* { 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" } } */