public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618)
@ 2011-07-04 18:10 Jakub Jelinek
  2011-07-05  8:44 ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2011-07-04 18:10 UTC (permalink / raw)
  To: gcc-patches

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

Hi!

Before http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168951
set_mem_attributes_minus_bitpos would set MEM_NOTRAP_P for decls
based on whether they are DECL_WEAK or not, but now it is set only
from !tree_could_trap_p.

These patches adjust tree_could_trap_p to say that references
to weak vars/functions may trap (for calls it was doing that already).

The first version of the patch is intended for 4.7 and only handles
that way weak vars/functions that aren't known to be defined somewhere
(either in current CU, or in the CUs included in -flto build).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

The second version is simplified one which always treats DECL_WEAK
vars as maybe trapping.  Ok for 4.6?

	Jakub

[-- Attachment #2: X189 --]
[-- Type: text/plain, Size: 1708 bytes --]

2011-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/49618
	* tree-eh.c (tree_could_trap_p) <case CALL_EXPR>: For DECL_WEAK
	t recurse on the decl.
	<case FUNCTION_DECL, case VAR_DECL>: For DECL_WEAK decls
	return true if expr isn't known to be defined in current
	TU or some other LTO partition.

--- gcc/tree-eh.c.jj	2011-06-17 11:02:19.000000000 +0200
+++ gcc/tree-eh.c	2011-07-04 14:27:01.000000000 +0200
@@ -2449,8 +2449,42 @@ tree_could_trap_p (tree expr)
     case CALL_EXPR:
       t = get_callee_fndecl (expr);
       /* Assume that calls to weak functions may trap.  */
-      if (!t || !DECL_P (t) || DECL_WEAK (t))
+      if (!t || !DECL_P (t))
 	return true;
+      if (DECL_WEAK (t))
+	return tree_could_trap_p (t);
+      return false;
+
+    case FUNCTION_DECL:
+      /* Assume that accesses to weak functions may trap, unless we know
+	 they are certainly defined in current TU or in some other
+	 LTO partition.  */
+      if (DECL_WEAK (expr))
+	{
+	  struct cgraph_node *node;
+	  if (!DECL_EXTERNAL (expr))
+	    return false;
+	  node = cgraph_function_node (cgraph_get_node (expr), NULL);
+	  if (node && node->in_other_partition)
+	    return false;
+	  return true;
+	}
+      return false;
+
+    case VAR_DECL:
+      /* Assume that accesses to weak vars may trap, unless we know
+	 they are certainly defined in current TU or in some other
+	 LTO partition.  */
+      if (DECL_WEAK (expr))
+	{
+	  struct varpool_node *node;
+	  if (!DECL_EXTERNAL (expr))
+	    return false;
+	  node = varpool_variable_node (varpool_get_node (expr), NULL);
+	  if (node && node->in_other_partition)
+	    return false;
+	  return true;
+	}
       return false;
 
     default:

[-- Attachment #3: X189a --]
[-- Type: text/plain, Size: 614 bytes --]

2011-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/49618
	* tree-eh.c (tree_could_trap_p) <case FUNCTION_DECL, case VAR_DECL>:
	For DECL_WEAK decls return true.

--- gcc/tree-eh.c.jj	2011-05-11 17:01:05.000000000 +0200
+++ gcc/tree-eh.c	2011-07-04 14:32:54.000000000 +0200
@@ -2459,6 +2459,13 @@ tree_could_trap_p (tree expr)
 	return true;
       return false;
 
+    case VAR_DECL:
+    case FUNCTION_DECL:
+      /* Assume that accesses to weak vars or functions may trap.  */
+      if (DECL_WEAK (expr))
+        return true;
+      return false;
+
     default:
       return false;
     }

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

* Re: [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618)
  2011-07-04 18:10 [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618) Jakub Jelinek
@ 2011-07-05  8:44 ` Richard Guenther
  2011-07-05  8:44   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Guenther @ 2011-07-05  8:44 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Mon, Jul 4, 2011 at 8:09 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> Before http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168951
> set_mem_attributes_minus_bitpos would set MEM_NOTRAP_P for decls
> based on whether they are DECL_WEAK or not, but now it is set only
> from !tree_could_trap_p.
>
> These patches adjust tree_could_trap_p to say that references
> to weak vars/functions may trap (for calls it was doing that already).
>
> The first version of the patch is intended for 4.7 and only handles
> that way weak vars/functions that aren't known to be defined somewhere
> (either in current CU, or in the CUs included in -flto build).
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> The second version is simplified one which always treats DECL_WEAK
> vars as maybe trapping.  Ok for 4.6?

The trunk version is ok.  For the 4.6 version, don't you need a CALL_EXPR
case similar to the trunk version?

Thanks,
Richard.

>        Jakub
>

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

* Re: [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618)
  2011-07-05  8:44 ` Richard Guenther
@ 2011-07-05  8:44   ` Jakub Jelinek
  2011-07-05  9:03     ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2011-07-05  8:44 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On Tue, Jul 05, 2011 at 10:33:28AM +0200, Richard Guenther wrote:
> On Mon, Jul 4, 2011 at 8:09 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > The second version is simplified one which always treats DECL_WEAK
> > vars as maybe trapping.  Ok for 4.6?
> 
> The trunk version is ok.  For the 4.6 version, don't you need a CALL_EXPR
> case similar to the trunk version?

No, as the 4.6 version for FUNCTION_DECLs checks just DECL_WEAK and nothing
else, what CALL_EXPR already checks is all that is needed.
The reason why I've added recursion for CALL_EXPRs for trunk is so that
all the FUNCTION_DECL/VAR_DECL cgraph/varpool lookups don't need to be
duplicated.

	Jakub

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

* Re: [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618)
  2011-07-05  8:44   ` Jakub Jelinek
@ 2011-07-05  9:03     ` Richard Guenther
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Guenther @ 2011-07-05  9:03 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Tue, Jul 5, 2011 at 10:43 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, Jul 05, 2011 at 10:33:28AM +0200, Richard Guenther wrote:
>> On Mon, Jul 4, 2011 at 8:09 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > The second version is simplified one which always treats DECL_WEAK
>> > vars as maybe trapping.  Ok for 4.6?
>>
>> The trunk version is ok.  For the 4.6 version, don't you need a CALL_EXPR
>> case similar to the trunk version?
>
> No, as the 4.6 version for FUNCTION_DECLs checks just DECL_WEAK and nothing
> else, what CALL_EXPR already checks is all that is needed.
> The reason why I've added recursion for CALL_EXPRs for trunk is so that
> all the FUNCTION_DECL/VAR_DECL cgraph/varpool lookups don't need to be
> duplicated.

Ah, yeah.

Ok for 4.6 then.

Thanks,
Richard.

>        Jakub
>

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

end of thread, other threads:[~2011-07-05  8:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-04 18:10 [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618) Jakub Jelinek
2011-07-05  8:44 ` Richard Guenther
2011-07-05  8:44   ` Jakub Jelinek
2011-07-05  9:03     ` Richard Guenther

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).