public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [committed] Avoid -Wuninitialized warnings in certain OpenMP cases (PR middle-end/70550)
Date: Wed, 06 Apr 2016 12:46:00 -0000	[thread overview]
Message-ID: <20160406124606.GW19207@tucnak.redhat.com> (raw)

Hi!

I've committed my counter-part of the recently posted OpenACC
-Wuninitialized patch.
omp-low already makes sure -Wuninitialized doesn't warn when used in shared
clause (explicit or implicit).  This patch adds to that avoidance of warning
for mapping of vars in target construct (if they aren't addressable, we
could warn), and for implicit firstprivate clauses on task/taskloop and
target constructs.
IMHO if somebody uses explicit firstprivate clause, then warning is
desirable, if the var is uninitialized, one should better use private
instead of firstprivate clause.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2016-04-06  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/70550
	* tree.h (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT): Define.
	* gimplify.c (gimplify_adjust_omp_clauses_1): Set it for implicit
	firstprivate clauses.
	* omp-low.c (lower_send_clauses): Set TREE_NO_WARNING for
	OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT !by_ref vars in task contexts.
	(lower_omp_target): Set TREE_NO_WARNING for
	non-addressable possibly uninitialized vars which are copied into
	addressable temporaries or copied for GOMP_MAP_FIRSTPRIVATE_INT.

	* c-c++-common/gomp/pr70550-1.c: New test.
	* c-c++-common/gomp/pr70550-2.c: New test.

--- gcc/tree.h.jj	2016-04-05 18:56:59.908992839 +0200
+++ gcc/tree.h	2016-04-06 10:04:46.616725165 +0200
@@ -1430,6 +1430,10 @@ extern void protected_set_expr_location
 #define OMP_CLAUSE_PRIVATE_TASKLOOP_IV(NODE) \
   TREE_PROTECTED (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_PRIVATE))
 
+/* True on a FIRSTPRIVATE clause if it has been added implicitly.  */
+#define OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT(NODE) \
+  (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FIRSTPRIVATE)->base.public_flag)
+
 /* True on a LASTPRIVATE clause if a FIRSTPRIVATE clause for the same
    decl is present in the chain.  */
 #define OMP_CLAUSE_LASTPRIVATE_FIRSTPRIVATE(NODE) \
--- gcc/gimplify.c.jj	2016-04-05 18:57:00.038991093 +0200
+++ gcc/gimplify.c	2016-04-06 10:04:46.619725124 +0200
@@ -7742,6 +7742,8 @@ gimplify_adjust_omp_clauses_1 (splay_tre
 	   && (flags & GOVD_WRITTEN) == 0
 	   && omp_shared_to_firstprivate_optimizable_decl_p (decl))
     OMP_CLAUSE_SHARED_READONLY (clause) = 1;
