From 4e1f19f0bc4b664a9dcd36acab7d722d5c862e59 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 21 Mar 2017 16:21:14 +0000 Subject: 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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@246325 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/gimple-ssa-warn-alloca.c | 17 +++++++++++++---- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/Walloca-14.c | 12 ++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Walloca-14.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 03b2a419331..2998017abd7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-03-21 Marek Polacek + Martin Sebor + + PR tree-optimization/80109 + * gimple-ssa-warn-alloca.c (alloca_call_type): Only call get_range_info + on INTEGRAL_TYPE_P. + 2017-03-21 Jakub Jelinek Segher Boessenkool diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c index b940efa910c..ec95cc6ddd8 100644 --- a/gcc/gimple-ssa-warn-alloca.c +++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a87efc180d..854726236e0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-03-21 Marek Polacek + Martin Sebor + + PR tree-optimization/80109 + * gcc.dg/Walloca-14.c: New test. + 2017-03-21 Jakub Jelinek PR target/80125 diff --git a/gcc/testsuite/gcc.dg/Walloca-14.c b/gcc/testsuite/gcc.dg/Walloca-14.c new file mode 100644 index 00000000000..6ff2e7f29c5 --- /dev/null +++ b/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); +} -- cgit v1.2.3