[PR68083] don't introduce undefined behavior in ifcombine
The ifcombine pass may move a conditional access to an uninitialized value before the condition that ensures it is always well-defined, thus introducing undefined behavior. Stop it from doing so. for gcc/ChangeLog PR tree-optimization/68083 * tree-ssa-ifcombine.c: Include tree-ssa.h. (bb_no_side_effects_p): Test for undefined uses too. * tree-ssa.c (gimple_uses_undefined_value_p): New. * tree-ssa.h (gimple_uses_undefined_value_p): Declare. for gcc/testsuite/ChangeLog PR tree-optimization/68083 * gcc.dg/torture/pr68083.c: New. From Zhendong Su. From-SVN: r229690
This commit is contained in:
parent
dac7e9b819
commit
828ca3d835
7 changed files with 77 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
|||
2015-11-02 Alexandre Oliva <aoliva@redhat.com>
|
||||
|
||||
PR tree-optimization/68083
|
||||
* tree-ssa-ifcombine.c: Include tree-ssa.h.
|
||||
(bb_no_side_effects_p): Test for undefined uses too.
|
||||
* tree-ssa.c (gimple_uses_undefined_value_p): New.
|
||||
* tree-ssa.h (gimple_uses_undefined_value_p): Declare.
|
||||
|
||||
2015-10-23 Steve Ellcey <sellcey@imgtec.com>
|
||||
|
||||
* MAINTAINERS: Update email address.
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
2015-11-02 Alexandre Oliva <aoliva@redhat.com>
|
||||
|
||||
PR tree-optimization/68083
|
||||
* tree-ssa-ifcombine.c: Include tree-ssa.h.
|
||||
(bb_no_side_effects_p): Test for undefined uses too.
|
||||
* tree-ssa.c (gimple_uses_undefined_value_p): New.
|
||||
* tree-ssa.h (gimple_uses_undefined_value_p): Declare.
|
||||
|
||||
2015-11-02 Jeff Law <jeff@redhat.com>
|
||||
|
||||
* tree-ssa-threadupdate.c (valid_jump_thread_path): Also detect
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2015-11-02 Alexandre Oliva <aoliva@redhat.com>
|
||||
|
||||
PR tree-optimization/68083
|
||||
* gcc.dg/torture/pr68083.c: New. From Zhendong Su.
|
||||
|
||||
2015-11-02 Jeff Law <law@redhat.com>
|
||||
|
||||
* gcc.dg/tree-ssa/ssa-thread-11.c: Verify that we do not have
|
||||
|
|
35
gcc/testsuite/gcc.dg/torture/pr68083.c
Normal file
35
gcc/testsuite/gcc.dg/torture/pr68083.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* { dg-do run } */
|
||||
|
||||
int a = 2, b = 1, c = 1;
|
||||
|
||||
int
|
||||
fn1 ()
|
||||
{
|
||||
int d;
|
||||
for (; a; a--)
|
||||
{
|
||||
for (d = 0; d < 4; d++)
|
||||
{
|
||||
int k;
|
||||
if (c < 1)
|
||||
if (k)
|
||||
c = 0;
|
||||
if (b)
|
||||
continue;
|
||||
return 0;
|
||||
}
|
||||
b = !1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
fn1 ();
|
||||
|
||||
if (a != 1)
|
||||
__builtin_abort ();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see
|
|||
#include "gimple-iterator.h"
|
||||
#include "gimplify-me.h"
|
||||
#include "tree-cfg.h"
|
||||
#include "tree-ssa.h"
|
||||
|
||||
#ifndef LOGICAL_OP_NON_SHORT_CIRCUIT
|
||||
#define LOGICAL_OP_NON_SHORT_CIRCUIT \
|
||||
|
@ -122,6 +123,7 @@ bb_no_side_effects_p (basic_block bb)
|
|||
continue;
|
||||
|
||||
if (gimple_has_side_effects (stmt)
|
||||
|| gimple_uses_undefined_value_p (stmt)
|
||||
|| gimple_could_trap_p (stmt)
|
||||
|| gimple_vuse (stmt))
|
||||
return false;
|
||||
|
|
|
@ -1203,6 +1203,24 @@ ssa_undefined_value_p (tree t, bool partial)
|
|||
}
|
||||
|
||||
|
||||
/* Return TRUE iff STMT, a gimple statement, references an undefined
|
||||
SSA name. */
|
||||
|
||||
bool
|
||||
gimple_uses_undefined_value_p (gimple *stmt)
|
||||
{
|
||||
ssa_op_iter iter;
|
||||
tree op;
|
||||
|
||||
FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
|
||||
if (ssa_undefined_value_p (op))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* If necessary, rewrite the base of the reference tree *TP from
|
||||
a MEM_REF to a plain or converted symbol. */
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ extern bool tree_ssa_useless_type_conversion (tree);
|
|||
extern tree tree_ssa_strip_useless_type_conversions (tree);
|
||||
|
||||
extern bool ssa_undefined_value_p (tree, bool = true);
|
||||
extern bool gimple_uses_undefined_value_p (gimple *);
|
||||
extern void execute_update_addresses_taken (void);
|
||||
|
||||
/* Given an edge_var_map V, return the PHI arg definition. */
|
||||
|
|
Loading…
Add table
Reference in a new issue