public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>, Richard Biener <rguenther@suse.de>
Cc: Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: [PATCH] avoid ICE when pretty-printing a VLA with an error bound (PR 85956, take 2)
Date: Mon, 07 Jan 2019 22:42:00 -0000	[thread overview]
Message-ID: <20190107224233.GS30353@tucnak> (raw)
In-Reply-To: <CADzB+2mBrpy1pmX8CNpXLGeijK1N70r=YARfx7=yMvb_htfeow@mail.gmail.com>

Hi!

On Thu, May 31, 2018 at 01:34:19PM -0400, Jason Merrill wrote:
> Returning error_mark_node from omp_copy_decl and then continuing seems
> like the problem, then.  Would it really be that hard to return an
> uninitialized variable instead?

The following patch does that, but not from omp_copy_decl, but only in the
caller for the array bounds (the rest would be still errors).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-01-07  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/85956
	PR lto/88733
	* tree-inline.h (struct copy_body_data): Add adjust_array_error_bounds
	field.
	* tree-inline.c (remap_type_1): Formatting fix.  If TYPE_MAX_VALUE of
	ARRAY_TYPE's TYPE_DOMAIN is newly error_mark_node, replace it with
	a dummy "omp dummy var" variable if id->adjust_array_error_bounds.
	* omp-low.c (new_omp_context): Set cb.adjust_array_error_bounds.
fortran/
	* trans-openmp.c: Include attribs.h.
	(gfc_walk_alloc_comps, gfc_omp_clause_linear_ctor): Handle
	VAR_DECL max bound with "omp dummy var" attribute like NULL or
	error_mark_node - recompute number of elts independently.
testsuite/
	* c-c++-common/gomp/pr85956.c: New test.
	* g++.dg/gomp/pr88733.C: New test.

--- gcc/tree-inline.h.jj	2019-01-07 12:37:38.644966905 +0100
+++ gcc/tree-inline.h	2019-01-07 18:03:27.478852009 +0100
@@ -122,6 +122,10 @@ struct copy_body_data
   /* True if the location information will need to be reset.  */
   bool reset_location;
 
+  /* Replace error_mark_node as upper bound of array types with
+     an uninitialized VAR_DECL temporary.  */
+  bool adjust_array_error_bounds;
+
   /* A function to be called when duplicating BLOCK nodes.  */
   void (*transform_lang_insert_block) (tree);
 
--- gcc/tree-inline.c.jj	2019-01-07 12:37:38.635967053 +0100
+++ gcc/tree-inline.c	2019-01-07 19:09:29.887727827 +0100
@@ -523,11 +523,27 @@ remap_type_1 (tree type, copy_body_data
 
       if (TYPE_MAIN_VARIANT (new_tree) != new_tree)
 	{
-	  gcc_checking_assert (TYPE_DOMAIN (type) == TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)));
+	  gcc_checking_assert (TYPE_DOMAIN (type)
+			       == TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)));
 	  TYPE_DOMAIN (new_tree) = TYPE_DOMAIN (TYPE_MAIN_VARIANT (new_tree));
 	}
       else
-	TYPE_DOMAIN (new_tree) = remap_type (TYPE_DOMAIN (new_tree), id);
+        {
+	  TYPE_DOMAIN (new_tree) = remap_type (TYPE_DOMAIN (new_tree), id);
+	  /* For array bounds where we have decided not to copy over the bounds
+	     variable which isn't used in OpenMP/OpenACC region, change them to
+	     an uninitialized VAR_DECL temporary.  */
+	  if (TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) == error_mark_node
+	      && id->adjust_array_error_bounds
+	      && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != error_mark_node)
+	    {
+	      tree v = create_tmp_var (TREE_TYPE (TYPE_DOMAIN (new_tree)));
+	      DECL_ATTRIBUTES (v)
+		= tree_cons (get_identifier ("omp dummy var"), NULL_TREE,
+			     DECL_ATTRIBUTES (v));
+	      TYPE_MAX_VALUE (TYPE_DOMAIN (new_tree)) = v;
+	    }
+        }
       break;
 
     case RECORD_TYPE:
--- gcc/omp-low.c.jj	2019-01-07 12:37:38.501969255 +0100
+++ gcc/omp-low.c	2019-01-07 18:03:27.509851500 +0100
@@ -872,6 +872,7 @@ new_omp_context (gimple *stmt, omp_conte
     }
 
   ctx->cb.decl_map = new hash_map<tree, tree>;
+  ctx->cb.adjust_array_error_bounds = true;
 
   return ctx;
 }
