From patchwork Tue Nov 25 22:57:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 414920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F349F1400A0 for ; Wed, 26 Nov 2014 09:58:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=lTx5imsE/lq7 gNvQ330ZOyRoPW1no1OL/l/4/7pE1HnS5yYRQQlG4+zrtegx0DSnTUmcXWE/Rx9I rL5I3Zza88OCiTyEVEv1QZu8POEyxbxHgldmO1Ih1yXNZLnkMiTH/92Mr6s3/w8D sbFUYMo13JY90yw5JHW8dxumYM0Lalw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=JS9v4A9+wNfkNsJhTi 2bwlTluQY=; b=A91n7G18F96EqsAMZJv6q9VoMVrJjPd//0vPib4BENgg/PqhMT HpR+gkGrXCQPpZcN1DTutnkMS/RMgzWQ7N0MI3o5ezaOjr0mGH4Zyqs+nWQ+VZOS d7AY4oyYdXiGlfw5raph85mhuSe5MoAIvS1VUsKuvhERvj78wuHBALaAA= Received: (qmail 29302 invoked by alias); 25 Nov 2014 22:57:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29290 invoked by uid 89); 25 Nov 2014 22:57:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 25 Nov 2014 22:57:44 +0000 From: Mark Wielaard To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, ccoutant@google.com, Mark Wielaard Subject: [PATCH] DWARF add DW_AT_noreturn on noreturn function subprogram. Date: Tue, 25 Nov 2014 23:57:01 +0100 Message-Id: <1416956221-26727-1-git-send-email-mjw@redhat.com> X-Spam-Score: -2.9 (--) 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 We could also use a new GNU extension if we don't trust these constants to be stable. 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. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index d0eaaf1..25f0e7d 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -18348,6 +18348,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); } 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 index 0000000..73a0af4 --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/noreturn-function.C @@ -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 index 0000000..7c8924a --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-attribute.c @@ -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 index 0000000..ced96d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/noreturn-function-keyword.c @@ -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) + ; +} + diff --git a/include/dwarf2.def b/include/dwarf2.def index 8ca143c..8533a3e 100644 --- a/include/dwarf2.def +++ b/include/dwarf2.def @@ -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. */