From: Jakub Jelinek Date: Tue, 3 Apr 2018 21:45:52 +0000 (+0200) Subject: re PR rtl-optimization/85167 (shrink-wrap.c:333:15: runtime error with UBSAN) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b6a7a294ce823917dd08e8d5923137ff75b09fae;p=gcc.git re PR rtl-optimization/85167 (shrink-wrap.c:333:15: runtime error with UBSAN) PR rtl-optimization/85167 * shrink-wrap.c (move_insn_for_shrink_wrap): Don't set bb_uses and bb_defs if *split_p, instead preinitialize it to NULL. * gcc.dg/pr85167.c: New test. From-SVN: r259058 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 78d14afe171..cd64aa46cc1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2018-04-03 Jakub Jelinek + PR rtl-optimization/85167 + * shrink-wrap.c (move_insn_for_shrink_wrap): Don't set bb_uses and + bb_defs if *split_p, instead preinitialize it to NULL. + PR tree-optimization/85156 * builtins.c (fold_builtin_expect): Use save_expr on arg1 to avoid evaluating the argument multiple times. diff --git a/gcc/shrink-wrap.c b/gcc/shrink-wrap.c index fd19acec9c1..6b47d4ea8cd 100644 --- a/gcc/shrink-wrap.c +++ b/gcc/shrink-wrap.c @@ -157,7 +157,7 @@ move_insn_for_shrink_wrap (basic_block bb, rtx_insn *insn, struct dead_debug_local *debug) { rtx set, src, dest; - bitmap live_out, live_in, bb_uses, bb_defs; + bitmap live_out, live_in, bb_uses = NULL, bb_defs = NULL; unsigned int i, dregno, end_dregno; unsigned int sregno = FIRST_PSEUDO_REGISTER; unsigned int end_sregno = FIRST_PSEUDO_REGISTER; @@ -330,8 +330,11 @@ move_insn_for_shrink_wrap (basic_block bb, rtx_insn *insn, /* Check whether BB uses DEST or clobbers DEST. We need to add INSN to BB if so. Either way, DEST is no longer live on entry, except for any part that overlaps SRC (next loop). */ - bb_uses = &DF_LR_BB_INFO (bb)->use; - bb_defs = &DF_LR_BB_INFO (bb)->def; + if (!*split_p) + { + bb_uses = &DF_LR_BB_INFO (bb)->use; + bb_defs = &DF_LR_BB_INFO (bb)->def; + } if (df_live) { for (i = dregno; i < end_dregno; i++) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d1322cb076..de14495bf9a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-04-03 Jakub Jelinek + PR rtl-optimization/85167 + * gcc.dg/pr85167.c: New test. + PR tree-optimization/85156 * c-c++-common/pr85156.c: New test. * gcc.c-torture/execute/pr85156.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr85167.c b/gcc/testsuite/gcc.dg/pr85167.c new file mode 100644 index 00000000000..e4277e3ef72 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr85167.c @@ -0,0 +1,16 @@ +/* PR rtl-optimization/85167 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -w" } */ + +struct A { long b; }; +int c, d, e; +int bar (void); + +int +foo (void) +{ + long g; + for (; g == c ? 0 : (e = 1); g = ((struct A *)g)->b) + if (bar ()) + return d; +}