From 79ddec0279508bee9a68b640a9633d874b06ac4a Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sat, 17 Oct 2009 22:17:26 +0000 Subject: [PATCH] gimple-low.c (lower_stmt): If the call is noreturn, remove a subsequent GOTO or RETURN statement. * gimple-low.c (lower_stmt) : If the call is noreturn, remove a subsequent GOTO or RETURN statement. From-SVN: r152959 --- gcc/ChangeLog | 9 +++++++-- gcc/gimple-low.c | 13 +++++++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/noreturn1.adb | 15 +++++++++++++++ gcc/testsuite/gnat.dg/noreturn1.ads | 8 ++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/noreturn1.adb create mode 100644 gcc/testsuite/gnat.dg/noreturn1.ads diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2aedb058d0b..c05cc6d82c7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,10 +1,15 @@ +2009-10-17 Eric Botcazou + + * gimple-low.c (lower_stmt) : If the call is noreturn, + remove a subsequent GOTO or RETURN statement. + 2009-10-17 Andy Hutchinson * config/avr.md (*movqi): Add zero as equally preferable constraint as general register. - (*movhi): Ditto. + (*movhi): Ditto. - 2009-10-17 Eric Botcazou +2009-10-17 Eric Botcazou * print-tree.c (print_node): Fix string for DECL_STRUCT_FUNCTION. diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c index b58fd7b42f5..39c735197a7 100644 --- a/gcc/gimple-low.c +++ b/gcc/gimple-low.c @@ -387,6 +387,19 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data *data) lower_builtin_setjmp (gsi); return; } + + /* After a noreturn call, remove a subsequent GOTO or RETURN that might + have been mechanically added; this will prevent the EH lowering pass + from adding useless edges and thus complicating the initial CFG. */ + if (decl && (flags_from_decl_or_type (decl) & ECF_NORETURN)) + { + gsi_next (gsi); + if (!gsi_end_p (*gsi) + && (gimple_code (gsi_stmt (*gsi)) == GIMPLE_GOTO + || gimple_code (gsi_stmt (*gsi)) == GIMPLE_RETURN)) + gsi_remove (gsi, false); + return; + } } break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 14900619ee6..62f8075d157 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2009-10-17 Eric Botcazou + + * gnat.dg/noreturn1.ad[sb]: New test. + 2009-10-17 Janus Weil Paul Thomas diff --git a/gcc/testsuite/gnat.dg/noreturn1.adb b/gcc/testsuite/gnat.dg/noreturn1.adb new file mode 100644 index 00000000000..83eafe7f364 --- /dev/null +++ b/gcc/testsuite/gnat.dg/noreturn1.adb @@ -0,0 +1,15 @@ +-- { dg-compile } + +package body Noreturn1 is + + procedure Error (E : in Exception_Occurrence) is + Occurrence_Message : constant String := Exception_Message (E); + begin + if Occurrence_Message = "$" then + raise Program_Error; + else + raise Constraint_Error; + end if; + end; + +end Noreturn1; diff --git a/gcc/testsuite/gnat.dg/noreturn1.ads b/gcc/testsuite/gnat.dg/noreturn1.ads new file mode 100644 index 00000000000..c63e4399907 --- /dev/null +++ b/gcc/testsuite/gnat.dg/noreturn1.ads @@ -0,0 +1,8 @@ +with Ada.Exceptions; use Ada.Exceptions; + +package Noreturn1 is + + procedure Error (E : in Exception_Occurrence); + pragma No_Return (Error); + +end Noreturn1;