User account creation filtered due to spam.

Bug 29323 - [4.0 Regression] set_nothrow_function_flags does invalid analysis on weak functions
Summary: [4.0 Regression] set_nothrow_function_flags does invalid analysis on weak fun...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.1.2
Assignee: Not yet assigned to anyone
URL:
Keywords: EH, wrong-code
Depends on:
Blocks:
 
Reported: 2006-10-02 16:05 UTC by Jorn Wolfgang Rennecke
Modified: 2007-02-03 20:30 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3 4.1.2 4.2.0
Known to fail: 4.1.1 4.2.0 3.3.3 3.0.4
Last reconfirmed: 2006-10-09 14:25:36


Attachments
test case - main file (221 bytes, text/plain)
2006-10-02 16:09 UTC, Jorn Wolfgang Rennecke
Details
test case - actual definition of function foo (67 bytes, text/plain)
2006-10-02 16:10 UTC, Jorn Wolfgang Rennecke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2006-10-02 16:05:00 UTC
If a function definition is present, except.c:set_nothrow_function_flags marks functions as nothrow depending on analysis of the function definition.
This is incorrect when the function does not bind locally (compare with
other function analysis in PR tree-optimization/27781).
Comment 1 Jorn Wolfgang Rennecke 2006-10-02 16:09:02 UTC
Created attachment 12370 [details]
test case - main file
Comment 2 Jorn Wolfgang Rennecke 2006-10-02 16:10:06 UTC
Created attachment 12371 [details]
test case - actual definition of function foo
Comment 3 Jorn Wolfgang Rennecke 2006-10-02 17:07:41 UTC
While except.c:set_nothrow_function_flags analyzes rtl, the DECL_NOTHROW flag
it computes is a tree bit.  via calls.c:flags_from_decl_or_type ->
calls.c:call_expr_flags -> tree-eh.c:tree_could_throw_p makes this information
is made available to the tree optimizers.
Comment 4 Andrew Pinski 2006-10-03 05:26:42 UTC
http://gcc.gnu.org/ml/gcc-patches/2000-03/msg00354.html
So this is a regression from 2.95.3.
Comment 5 Richard Biener 2006-10-09 14:25:36 UTC
The frontend marks foo () TREE_STATIC in start_preparsed_function () and later TREE_NOTHROW in finish_function () because

  /* If this function can't throw any exceptions, remember that.  */
  if (!processing_template_decl
      && !cp_function_chain->can_throw
      && !flag_non_call_exceptions)
    TREE_NOTHROW (fndecl) = 1;

where cp_function_chain->can_throw is 0 (its initial value(?)).

Fixing that and the RTL problem fixes the testcase.  I am, of course, not
sure if the C++ frontend fix is ok.

Index: except.c
===================================================================
--- except.c    (revision 117569)
+++ except.c    (working copy)
@@ -2787,6 +2787,9 @@ set_nothrow_function_flags (void)
 {
   rtx insn;
 
+  if (!targetm.binds_local_p (current_function_decl))
+    return 0;
+
   TREE_NOTHROW (current_function_decl) = 1;
 
   /* Assume cfun->all_throwers_are_sibcalls until we encounter
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 117569)
+++ cp/decl.c   (working copy)
@@ -11081,7 +11081,8 @@ finish_function (int flags)
   /* If this function can't throw any exceptions, remember that.  */
   if (!processing_template_decl
       && !cp_function_chain->can_throw
-      && !flag_non_call_exceptions)
+      && !flag_non_call_exceptions
+      && targetm.binds_local_p (fndecl))
     TREE_NOTHROW (fndecl) = 1;
 
   /* This must come after expand_function_end because cleanups might



Comment 6 patchapp@dberlin.org 2006-10-09 16:10:15 UTC
Subject: Bug number PR29323

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00458.html
Comment 7 Richard Biener 2006-10-10 08:27:13 UTC
Subject: Bug 29323

Author: rguenth
Date: Tue Oct 10 08:27:02 2006
New Revision: 117598

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117598
Log:
2006-10-10  Richard Guenther  <rguenther@suse.de>

	PR rtl-optimization/29323
	* except.c (set_nothrow_function_flags): For functions
	that do not bind local bail out early.

	* decl.c (finish_function): Set TREE_NOTHROW only for
	functions that bind local.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/except.c

Comment 8 Richard Biener 2006-10-10 08:27:25 UTC
Fixed on the mainline.
Comment 9 Richard Biener 2006-10-14 09:13:54 UTC
Subject: Bug 29323

Author: rguenth
Date: Sat Oct 14 09:13:43 2006
New Revision: 117727

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117727
Log:
2006-10-14  Richard Guenther  <rguenther@suse.de>

	PR rtl-optimization/29323
        * except.c (set_nothrow_function_flags): For functions
        that do not bind local bail out early.

        * decl.c (finish_function): Set TREE_NOTHROW only for
        functions that bind local.

Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/decl.c
    branches/gcc-4_1-branch/gcc/except.c

Comment 10 Richard Biener 2006-10-14 09:14:15 UTC
Fixed for 4.1.2.
Comment 11 Gabriel Dos Reis 2007-02-03 20:30:01 UTC
Fixed in GCC-4.1.2.