PR middle-end/89294 - ICE in valid_constant_size_p
authorMartin Sebor <msebor@redhat.com>
Mon, 18 Feb 2019 16:31:17 +0000 (16:31 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 18 Feb 2019 16:31:17 +0000 (09:31 -0700)
gcc/c-family/ChangeLog:

PR middle-end/89294
* c-common.c (invalid_array_size_error): Handle cst_size_not_constant.

gcc/ChangeLog:

PR middle-end/89294
* tree.c (valid_constant_size_p): Avoid assuming size is a constant
expression.
* tree.h (cst_size_error): Add the cst_size_not_constant enumerator.

From-SVN: r268990

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/tree.c
gcc/tree.h

index bf74a0af23438dc3063d0b9e9bb0b604b96f9415..3caa28a8cca0b18b7a5881f3a82d319191e1f28e 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-18  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/89294
+       * tree.c (valid_constant_size_p): Avoid assuming size is a constant
+       expression.
+       * tree.h (cst_size_error): Add the cst_size_not_constant enumerator.
+
 2019-02-18  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/89296
index ed8026a33e098eed12567a745a61f8cddcbd2a75..2d3839ee5a7bf402cfbb2bc0038d7a493ecd6837 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-18  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/89294
+       * c-common.c (invalid_array_size_error): Handle cst_size_not_constant.
+
 2019-02-16  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/88680
index c6856c9ad103402d12e784d498a995fffdc2af9f..e5a5ea803d725895c569d213639995228f27653b 100644 (file)
@@ -8248,6 +8248,13 @@ invalid_array_size_error (location_t loc, cst_size_error error,
   tree maxsize = max_object_size ();
   switch (error)
     {
+    case cst_size_not_constant:
+      if (name)
+       error_at (loc, "size of array %qE is not a constant expression",
+                 name);
+      else
+       error_at (loc, "size of array is not a constant expression");
+      break;
     case cst_size_negative:
       if (name)
        error_at (loc, "size %qE of array %qE is negative",
index af7abd87b7ab53665fed1f839e486c8e42b5adc6..30e01df0ace64ac8ad11f92d7d90b8d94aee9798 100644 (file)
@@ -7521,7 +7521,13 @@ valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */)
   if (!perr)
     perr = &error;
 
-  if (TREE_OVERFLOW (size))
+  if (TREE_CODE (size) != INTEGER_CST)
+    {
+      *perr = cst_size_not_constant;
+      return false;
+    }
+
+  if (TREE_OVERFLOW_P (size))
     {
       *perr = cst_size_overflow;
       return false;
index 96d84d961c58a834eaa76ad33b119219fe07fcc6..0e8e8dff87607d206c60cb36e967fce69c402ab1 100644 (file)
@@ -4352,6 +4352,7 @@ extern tree excess_precision_type (tree);
    is not a valid size.  */
 enum cst_size_error {
   cst_size_ok,
+  cst_size_not_constant,
   cst_size_negative,
   cst_size_too_big,
   cst_size_overflow