DWARF add DW_AT_noreturn on noreturn function subprogram.
authorMark Wielaard <mjw@redhat.com>
Wed, 26 Nov 2014 10:10:27 +0000 (10:10 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Wed, 26 Nov 2014 10:10:27 +0000 (10:10 +0000)
This implements the DWARFv5 noreturn proposal:
http://dwarfstd.org/ShowIssue.php?issue=140331.1

TREE_THIS_VOLATILE on a FUNCTION_DECL node means the function does not
return normally. This catches the traditional noreturn GNU attribute,
the C11 _Noreturn keyword and the C++11 [[noreturn]] attribute.

This relies on the DW_AT_noreturn constant defined in the DWARFv5 DRAFT:
http://www.dwarfstd.org/doc/dwarf5.20141029.pdf

gcc/ChangeLog

* dwarf2out.c (gen_subprogram_die): Add DW_AT_noreturn when the
function decl has TREE_THIS_VOLATILE.

gcc/testsuite/ChangeLog

* g++.dg/debug/dwarf2/noreturn-function.C: New test.
* gcc.dg/debug/dwarf2/noreturn-function-attribute.c: Likewise.
* gcc.dg/debug/dwarf2/noreturn-function-keyword.c: Likewise.

include/ChangeLog

* dwarf2.def (DW_AT_noreturn): New DWARF5 attribute.

From-SVN: r218075

gcc/ChangeLog
gcc/dwarf2out.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/debug/dwarf2/noreturn-function.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-attribute.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-keyword.c [new file with mode: 0644]
include/ChangeLog
include/dwarf2.def

index 14fc5b90f1c26e114c092c460279f775a6374317..e7845c7b51a1f88f911958f0d0b12062394228b7 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-25  Mark Wielaard  <mjw@redhat.com>
+
+       * dwarf2out.c (gen_subprogram_die): Add DW_AT_noreturn when the
+       function decl has TREE_THIS_VOLATILE.
+
 2014-11-26  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/62238
index 3d50ac984f307cce0247a127bbe57485d2f353bc..25307d22d7b017a7f8ece71ac3bcb71a11f6bebb 100644 (file)
@@ -18336,6 +18336,9 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
       if (DECL_ARTIFICIAL (decl))
        add_AT_flag (subr_die, DW_AT_artificial, 1);
 
+      if (TREE_THIS_VOLATILE (decl) && (dwarf_version >= 5 || !dwarf_strict))
+       add_AT_flag (subr_die, DW_AT_noreturn, 1);
+
       add_accessibility_attribute (subr_die, decl);
     }
 
index adc868ff2335988cece9db4dc51ff6a751aec0a0..429885c21bf2edb325474aacf159e5dbe3885c63 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-24  Mark Wielaard  <mjw@redhat.com>
+
+       * g++.dg/debug/dwarf2/noreturn-function.C: New test.
+       * gcc.dg/debug/dwarf2/noreturn-function-attribute.c: Likewise.
+       * gcc.dg/debug/dwarf2/noreturn-function-keyword.c: Likewise.
+
 2014-11-26  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/62238
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/noreturn-function.C b/gcc/testsuite/g++.dg/debug/dwarf2/noreturn-function.C
new file mode 100644 (file)
index 0000000..73a0af4
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-O -std=c++11 -g -dA -gno-strict-dwarf" }
+// Expect DW_AT_noreturn once in .debug_info and once in .debug_abbrev
+// { dg-final { scan-assembler-times "DW_AT_noreturn" 2 } }
+
+class Foo
+{
+  int i;
+  void bar [[noreturn]] (int j);
+};
+
+void
+Foo::bar (int j)
+{
+  while (1) { ; }
+}
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-attribute.c b/gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-attribute.c
new file mode 100644 (file)
index 0000000..7c8924a
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// { dg-options "-O -std=c99 -g -dA -gno-strict-dwarf" }
+// Expect DW_AT_noreturn once in .debug_info and once in .debug_abbrev
+// { dg-final { scan-assembler-times "DW_AT_noreturn" 2 } }
+
+void __attribute__ ((noreturn))
+baz (void)
+{
+  while (1) { ; }
+}
+
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-keyword.c b/gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-keyword.c
new file mode 100644 (file)
index 0000000..ced96d1
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-O -std=c11 -g -dA -gno-strict-dwarf" }
+// Expect DW_AT_noreturn once in .debug_info and once in .debug_abbrev
+// { dg-final { scan-assembler-times "DW_AT_noreturn" 2 } }
+
+_Noreturn void exit (int);
+
+void exit (int i)
+{
+  while (i < 0 || i == 0 || i > 0)
+    ;
+}
+
index ea7fba60ae158d00dd2d0d973474498dff85f8f7..e73a9a89df6498c61ed0c99bfc3f9310c7cd3471 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-25  Mark Wielaard  <mjw@redhat.com>
+
+       * dwarf2.def (DW_AT_noreturn): New DWARF5 attribute.
+
 2014-11-14  Shinichiro Hamaji  <shinichiro.hamaji@gmail.com>
 
        * dwarf2.def (DW_AT_APPLE_optimized, DW_AT_APPLE_flags)
index 8ca143c52121bcc0e1031bc5c8b3147ac69691cd..8533a3edbd588f2d7f9ef36c028c25b5f2133bb0 100644 (file)
@@ -308,6 +308,8 @@ DW_AT (DW_AT_data_bit_offset, 0x6b)
 DW_AT (DW_AT_const_expr, 0x6c)
 DW_AT (DW_AT_enum_class, 0x6d)
 DW_AT (DW_AT_linkage_name, 0x6e)
+/* DWARF 5.  */
+DW_AT (DW_AT_noreturn, 0x87)
 
 DW_AT_DUP (DW_AT_lo_user, 0x2000) /* Implementation-defined range start.  */
 DW_AT_DUP (DW_AT_hi_user, 0x3fff) /* Implementation-defined range end.  */