The problem here is that as we follow the cast from an unsigned int to
__SIZE_TYPE__, we ignore the VR_ANTI_RANGE of 7 exhibited by the test in
the PR:
+void g (unsigned int n)
+{
+ if (n == 7)
+ n = 11;
+ f (__builtin_alloca (n));
+}
Since we can't get any meaningful information from VR_ANTI_RANGE as we
drill down to a cast, the appropriate thing is to drop it without
assuming it has a range. This was as oversight in not handling
VR_ANTI_RANGE gracefully, and I'll go on a limb here and say that
attached patch is obvious.
Committed to trunk.
commit 59256dfdee704d08bcd20f0576abd3353f5767cc
Author: Aldy Hernandez <al...@redhat.com>
Date: Fri Dec 2 04:42:26 2016 -0500
PR middle-end/78328
* gimple-ssa-warn-alloca.c (alloca_call_type): Handle
VR_ANTI_RANGE.
diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c
index e75f2fa..ae379f9 100644
--- a/gcc/gimple-ssa-warn-alloca.c
+++ b/gcc/gimple-ssa-warn-alloca.c
@@ -339,6 +339,8 @@ alloca_call_type (gimple *stmt, bool is_vla, tree
*invalid_casted_type)
{
// Fall through.
}
+ else if (range_type == VR_ANTI_RANGE)
+ return alloca_type_and_limit (ALLOCA_UNBOUNDED);
else if (range_type != VR_VARYING)
return
alloca_type_and_limit (ALLOCA_BOUND_MAYBE_LARGE, max);
diff --git a/gcc/testsuite/gcc.dg/Walloca-12.c
b/gcc/testsuite/gcc.dg/Walloca-12.c
new file mode 100644
index 0000000..5d71cda
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Walloca-12.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-Walloca-larger-than=128 -O2" } */
+
+void f (void*);
+
+void g (unsigned int n)
+{
+ if (n == 7)
+ n = 11;
+ f (__builtin_alloca (n)); /* { dg-warning "unbounded use of 'alloca'" } */
+}