This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ICE on invalid with -Walloca-larger-than (PR tree-optimization/80109)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Aldy Hernandez <aldyh at redhat dot com>, Martin Sebor <msebor at redhat dot com>, Jeff Law <law at redhat dot com>
- Date: Mon, 20 Mar 2017 19:51:49 +0100
- Subject: [PATCH] Fix ICE on invalid with -Walloca-larger-than (PR tree-optimization/80109)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 83D5E7E9DE
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83D5E7E9DE
We crash with this invalid testcase because we aren't properly checking what we
are passing down to get_range_info, i.e., we can't pass a pointer. So fixed by
checking the argument first, and calling alloca_type_and_limit if it is of a
wrong type.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-03-20 Marek Polacek <polacek@redhat.com>
Martin Sebor <msebor@redhat.com>
PR tree-optimization/80109
* gimple-ssa-warn-alloca.c (alloca_call_type): Only call get_range_info
on INTEGRAL_TYPE_P.
* gcc.dg/Walloca-14.c: New test.
diff --git gcc/gimple-ssa-warn-alloca.c gcc/gimple-ssa-warn-alloca.c
index b940efa..ec95cc6 100644
--- gcc/gimple-ssa-warn-alloca.c
+++ gcc/gimple-ssa-warn-alloca.c
@@ -327,11 +327,20 @@ alloca_call_type (gimple *stmt, bool is_vla, tree *invalid_casted_type)
// away with better range information. But it gets
// most of the cases.
gimple *def = SSA_NAME_DEF_STMT (len);
- if (gimple_assign_cast_p (def)
- && TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def))))
+ if (gimple_assign_cast_p (def))
{
- len_casted = gimple_assign_rhs1 (def);
- range_type = get_range_info (len_casted, &min, &max);
+ tree rhs1 = gimple_assign_rhs1 (def);
+ tree rhs1type = TREE_TYPE (rhs1);
+
+ // Bail if the argument type is not valid.
+ if (!INTEGRAL_TYPE_P (rhs1type))
+ return alloca_type_and_limit (ALLOCA_OK);
+
+ if (TYPE_UNSIGNED (rhs1type))
+ {
+ len_casted = rhs1;
+ range_type = get_range_info (len_casted, &min, &max);
+ }
}
// An unknown range or a range of the entire domain is
// really no range at all.
diff --git gcc/testsuite/gcc.dg/Walloca-14.c gcc/testsuite/gcc.dg/Walloca-14.c
index e69de29..6ff2e7f 100644
--- gcc/testsuite/gcc.dg/Walloca-14.c
+++ gcc/testsuite/gcc.dg/Walloca-14.c
@@ -0,0 +1,12 @@
+/* PR tree-optimization/80109 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Walloca-larger-than=126812070" } */
+
+void
+g (int *p)
+{
+ extern void f (void *);
+
+ void *q = __builtin_alloca (p); /* { dg-warning "passing argument 1" } */
+ f (q);
+}
Marek