public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fix bogus 'function does return' warning
@ 2009-10-15 19:51 Eric Botcazou
  2009-10-16  9:50 ` Richard Guenther
  0 siblings, 1 reply; 19+ messages in thread
From: Eric Botcazou @ 2009-10-15 19:51 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1658 bytes --]

Hi,

the GIMPLE EH patch introduced a regression for the attached testcase: a 
bogus 'function does return' is now issued.

The problem is that the EH pass turns

      D.2142 = &"p.adb"[0];
      .gnat_rcheck_20 (D.2142, 7);
      <D.2137>:
      D.2143 = &"p.adb"[0];
      .gnat_rcheck_04 (D.2143, 9);
      goto <D.2151>;
    }
  finally
    {
      p.error (); [static-chain: &FRAME.8]
    }
  <D.2151>:
  return;

into

  D.2142 = &"p.adb"[0];
  .gnat_rcheck_20 (D.2142, 7);
  <D.2137>:
  D.2143 = &"p.adb"[0];
  .gnat_rcheck_04 (D.2143, 9);
  finally_tmp.10 = 0;
  goto <D.2156>;
  <D.2156>:
  p.error (); [static-chain: &FRAME.8]
  switch (finally_tmp.10) <default: <D.2159>, default: <D.2159>, case 1: 
<D.2158>>
  <D.2159>:
  goto <D.2151>;
  <D.2151>:
  return;
  <D.2157>:
  finally_tmp.10 = 1;
  goto <D.2156>;
  <D.2158>:
  resx 1

thus masking the fact that D.2159 and D.2151 are unreachable.  So the CFG ends 
up being

<bb 21>:
  D.2143 = &"p.adb"[0];
  .gnat_rcheck_04 (D.2143, 9);

<L17>:
  return;

<L19>:
  finally_tmp.10 = 1;
  p.error (); [static-chain: &FRAME.8]
  switch (finally_tmp.10) <default: <L17>, case 1: <L20>>

<L20>:
  resx 1

and the EXIT block has a predecessor, hence the warning.


The proposed fix is to remove unreachable statements after noreturn calls 
during the "lower" pass.  Tested on i586-suse-linux, OK for mainline?


2009-10-15  Eric Botcazou  <ebotcazou@adacore.com>

	* gimple-low.c (lower_stmt) <GIMPLE_CALL>: If the call is noreturn,
	remove subsequent regular statements in the sequence.


2009-10-15  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/noreturn1.ad[sb]: New test.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 701 bytes --]

Index: gimple-low.c
===================================================================
--- gimple-low.c	(revision 152797)
+++ gimple-low.c	(working copy)
@@ -387,6 +387,18 @@ lower_stmt (gimple_stmt_iterator *gsi, s
 	    lower_builtin_setjmp (gsi);
 	    return;
 	  }
+
+	/* After a noreturn call, remove the subsequent statements in the
+	   sequence up to the next OMP statement or label.  */
+	if (decl && (flags_from_decl_or_type (decl) & ECF_NORETURN))
+	  {
+	      gsi_next (gsi);
+	      while (!gsi_end_p (*gsi)
+		     && !is_gimple_omp (gsi_stmt (*gsi))
+		     && gimple_code (gsi_stmt (*gsi)) != GIMPLE_LABEL)
+		gsi_remove (gsi, false);
+	      return;
+	  }
       }
       break;
 

[-- Attachment #3: noreturn1.adb --]
[-- Type: text/x-adasrc, Size: 327 bytes --]

-- { 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;

[-- Attachment #4: noreturn1.ads --]
[-- Type: text/x-adasrc, Size: 159 bytes --]

with Ada.Exceptions; use Ada.Exceptions;

package Noreturn1 is

   procedure Error (E : in Exception_Occurrence);
   pragma No_Return (Error);

end Noreturn1;

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2009-10-19 17:57 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-15 19:51 [Patch] Fix bogus 'function does return' warning Eric Botcazou
2009-10-16  9:50 ` Richard Guenther
2009-10-16  9:55   ` Eric Botcazou
2009-10-16 10:38     ` Richard Guenther
2009-10-16 11:12       ` Eric Botcazou
2009-10-16 11:32         ` Richard Guenther
2009-10-16 13:21           ` Eric Botcazou
2009-10-17 10:26             ` Eric Botcazou
2009-10-17 11:29               ` Richard Guenther
2009-10-17 11:36                 ` Eric Botcazou
2009-10-17 14:12                   ` Richard Guenther
2009-10-17 17:00                     ` Richard Henderson
2009-10-17 17:10                       ` Richard Guenther
2009-10-18 15:49                         ` Eric Botcazou
2009-10-18 16:36                           ` Richard Henderson
2009-10-18 18:41                             ` Eric Botcazou
2009-10-19 15:39                               ` Richard Henderson
2009-10-19 17:32                                 ` Eric Botcazou
2009-10-19 18:30                                   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).