From patchwork Sun Jun 27 08:43:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 57085 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]) by ozlabs.org (Postfix) with SMTP id AE23CB6EFE for ; Sun, 27 Jun 2010 18:47:53 +1000 (EST) Received: (qmail 7449 invoked by alias); 27 Jun 2010 08:47:52 -0000 Received: (qmail 7440 invoked by uid 22791); 27 Jun 2010 08:47:51 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,TW_TM X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 27 Jun 2010 08:47:47 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6DC06CB0232 for ; Sun, 27 Jun 2010 10:47:56 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mKvwewaPMIbC for ; Sun, 27 Jun 2010 10:47:56 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 3E39ECB0221 for ; Sun, 27 Jun 2010 10:47:56 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix bogus noreturn warning Date: Sun, 27 Jun 2010 10:43:20 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201006271043.21089.ebotcazou@adacore.com> 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 More precisely: /home/eric/svn/gcc/gcc/testsuite/gnat.dg/noreturn3.adb: In function 'Noreturn3.Raise_Error': /home/eric/svn/gcc/gcc/testsuite/gnat.dg/noreturn3.adb:25:6: warning: 'noreturn' function does return [enabled by default] Fix shamelessly borrowed from the C front-end, tested on i586-suse-linux and applied on the mainline. 2010-06-27 Eric Botcazou * gcc-interface/trans.c: Include tree-flow.h. (gnu_switch_label_stack): Delete. (Case_Statement_to_gnu): Do not emit the goto at the end of a case if its associated block cannot fall through. Do not emit the final label if no cases branche to it. * gcc-interface/Make-lang.in (ada/trans.o): Add $(TREE_FLOW_H). 2010-06-27 Eric Botcazou * gnat.dg/noreturn3.ad[sb]: New test. Index: gcc-interface/Make-lang.in =================================================================== --- gcc-interface/Make-lang.in (revision 161455) +++ gcc-interface/Make-lang.in (working copy) @@ -1260,7 +1260,7 @@ ada/targtyps.o : ada/gcc-interface/targt $(COMPILER) -c $(ALL_COMPILERFLAGS) -I.. $(ALL_CPPFLAGS) $< -o $@ ada/trans.o : ada/gcc-interface/trans.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ - $(TM_H) $(TREE_H) $(FLAGS_H) output.h tree-iterator.h \ + $(TM_H) $(TREE_H) $(FLAGS_H) output.h tree-iterator.h $(TREE_FLOW_H) \ $(GIMPLE_H) ada/gcc-interface/ada.h ada/adadecode.h ada/types.h \ ada/atree.h ada/elists.h ada/namet.h ada/nlists.h ada/snames.h \ ada/stringt.h ada/uintp.h ada/urealp.h ada/fe.h ada/sinfo.h ada/einfo.h \ Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 161455) +++ gcc-interface/trans.c (working copy) @@ -33,6 +33,7 @@ #include "output.h" #include "libfuncs.h" /* For set_stack_check_libfunc. */ #include "tree-iterator.h" +#include "tree-flow.h" #include "gimple.h" #include "ada.h" @@ -168,9 +169,6 @@ static GTY(()) VEC(tree,gc) *gnu_return_ /* Stack of LOOP_STMT nodes. */ static GTY(()) VEC(tree,gc) *gnu_loop_label_stack; -/* Stack of labels for switch statements. */ -static GTY(()) VEC(tree,gc) *gnu_switch_label_stack; - /* The stacks for N_{Push,Pop}_*_Label. */ static GTY(()) VEC(tree,gc) *gnu_constraint_error_label_stack; static GTY(()) VEC(tree,gc) *gnu_storage_error_label_stack; @@ -1908,9 +1906,9 @@ Attribute_to_gnu (Node_Id gnat_node, tre static tree Case_Statement_to_gnu (Node_Id gnat_node) { - tree gnu_result; - tree gnu_expr; + tree gnu_result, gnu_expr, gnu_label; Node_Id gnat_when; + bool may_fallthru = false; gnu_expr = gnat_to_gnu (Expression (gnat_node)); gnu_expr = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr); @@ -1933,8 +1931,7 @@ Case_Statement_to_gnu (Node_Id gnat_node /* We build a SWITCH_EXPR that contains the code with interspersed CASE_LABEL_EXPRs for each label. */ - VEC_safe_push (tree, gc, gnu_switch_label_stack, - create_artificial_label (input_location)); + gnu_label = create_artificial_label (input_location); start_stmt_group (); for (gnat_when = First_Non_Pragma (Alternatives (gnat_node)); @@ -2014,18 +2011,22 @@ Case_Statement_to_gnu (Node_Id gnat_node containing the Case statement. */ if (choices_added_p) { - add_stmt (build_stmt_group (Statements (gnat_when), true)); - add_stmt (build1 (GOTO_EXPR, void_type_node, - VEC_last (tree, gnu_switch_label_stack))); + tree group = build_stmt_group (Statements (gnat_when), true); + bool group_may_fallthru = block_may_fallthru (group); + add_stmt (group); + if (group_may_fallthru) + { + add_stmt (build1 (GOTO_EXPR, void_type_node, gnu_label)); + may_fallthru = true; + } } } - /* Now emit a definition of the label all the cases branched to. */ - add_stmt (build1 (LABEL_EXPR, void_type_node, - VEC_last (tree, gnu_switch_label_stack))); + /* Now emit a definition of the label the cases branche to, if any. */ + if (may_fallthru) + add_stmt (build1 (LABEL_EXPR, void_type_node, gnu_label)); gnu_result = build3 (SWITCH_EXPR, TREE_TYPE (gnu_expr), gnu_expr, end_stmt_group (), NULL_TREE); - VEC_pop (tree, gnu_switch_label_stack); return gnu_result; }