* [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809)
@ 2017-03-02 12:32 Marek Polacek
2017-03-02 12:47 ` Martin Liška
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Marek Polacek @ 2017-03-02 12:32 UTC (permalink / raw)
To: GCC Patches
As demonstrated by this test, we can crash on the assert in alloca_call_type:
gcc_assert (is_vla || warn_alloca_limit > 0);
when -Walloca-larger-than= receives an argument greater than INT_MAX. Even
though warn_vla_limit is marked as UInteger in c.opt, those are still
represented as ints; opt-functions.awk has
202 else if (flag_set_p("UInteger", flags))
203 return "int "
...
213 if (flag_set_p("UInteger", flags))
214 return "int "
So 4207115063 is converted to int which is some negative value.
It's probably too late to change opt-functions.awk now, so the following
is a badn aid fix.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-03-02 Marek Polacek <polacek@redhat.com>
PR middle-end/79809
* gimple-ssa-warn-alloca.c (pass_walloca::gate): Use HOST_WIDE_INT.
(alloca_call_type): Likewise.
* g++.dg/Walloca1.C: New test.
diff --git gcc/gimple-ssa-warn-alloca.c gcc/gimple-ssa-warn-alloca.c
index d553a34..dd41775 100644
--- gcc/gimple-ssa-warn-alloca.c
+++ gcc/gimple-ssa-warn-alloca.c
@@ -78,7 +78,8 @@ pass_walloca::gate (function *fun ATTRIBUTE_UNUSED)
if (first_time_p)
return warn_alloca != 0;
- return warn_alloca_limit > 0 || warn_vla_limit > 0;
+ return ((unsigned HOST_WIDE_INT) warn_alloca_limit > 0
+ || (unsigned HOST_WIDE_INT) warn_vla_limit > 0);
}
// Possible problematic uses of alloca.
@@ -278,8 +279,8 @@ alloca_call_type (gimple *stmt, bool is_vla, tree *invalid_casted_type)
wide_int min, max;
struct alloca_type_and_limit ret = alloca_type_and_limit (ALLOCA_UNBOUNDED);
- gcc_assert (!is_vla || warn_vla_limit > 0);
- gcc_assert (is_vla || warn_alloca_limit > 0);
+ gcc_assert (!is_vla || (unsigned HOST_WIDE_INT) warn_vla_limit > 0);
+ gcc_assert (is_vla || (unsigned HOST_WIDE_INT) warn_alloca_limit > 0);
// Adjust warn_alloca_max_size for VLAs, by taking the underlying
// type into account.
diff --git gcc/testsuite/g++.dg/Walloca1.C gcc/testsuite/g++.dg/Walloca1.C
index e69de29..23b97e8 100644
--- gcc/testsuite/g++.dg/Walloca1.C
+++ gcc/testsuite/g++.dg/Walloca1.C
@@ -0,0 +1,6 @@
+/* PR middle-end/79809 */
+/* { dg-do compile } */
+/* { dg-options "-Walloca-larger-than=4207115063 -Wvla-larger-than=1233877270 -O2" } */
+
+int a;
+char *b = static_cast<char *>(__builtin_alloca (a)); // { dg-warning "argument to .alloca. may be too large" }
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809)
2017-03-02 12:32 [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809) Marek Polacek
@ 2017-03-02 12:47 ` Martin Liška
2017-03-07 16:38 ` Jeff Law
2017-03-08 11:31 ` Andreas Schwab
2 siblings, 0 replies; 5+ messages in thread
From: Martin Liška @ 2017-03-02 12:47 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 03/02/2017 01:32 PM, Marek Polacek wrote:
> It's probably too late to change opt-functions.awk now, so the following
> is a badn aid fix.
Thanks for the patch, I've written this to my TODO list for new stage1.
It's bit connected to IntegerRange attribute which I would like to append
to options.
Martin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809)
2017-03-02 12:32 [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809) Marek Polacek
2017-03-02 12:47 ` Martin Liška
@ 2017-03-07 16:38 ` Jeff Law
2017-03-08 11:31 ` Andreas Schwab
2 siblings, 0 replies; 5+ messages in thread
From: Jeff Law @ 2017-03-07 16:38 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 03/02/2017 05:32 AM, Marek Polacek wrote:
> As demonstrated by this test, we can crash on the assert in alloca_call_type:
> gcc_assert (is_vla || warn_alloca_limit > 0);
> when -Walloca-larger-than= receives an argument greater than INT_MAX. Even
> though warn_vla_limit is marked as UInteger in c.opt, those are still
> represented as ints; opt-functions.awk has
>
> 202 else if (flag_set_p("UInteger", flags))
> 203 return "int "
> ...
> 213 if (flag_set_p("UInteger", flags))
> 214 return "int "
>
> So 4207115063 is converted to int which is some negative value.
>
> It's probably too late to change opt-functions.awk now, so the following
> is a badn aid fix.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2017-03-02 Marek Polacek <polacek@redhat.com>
>
> PR middle-end/79809
> * gimple-ssa-warn-alloca.c (pass_walloca::gate): Use HOST_WIDE_INT.
> (alloca_call_type): Likewise.
>
> * g++.dg/Walloca1.C: New test.
OK.
jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809)
2017-03-02 12:32 [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809) Marek Polacek
2017-03-02 12:47 ` Martin Liška
2017-03-07 16:38 ` Jeff Law
@ 2017-03-08 11:31 ` Andreas Schwab
2017-03-08 12:56 ` Marek Polacek
2 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2017-03-08 11:31 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Mär 02 2017, Marek Polacek <polacek@redhat.com> wrote:
> diff --git gcc/testsuite/g++.dg/Walloca1.C gcc/testsuite/g++.dg/Walloca1.C
> index e69de29..23b97e8 100644
> --- gcc/testsuite/g++.dg/Walloca1.C
> +++ gcc/testsuite/g++.dg/Walloca1.C
> @@ -0,0 +1,6 @@
> +/* PR middle-end/79809 */
> +/* { dg-do compile } */
> +/* { dg-options "-Walloca-larger-than=4207115063 -Wvla-larger-than=1233877270 -O2" } */
> +
> +int a;
> +char *b = static_cast<char *>(__builtin_alloca (a)); // { dg-warning "argument to .alloca. may be too large" }
FAIL: g++.dg/Walloca1.C -std=gnu++11 (test for warnings, line 6)
FAIL: g++.dg/Walloca1.C -std=gnu++11 (test for excess errors)
Excess errors:
/daten/aranym/gcc/gcc-20170308/gcc/testsuite/g++.dg/Walloca1.C:6:48: warning: unbounded use of 'alloca' [-Walloca-larger-than=]
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809)
2017-03-08 11:31 ` Andreas Schwab
@ 2017-03-08 12:56 ` Marek Polacek
0 siblings, 0 replies; 5+ messages in thread
From: Marek Polacek @ 2017-03-08 12:56 UTC (permalink / raw)
To: Andreas Schwab; +Cc: GCC Patches
On Wed, Mar 08, 2017 at 12:30:59PM +0100, Andreas Schwab wrote:
> On Mär 02 2017, Marek Polacek <polacek@redhat.com> wrote:
>
> > diff --git gcc/testsuite/g++.dg/Walloca1.C gcc/testsuite/g++.dg/Walloca1.C
> > index e69de29..23b97e8 100644
> > --- gcc/testsuite/g++.dg/Walloca1.C
> > +++ gcc/testsuite/g++.dg/Walloca1.C
> > @@ -0,0 +1,6 @@
> > +/* PR middle-end/79809 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-Walloca-larger-than=4207115063 -Wvla-larger-than=1233877270 -O2" } */
> > +
> > +int a;
> > +char *b = static_cast<char *>(__builtin_alloca (a)); // { dg-warning "argument to .alloca. may be too large" }
>
> FAIL: g++.dg/Walloca1.C -std=gnu++11 (test for warnings, line 6)
> FAIL: g++.dg/Walloca1.C -std=gnu++11 (test for excess errors)
> Excess errors:
> /daten/aranym/gcc/gcc-20170308/gcc/testsuite/g++.dg/Walloca1.C:6:48: warning: unbounded use of 'alloca' [-Walloca-larger-than=]
Ok, this should help:
2017-03-08 Marek Polacek <polacek@redhat.com>
* g++.dg/Walloca1.C: Adjust dg-warning.
diff --git gcc/testsuite/g++.dg/Walloca1.C gcc/testsuite/g++.dg/Walloca1.C
index 23b97e8..818c6f0 100644
--- gcc/testsuite/g++.dg/Walloca1.C
+++ gcc/testsuite/g++.dg/Walloca1.C
@@ -3,4 +3,4 @@
/* { dg-options "-Walloca-larger-than=4207115063 -Wvla-larger-than=1233877270 -O2" } */
int a;
-char *b = static_cast<char *>(__builtin_alloca (a)); // { dg-warning "argument to .alloca. may be too large" }
+char *b = static_cast<char *>(__builtin_alloca (a)); // { dg-warning "argument to .alloca. may be too large|unbounded use of" }
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-08 12:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-02 12:32 [PATCH] Fix ICE with -Walloca-larger-than=[>INT_MAX] (PR middle-end/79809) Marek Polacek
2017-03-02 12:47 ` Martin Liška
2017-03-07 16:38 ` Jeff Law
2017-03-08 11:31 ` Andreas Schwab
2017-03-08 12:56 ` Marek Polacek
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).