From 0a6ea5c9c9fb6fdc077bedeba45446c809bb6850 Mon Sep 17 00:00:00 2001 From: Meador Inge Date: Fri, 30 Aug 2013 16:36:46 +0000 Subject: [PATCH] tree-vrp.c (check_array_ref): Bail out on zero-length arrays. gcc/ 2013-08-30 Meador Inge * tree-vrp.c (check_array_ref): Bail out on zero-length arrays. gcc/testsuite/ 2013-08-30 Meador Inge * gcc.dg/Warray-bounds-11.c: New testcase. From-SVN: r202115 --- gcc/ChangeLog | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/Warray-bounds-11.c | 12 ++++++++++++ gcc/tree-vrp.c | 5 +++-- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-11.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 787040f5dc7..cbc6f8bd54f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2013-08-30 Meador Inge + + * tree-vrp.c (check_array_ref): Bail out on zero-length arrays. + 2013-08-30 Marek Polacek * Makefile.in (ubsan.o): Add. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4895bb8e3aa..144a6e60833 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-08-30 Meador Inge + + * gcc.dg/Warray-bounds-11.c: New testcase. + 2013-08-30 Marek Polacek * g++.dg/ubsan/div-by-zero-1.C: New test. diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-11.c b/gcc/testsuite/gcc.dg/Warray-bounds-11.c new file mode 100644 index 00000000000..130175d745f --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-11.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds -std=gnu99" } */ +/* Test zero-length arrays for GNU C. */ + +unsigned int a[] = { }; +unsigned int size_a; + +int test(void) +{ + /* This should not warn. */ + return size_a ? a[0] : 0; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index d5548ff55eb..062e03c5c43 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -6137,9 +6137,10 @@ check_array_ref (location_t location, tree ref, bool ignore_off_by_one) low_sub = up_sub = TREE_OPERAND (ref, 1); up_bound = array_ref_up_bound (ref); - /* Can not check flexible arrays. */ + /* Can not check flexible arrays or zero-length arrays. */ if (!up_bound - || TREE_CODE (up_bound) != INTEGER_CST) + || TREE_CODE (up_bound) != INTEGER_CST + || tree_int_cst_equal (up_bound, integer_minus_one_node)) return; /* Accesses to trailing arrays via pointers may access storage