aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2014-11-19 10:49:18 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2014-11-19 10:49:18 +0100
commit5620052d3d8c020cd10d88d79eb8208433536d56 (patch)
tree979c09b8ed38c5c7392a99152555b651831af48a /gcc
parenta2a2fe4bfaff0a8e97698b92296ca760222d2605 (diff)
downloadgcc-5620052d3d8c020cd10d88d79eb8208433536d56.zip
gcc-5620052d3d8c020cd10d88d79eb8208433536d56.tar.gz
gcc-5620052d3d8c020cd10d88d79eb8208433536d56.tar.bz2
re PR sanitizer/63520 (ICE: in get_biv_step, at loop-iv.c:824 with -fsanitize=undefined on ppc64)
PR sanitizer/63520 * internal-fn.c (expand_ubsan_result_store): New function. (expand_addsub_overflow, expand_neg_overflow, expand_mul_overflow): Use it instead of just emit_move_insn. * c-c++-common/ubsan/pr63520.c: New test. From-SVN: r217758
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/internal-fn.c21
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr63520.c16
4 files changed, 46 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 172822d..eeae399 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/63520
+ * internal-fn.c (expand_ubsan_result_store): New function.
+ (expand_addsub_overflow, expand_neg_overflow, expand_mul_overflow):
+ Use it instead of just emit_move_insn.
+
2014-11-19 Richard Biener <rguenther@suse.de>
PR tree-optimization/63844
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 073d941..0cb15b2 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -395,6 +395,21 @@ expand_arith_overflow_result_store (tree lhs, rtx target,
write_complex_part (target, lres, false);
}
+/* Helper for expand_*_overflow. Store RES into TARGET. */
+
+static void
+expand_ubsan_result_store (rtx target, rtx res)
+{
+ if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
+ /* If this is a scalar in a register that is stored in a wider mode
+ than the declared mode, compute the result into its declared mode
+ and then convert to the wider mode. Our value is the computed
+ expression. */
+ convert_move (SUBREG_REG (target), res, SUBREG_PROMOTED_SIGN (target));
+ else
+ emit_move_insn (target, res);
+}
+
/* Add sub/add overflow checking to the statement STMT.
CODE says whether the operation is +, or -. */
@@ -809,7 +824,7 @@ expand_addsub_overflow (location_t loc, tree_code code, tree lhs,
if (lhs)
{
if (is_ubsan)
- emit_move_insn (target, res);
+ expand_ubsan_result_store (target, res);
else
{
if (do_xor)
@@ -904,7 +919,7 @@ expand_neg_overflow (location_t loc, tree lhs, tree arg1, bool is_ubsan)
if (lhs)
{
if (is_ubsan)
- emit_move_insn (target, res);
+ expand_ubsan_result_store (target, res);
else
expand_arith_overflow_result_store (lhs, target, mode, res);
}
@@ -1590,7 +1605,7 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, tree arg1,
if (lhs)
{
if (is_ubsan)
- emit_move_insn (target, res);
+ expand_ubsan_result_store (target, res);
else
expand_arith_overflow_result_store (lhs, target, mode, res);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c42d725..c69393c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR sanitizer/63520
+ * c-c++-common/ubsan/pr63520.c: New test.
+
2014-11-19 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/57654
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr63520.c b/gcc/testsuite/c-c++-common/ubsan/pr63520.c
new file mode 100644
index 0000000..66da668
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr63520.c
@@ -0,0 +1,16 @@
+/* PR sanitizer/63520 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+int a;
+
+void
+foo (void)
+{
+ while (1)
+ {
+ if (a == 1)
+ break;
+ a -= 1;
+ }
+}