From: Richard Biener Date: Wed, 16 Sep 2015 07:25:15 +0000 (+0000) Subject: re PR middle-end/67442 (GCC 5.2.0 on x86_64 creates invalid address on specific array... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87261d26850e695a2e68f1e7b6115001ee67299e;p=gcc.git re PR middle-end/67442 (GCC 5.2.0 on x86_64 creates invalid address on specific array index calculation through pointer) 2015-09-16 Richard Biener PR middle-end/67442 * fold-const.c (extract_muldiv_1): Properly extend multiplication result before builting a tree via wide_int_to_tree. * gcc.dg/torture/pr67442.c: New testcase. From-SVN: r227818 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 92ed286935c..fca25b9b867 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-09-16 Richard Biener + + PR middle-end/67442 + * fold-const.c (extract_muldiv_1): Properly extend multiplication + result before builting a tree via wide_int_to_tree. + 2015-09-16 Mikhail Maltsev * Makefile.in: Add memory-block.cc diff --git a/gcc/fold-const.c b/gcc/fold-const.c index e9366e2de6e..fd1c87ed5ad 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6166,8 +6166,12 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, && ((sign == UNSIGNED && tcode != MULT_EXPR) || sign == SIGNED)) overflow_p = true; if (!overflow_p) - return fold_build2 (tcode, ctype, fold_convert (ctype, op0), - wide_int_to_tree (ctype, mul)); + { + mul = wide_int::from (mul, TYPE_PRECISION (ctype), + TYPE_SIGN (TREE_TYPE (op1))); + return fold_build2 (tcode, ctype, fold_convert (ctype, op0), + wide_int_to_tree (ctype, mul)); + } } /* If these operations "cancel" each other, we have the main diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b4eaf3de35d..9035db974d0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-16 Richard Biener + + PR middle-end/67442 + * gcc.dg/torture/pr67442.c: New testcase. + 2015-09-15 Eric Botcazou * gnat.dg/array24.adb: New test. diff --git a/gcc/testsuite/gcc.dg/torture/pr67442.c b/gcc/testsuite/gcc.dg/torture/pr67442.c new file mode 100644 index 00000000000..bc214d62d4d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr67442.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ + +short foo[100]; + +int main() +{ + short* bar = &foo[50]; + short i = 1; + short j = 1; + short value = bar[8 - i * 2 * j]; + return value; +}