public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] avoid ICE when pretty-printing a VLA with an error bound (PR 85956)
@ 2018-05-30 20:57 Martin Sebor
  2018-05-31  8:19 ` Jakub Jelinek
  0 siblings, 1 reply; 12+ messages in thread
From: Martin Sebor @ 2018-05-30 20:57 UTC (permalink / raw)
  To: Gcc Patch List

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

The syntactically valid but undefined test case submitted in bug
85956 shows that the pretty-printer ICEs when passed a pointer
to variable-length array whose upper bound is an error-mark-node.

The ICE is triggered by -Warray-bounds discovering that a negative
subscript into the VLA is out-of-bounds and trying to mention
the type of the VLA in the diagnostic.  The error bound appears
to be the result of the omp pass.

The attached change avoids the ICE by ignoring error-mark-node
as an array bound.  It results in -Warray-bounds printing:

   array subscript -1 is below array bounds of ‘int[]’

for the VLA type.  That's not ideal because the printed type is
indistinguishable from an array with an unknown bound, but in
the absence of a valid bound I can't really think of a solution
that's much better (but see below).

Without -fopenmp, when it detects an invalid index into a VLA
-Warray-bounds might print something like:

   array subscript -1 is below array bounds of ‘int[<Uef30> + 1]’

The <Uef30> + 1 represents the variable-length upper bound.  That
doesn't seem particularly informative or helpful but since it's
unrelated to the ICE (and might come up in other diagnostics
besides -Warray-bounds) I haven't changed it in the attached
patch.

If we want to print VLAs differently in diagnostics I think it
should be done in a separate change.  One possibility is to
leave the bound out altogether as this patch does.  Another is
to use the C [*] VLA syntax.  That should turn the above into:

   array subscript -1 is below array bounds of ‘int[*]’

This notation could be used just for valid VLAs or also for
the openmp VLAs with an error upper bound if they can't be
made valid.

Martin

[-- Attachment #2: gcc-85956.diff --]
[-- Type: text/x-patch, Size: 2241 bytes --]

PR middle-end/85956 - ICE in wide_int_to_tree_1:1549

gcc/c-family/ChangeLog:

	PR middle-end/85956
	* c-pretty-print.c (c_pretty_printer::direct_abstract_declarator):
	Handle error-mark-node in array bounds gracefully.

gcc/testsuite/ChangeLog:

	PR middle-end/85956
	* gcc.dg/gomp/pr85956.c: New test.

Index: gcc/c-family/c-pretty-print.c
===================================================================
--- gcc/c-family/c-pretty-print.c	(revision 260969)
+++ gcc/c-family/c-pretty-print.c	(working copy)
@@ -570,20 +570,26 @@ c_pretty_printer::direct_abstract_declarator (tree
       break;
 
     case ARRAY_TYPE:
-      pp_c_left_bracket (this);
-      if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
-	{
-	  tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
-	  tree type = TREE_TYPE (maxval);
+      {
+	pp_c_left_bracket (this);
 
-	  if (tree_fits_shwi_p (maxval))
-	    pp_wide_integer (this, tree_to_shwi (maxval) + 1);
-	  else
-	    expression (fold_build2 (PLUS_EXPR, type, maxval,
-                                     build_int_cst (type, 1)));
-	}
-      pp_c_right_bracket (this);
-      direct_abstract_declarator (TREE_TYPE (t));
+	if (tree dom = TYPE_DOMAIN (t))
+	  {
+	    tree maxval = TYPE_MAX_VALUE (dom);
+	    if (maxval && maxval != error_mark_node)
+	      {
+		tree type = TREE_TYPE (maxval);
+
+		if (tree_fits_shwi_p (maxval))
+		  pp_wide_integer (this, tree_to_shwi (maxval) + 1);
+		else
+		  expression (fold_build2 (PLUS_EXPR, type, maxval,
+					   build_int_cst (type, 1)));
+	      }
+	  }
+	pp_c_right_bracket (this);
+	direct_abstract_declarator (TREE_TYPE (t));
+      }
       break;
 
     case IDENTIFIER_NODE:
Index: gcc/testsuite/gcc.dg/gomp/pr85956.c
===================================================================
--- gcc/testsuite/gcc.dg/gomp/pr85956.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gomp/pr85956.c	(working copy)
@@ -0,0 +1,13 @@
+/* PR middle-end/85956 - ICE in wide_int_to_tree_1, at tree.c:1549
+   { dg-do compile }
+   { dg-options "-O2 -Wall -fopenmp" } */
+
+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 "\\\[-Warray-bounds]" } */
+}

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

end of thread, other threads:[~2019-01-11 20:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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               ` [PATCH] avoid ICE when pretty-printing a VLA with an error bound (PR 85956, take 2) Jakub Jelinek
2019-01-11 20:50                 ` Jeff Law

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