Commit ca1150f0 by Jakub Jelinek Committed by Jakub Jelinek

re PR sanitizer/81981 (-fsanitize=undefined makes a -Wmaybe-uninitialized warning disappear)

	PR sanitizer/81981
	* gimple-fold.c (gimple_fold_call): Optimize away useless UBSAN_PTR
	and UBSAN_BOUNDS internal calls.  Clean up IFN_UBSAN_OBJECT_SIZE
	handling.  Use replace_call_with_value with NULL instead of
	gsi_replace, unlink_stmt_vdef and release_defs.

	* gcc.dg/ubsan/pr81981.c: New test.

From-SVN: r251641
parent 40008742
2017-09-04 Jakub Jelinek <jakub@redhat.com> 2017-09-04 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81981
* gimple-fold.c (gimple_fold_call): Optimize away useless UBSAN_PTR
and UBSAN_BOUNDS internal calls. Clean up IFN_UBSAN_OBJECT_SIZE
handling. Use replace_call_with_value with NULL instead of
gsi_replace, unlink_stmt_vdef and release_defs.
* gdbhooks.py (OptMachineModePrinter.to_string): Use 8 spaces * gdbhooks.py (OptMachineModePrinter.to_string): Use 8 spaces
instead of tab. instead of tab.
......
...@@ -3936,18 +3936,43 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace) ...@@ -3936,18 +3936,43 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
gimple_call_arg (stmt, 2)); gimple_call_arg (stmt, 2));
break; break;
case IFN_UBSAN_OBJECT_SIZE: case IFN_UBSAN_OBJECT_SIZE:
if (integer_all_onesp (gimple_call_arg (stmt, 2)) {
|| (TREE_CODE (gimple_call_arg (stmt, 1)) == INTEGER_CST tree offset = gimple_call_arg (stmt, 1);
&& TREE_CODE (gimple_call_arg (stmt, 2)) == INTEGER_CST tree objsize = gimple_call_arg (stmt, 2);
&& tree_int_cst_le (gimple_call_arg (stmt, 1), if (integer_all_onesp (objsize)
gimple_call_arg (stmt, 2)))) || (TREE_CODE (offset) == INTEGER_CST
&& TREE_CODE (objsize) == INTEGER_CST
&& tree_int_cst_le (offset, objsize)))
{
replace_call_with_value (gsi, NULL_TREE);
return true;
}
}
break;
case IFN_UBSAN_PTR:
if (integer_zerop (gimple_call_arg (stmt, 1)))
{ {
gsi_replace (gsi, gimple_build_nop (), false); replace_call_with_value (gsi, NULL_TREE);
unlink_stmt_vdef (stmt);
release_defs (stmt);
return true; return true;
} }
break; break;
case IFN_UBSAN_BOUNDS:
{
tree index = gimple_call_arg (stmt, 1);
tree bound = gimple_call_arg (stmt, 2);
if (TREE_CODE (index) == INTEGER_CST
&& TREE_CODE (bound) == INTEGER_CST)
{
index = fold_convert (TREE_TYPE (bound), index);
if (TREE_CODE (index) == INTEGER_CST
&& tree_int_cst_le (index, bound))
{
replace_call_with_value (gsi, NULL_TREE);
return true;
}
}
}
break;
case IFN_GOACC_DIM_SIZE: case IFN_GOACC_DIM_SIZE:
case IFN_GOACC_DIM_POS: case IFN_GOACC_DIM_POS:
result = fold_internal_goacc_dim (stmt); result = fold_internal_goacc_dim (stmt);
......
2017-09-04 Jakub Jelinek <jakub@redhat.com> 2017-09-04 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81981
* gcc.dg/ubsan/pr81981.c: New test.
PR tree-optimization/70043 PR tree-optimization/70043
PR testsuite/82093 PR testsuite/82093
* gfortran.dg/vect/pr70043.f90 (fn1): Start loop from 1 instead of 0. * gfortran.dg/vect/pr70043.f90 (fn1): Start loop from 1 instead of 0.
......
/* PR sanitizer/81981 */
/* { dg-do compile } */
/* { dg-options "-O2 -Wmaybe-uninitialized -fsanitize=undefined -ffat-lto-objects" } */
int v;
int
foo (int i)
{
int t[1], u[1];
int n = 0;
if (i)
{
t[n] = i;
u[0] = i;
}
v = u[0]; /* { dg-warning "may be used uninitialized in this function" } */
return t[0]; /* { dg-warning "may be used uninitialized in this function" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment