public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Untested #pragma acc declare fix
@ 2016-10-07 12:21 Jakub Jelinek
  2016-10-07 19:45 ` Nathan Sidwell
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-10-07 12:21 UTC (permalink / raw)
  To: Nathan Sidwell, Thomas Schwinge, James Norris; +Cc: gcc-patches

Hi!

During review of Martin's -fsanitize-use-after-scope patch, I've noticed
what I believe is a bug in #pragma acc declare support.

In particular, the oacc_declare_returns has been added next to the CLOBBER
additions, but the clobbers are guarded with many conditions, e.g. aren't
emitted with -fstack-reuse=none and many other conditions.

I believe the additions to that data structure aren't guarded by these
conditions, it is just for VAR_DECLs that aren't is_global_var and have
current_function_decl context.

I haven't tested this patch (can bootstrap/regtest it), but don't have time
to try to write a testcase for all the cases where the conditions matter.

2016-10-07  Jakub Jelinek  <jakub@redhat.com>

	* gimplify.c (gimplify_bind_expr): Handle oacc_declare_returns
	even for -fstack-reuse=none, or for volatile vars etc.

--- gcc/gimplify.c.jj	2016-09-26 12:06:46.000000000 +0200
+++ gcc/gimplify.c	2016-10-07 14:11:09.299624104 +0200
@@ -1192,21 +1192,24 @@ gimplify_bind_expr (tree *expr_p, gimple
     {
       if (TREE_CODE (t) == VAR_DECL
 	  && !is_global_var (t)
-	  && DECL_CONTEXT (t) == current_function_decl
-	  && !DECL_HARD_REGISTER (t)
-	  && !TREE_THIS_VOLATILE (t)
-	  && !DECL_HAS_VALUE_EXPR_P (t)
-	  /* Only care for variables that have to be in memory.  Others
-	     will be rewritten into SSA names, hence moved to the top-level.  */
-	  && !is_gimple_reg (t)
-	  && flag_stack_reuse != SR_NONE)
+	  && DECL_CONTEXT (t) == current_function_decl)
 	{
-	  tree clobber = build_constructor (TREE_TYPE (t), NULL);
-	  gimple *clobber_stmt;
-	  TREE_THIS_VOLATILE (clobber) = 1;
-	  clobber_stmt = gimple_build_assign (t, clobber);
-	  gimple_set_location (clobber_stmt, end_locus);
-	  gimplify_seq_add_stmt (&cleanup, clobber_stmt);
+	  if (!DECL_HARD_REGISTER (t)
+	      && !TREE_THIS_VOLATILE (t)
+	      && !DECL_HAS_VALUE_EXPR_P (t)
+	      /* Only care for variables that have to be in memory.  Others
+		 will be rewritten into SSA names, hence moved to the
+		 top-level.  */
+	      && !is_gimple_reg (t)
+	      && flag_stack_reuse != SR_NONE)
+	    {
+	      tree clobber = build_constructor (TREE_TYPE (t), NULL);
+	      gimple *clobber_stmt;
+	      TREE_THIS_VOLATILE (clobber) = 1;
+	      clobber_stmt = gimple_build_assign (t, clobber);
+	      gimple_set_location (clobber_stmt, end_locus);
+	      gimplify_seq_add_stmt (&cleanup, clobber_stmt);
+	    }
 
 	  if (flag_openacc && oacc_declare_returns != NULL)
 	    {

	Jakub

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

* Re: [PATCH] Untested #pragma acc declare fix
  2016-10-07 12:21 [PATCH] Untested #pragma acc declare fix Jakub Jelinek
@ 2016-10-07 19:45 ` Nathan Sidwell
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2016-10-07 19:45 UTC (permalink / raw)
  To: Jakub Jelinek, Thomas Schwinge, James Norris; +Cc: gcc-patches

On 10/07/16 08:21, Jakub Jelinek wrote:
> Hi!
>
> During review of Martin's -fsanitize-use-after-scope patch, I've noticed
> what I believe is a bug in #pragma acc declare support.
>
> In particular, the oacc_declare_returns has been added next to the CLOBBER
> additions, but the clobbers are guarded with many conditions, e.g. aren't
> emitted with -fstack-reuse=none and many other conditions.
>
> I believe the additions to that data structure aren't guarded by these
> conditions, it is just for VAR_DECLs that aren't is_global_var and have
> current_function_decl context.
>
> I haven't tested this patch (can bootstrap/regtest it), but don't have time
> to try to write a testcase for all the cases where the conditions matter.

thanks, your logic seems sound.  I'll see what we can do about a test case.

nathan

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

end of thread, other threads:[~2016-10-07 19:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-07 12:21 [PATCH] Untested #pragma acc declare fix Jakub Jelinek
2016-10-07 19:45 ` Nathan Sidwell

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