+  else if (code == OMP_CLAUSE_FIRSTPRIVATE && (flags & GOVD_EXPLICIT) == 0)
+    OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause) = 1;
   else if (code == OMP_CLAUSE_MAP && (flags & GOVD_MAP_0LEN_ARRAY) != 0)
     {
       tree nc = build_omp_clause (input_location, OMP_CLAUSE_MAP);
--- gcc/omp-low.c.jj	2016-04-05 18:57:00.092990368 +0200
+++ gcc/omp-low.c	2016-04-06 10:23:57.344978709 +0200
@@ -6107,8 +6107,15 @@ lower_send_clauses (tree clauses, gimple
 
       switch (OMP_CLAUSE_CODE (c))
 	{
-	case OMP_CLAUSE_PRIVATE:
 	case OMP_CLAUSE_FIRSTPRIVATE:
+	  if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c)
+	      && !by_ref
+	      && is_task_ctx (ctx))
+	    TREE_NO_WARNING (var) = 1;
+	  do_in = true;
+	  break;
+
+	case OMP_CLAUSE_PRIVATE:
 	case OMP_CLAUSE_COPYIN:
 	case OMP_CLAUSE__LOOPTEMP_:
 	  do_in = true;
@@ -16083,7 +16090,16 @@ lower_omp_target (gimple_stmt_iterator *
 			|| map_kind == GOMP_MAP_POINTER
 			|| map_kind == GOMP_MAP_TO_PSET
 			|| map_kind == GOMP_MAP_FORCE_DEVICEPTR)
-		      gimplify_assign (avar, var, &ilist);
+		      {
+			/* If we need to initialize a temporary
+			   with VAR because it is not addressable, and
+			   the variable hasn't been initialized yet, then
+			   we'll get a warning for the store to avar.
+			   Don't warn in that case, the mapping might
+			   be implicit.  */
+			TREE_NO_WARNING (var) = 1;
+			gimplify_assign (avar, var, &ilist);
+		      }
 		    avar = build_fold_addr_expr (avar);
 		    gimplify_assign (x, avar, &ilist);
 		    if ((GOMP_MAP_COPY_FROM_P (map_kind)
@@ -16252,6 +16268,8 @@ lower_omp_target (gimple_stmt_iterator *
 		tree t = var;
 		if (is_reference (var))
 		  t = build_simple_mem_ref (var);
+		else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
+		  TREE_NO_WARNING (var) = 1;
 		if (TREE_CODE (type) != POINTER_TYPE)
 		  t = fold_convert (pointer_sized_int_node, t);
 		t = fold_convert (TREE_TYPE (x), t);
@@ -16263,6 +16281,8 @@ lower_omp_target (gimple_stmt_iterator *
 	      {
 		tree avar = create_tmp_var (TREE_TYPE (var));
 		mark_addressable (avar);
+		if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c))
+		  TREE_NO_WARNING (var) = 1;
 		gimplify_assign (avar, var, &ilist);
 		avar = build_fold_addr_expr (avar);
 		gimplify_assign (x, avar, &ilist);
--- gcc/testsuite/c-c++-common/gomp/pr70550-1.c.jj	2016-04-06 10:04:46.625725042 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr70550-1.c	2016-04-06 10:04:46.625725042 +0200
@@ -0,0 +1,81 @@
+/* PR middle-end/70550 */
+/* { dg-do compile } */
+/* { dg-additional-options "-Wuninitialized" } */
+
+#ifdef __SIZEOF_INT128__
+typedef __int128 T;
+#else
+typedef long long T;
+#endif
+
+void bar (T);
+#pragma omp declare target (bar)
+
+void
+foo (void)
+{
+  {
+    int i;
+    #pragma omp target defaultmap(tofrom:scalar)	/* { dg-bogus "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target defaultmap(tofrom:scalar)	/* { dg-bogus "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+  {
+    int i;
+    #pragma omp target					/* { dg-bogus "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target					/* { dg-bogus "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+  {
+    int i;
+    #pragma omp target firstprivate (i)			/* { dg-warning "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target firstprivate (j)			/* { dg-warning "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+  {
+    int i;
+    #pragma omp target private (i)			/* { dg-bogus "is used uninitialized in this function" } */
+    {
+      i = 26;
+      bar (i);
+    }
+  }
+  {
+    T j;
+    #pragma omp target private (j)			/* { dg-bogus "is used uninitialized in this function" } */
+    {
+      j = 37;
+      bar (j);
+    }
+  }
+}
--- gcc/testsuite/c-c++-common/gomp/pr70550-2.c.jj	2016-04-06 10:28:00.704648456 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr70550-2.c	2016-04-06 10:29:48.939167321 +0200
@@ -0,0 +1,55 @@
+/* PR middle-end/70550 */
+/* { dg-do compile } */
+/* { dg-additional-options "-Wuninitialized" } */
+
+void bar (int);
+
+void
+foo (void)
+{
+  int i, j, k, l, m, n, o, p, q;
+  #pragma omp task				/* { dg-bogus "is used uninitialized in this function" } */
+  {
+    i = 2;
+    bar (i);
+  }
+  #pragma omp taskloop				/* { dg-bogus "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      k = 7;
+      bar (k);
+    }
+  #pragma omp task firstprivate (l)		/* { dg-warning "is used uninitialized in this function" } */
+  {
+    l = 2;
+    bar (l);
+  }
+  #pragma omp taskloop firstprivate (m)		/* { dg-warning "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      m = 7;
+      bar (m);
+    }
+  #pragma omp task shared (n)			/* { dg-bogus "is used uninitialized in this function" } */
+  {
+    n = 2;
+    bar (n);
+  }
+  #pragma omp taskloop shared (o)		/* { dg-bogus "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      o = 7;
+      bar (o);
+    }
+  #pragma omp task private (p)			/* { dg-bogus "is used uninitialized in this function" } */
+  {
+    p = 2;
+    bar (p);
+  }
+  #pragma omp taskloop shared (q)		/* { dg-bogus "is used uninitialized in this function" } */
+  for (j = 0; j < 10; j++)
+    {
+      q = 7;
+      bar (q);
+    }
+}

	Jakub

                 reply	other threads:[~2016-04-06 12:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160406124606.GW19207@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).