--- gcc/fortran/trans-openmp.c.jj	2019-01-01 12:37:52.699391804 +0100
+++ gcc/fortran/trans-openmp.c	2019-01-07 19:17:00.295377803 +0100
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.
 #include "diagnostic-core.h"
 #undef GCC_DIAG_STYLE
 #define GCC_DIAG_STYLE __gcc_gfc__
+#include "attribs.h"
 
 int ompws_flags;
 
@@ -297,10 +298,19 @@ gfc_walk_alloc_comps (tree decl, tree de
 	}
       else
 	{
+	  bool compute_nelts = false;
 	  if (!TYPE_DOMAIN (type)
 	      || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
 	      || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
 	      || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
+	    compute_nelts = true;
+	  else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
+	    {
+	      tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
+	      if (lookup_attribute ("omp dummy var", a))
+		compute_nelts = true;
+	    }
+	  if (compute_nelts)
 	    {
 	      tem = fold_build2 (EXACT_DIV_EXPR, sizetype,
 				 TYPE_SIZE_UNIT (type),
@@ -912,11 +922,20 @@ gfc_omp_clause_linear_ctor (tree clause,
       && (!GFC_DECL_GET_SCALAR_ALLOCATABLE (OMP_CLAUSE_DECL (clause))
 	  || !POINTER_TYPE_P (type)))
     {
+      bool compute_nelts = false;
       gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
       if (!TYPE_DOMAIN (type)
 	  || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE
 	  || TYPE_MIN_VALUE (TYPE_DOMAIN (type)) == error_mark_node
 	  || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == error_mark_node)
+	compute_nelts = true;
+      else if (VAR_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
+	{
+	  tree a = DECL_ATTRIBUTES (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
+	  if (lookup_attribute ("omp dummy var", a))
+	    compute_nelts = true;
+	}
+      if (compute_nelts)
 	{
 	  nelems = fold_build2 (EXACT_DIV_EXPR, sizetype,
 				TYPE_SIZE_UNIT (type),
--- gcc/testsuite/c-c++-common/gomp/pr85956.c.jj	2019-01-07 18:03:27.509851500 +0100
+++ gcc/testsuite/c-c++-common/gomp/pr85956.c	2019-01-07 18:03:27.509851500 +0100
@@ -0,0 +1,12 @@
+/* PR middle-end/85956 */
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -Wall" } */
+
+void
+foo (int n, void *p)
+{
+  int (*a)[n] = (int (*)[n]) p;
+  #pragma omp parallel shared(a) default(none)
+  #pragma omp master
+    a[-1][-1] = 42;	/* { dg-warning "array subscript -1 is below array bounds" } */
+}
--- gcc/testsuite/g++.dg/gomp/pr88733.C.jj	2019-01-07 19:42:10.226723145 +0100
+++ gcc/testsuite/g++.dg/gomp/pr88733.C	2019-01-07 19:41:51.200024075 +0100
@@ -0,0 +1,29 @@
+// PR lto/88733
+// { dg-do compile }
+// { dg-additional-options "-flto -ffat-lto-objects" { target lto } }
+
+struct A { int f; } a;
+
+__attribute__((noipa)) void
+bar (A **x, int)
+{
+  x[0] = &a;
+}
+
+int
+foo (int n)
+{
+  int g;
+  A *j[n];
+  bar (j, n);
+#pragma omp parallel
+#pragma omp single
+  g = j[0]->f;
+  return g;
+}
+
+int
+main ()
+{
+  foo (0);
+}


	Jakub

  parent reply	other threads:[~2019-01-07 22:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 20:57 [PATCH] avoid ICE when pretty-printing a VLA with an error bound (PR 85956) Martin Sebor
2018-05-31  8:19 ` Jakub Jelinek
2018-05-31 13:25   ` Jason Merrill
2018-05-31 13:52     ` Jakub Jelinek
2018-05-31 15:08       ` Martin Sebor
2018-05-31 15:31         ` Jason Merrill
2018-05-31 15:36           ` Jakub Jelinek
2018-05-31 17:43             ` Jason Merrill
2018-05-31 17:45               ` Jakub Jelinek
2018-06-19  0:07                 ` Martin Sebor
2019-01-07 22:42               ` Jakub Jelinek [this message]
2019-01-11 20:50                 ` [PATCH] avoid ICE when pretty-printing a VLA with an error bound (PR 85956, take 2) Jeff Law

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=20190107224233.GS30353@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=rguenther@suse.de \
    /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).