This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Avoid assuming valid_constant_size_p argument is a constant expression (PR 89294)
- From: Martin Sebor <msebor at gmail dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 11 Feb 2019 18:13:50 -0700
- Subject: [PATCH] Avoid assuming valid_constant_size_p argument is a constant expression (PR 89294)
The attached patch removes the assumption introduced earlier today
in my fix for bug 87996 that the valid_constant_size_p argument is
a constant expression. I couldn't come up with a C/C++ test case
where this isn't true but apparently it can happen in Ada which I
inadvertently didn't build. I still haven't figured out what
I have to do to build it on my Fedora 29 machine so I tested
this change by hand (besides bootstrapping w/o Ada).
The first set of instructions Google gives me don't seem to do
it:
https://fedoraproject.org/wiki/Features/Ada_developer_tools
and neither does dnf install gcc-gnat as explained on our Wiki:
https://gcc.gnu.org/wiki/GNAT
If someone knows the magic chant I would be grateful (it might
be helpful to also update the Wiki page -- the last change to
it was made in 2012; I volunteer to do that).
Martin
PR middle-end/89294 - ICE in valid_constant_size_p
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.
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c (revision 268783)
+++ gcc/c-family/c-common.c (working copy)
@@ -8241,6 +8241,13 @@ invalid_array_size_error (location_t loc, cst_size
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: gcc/tree.c
===================================================================
--- gcc/tree.c (revision 268783)
+++ gcc/tree.c (working copy)
@@ -7521,8 +7521,14 @@ valid_constant_size_p (const_tree size, cst_size_e
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: gcc/tree.h
===================================================================
--- gcc/tree.h (revision 268783)
+++ gcc/tree.h (working copy)
@@ -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