diff options
author | Martin Sebor <msebor@redhat.com> | 2018-06-12 18:05:13 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-06-12 12:05:13 -0600 |
commit | e3329a782fc0e51b9a4ddfc6938a484ec4b03084 (patch) | |
tree | 54f2c40c75f1eaadb4e09b9210721c95bda1b3a4 /gcc/gimple-ssa-warn-restrict.c | |
parent | 47feeb36526b106053ad8d4fc7a64c23ce16f5de (diff) | |
download | gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.zip gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.tar.gz gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.tar.bz2 |
PR tree-optimization/85259 - Missing -Wstringop-overflow= since r256683
gcc/ChangeLog:
PR tree-optimization/85259
* builtins.c (compute_objsize): Handle constant offsets.
* gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Return
true iff a warning has been issued.
* gimple.h (gimple_nonartificial_location): New function.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Call
gimple_nonartificial_location and handle -Wno-system-headers.
(handle_builtin_stxncpy): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/85259
* gcc.dg/Wstringop-overflow-5.c: New test.
* gcc.dg/Wstringop-overflow-6.c: New test.
From-SVN: r261518
Diffstat (limited to 'gcc/gimple-ssa-warn-restrict.c')
-rw-r--r-- | gcc/gimple-ssa-warn-restrict.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index cc50fba..7dedb24 100644 --- a/gcc/gimple-ssa-warn-restrict.c +++ b/gcc/gimple-ssa-warn-restrict.c @@ -1593,8 +1593,6 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict, loc = expansion_point_location_if_in_system_header (loc); - tree type; - char rangestr[2][64]; if (ooboff[0] == ooboff[1] || (ooboff[0] != ref.offrange[0] @@ -1605,6 +1603,8 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict, (long long) ooboff[0].to_shwi (), (long long) ooboff[1].to_shwi ()); + bool warned = false; + if (oobref == error_mark_node) { if (ref.sizrange[0] == ref.sizrange[1]) @@ -1614,6 +1614,8 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict, (long long) ref.sizrange[0].to_shwi (), (long long) ref.sizrange[1].to_shwi ()); + tree type; + if (DECL_P (ref.base) && TREE_CODE (type = TREE_TYPE (ref.base)) == ARRAY_TYPE) { @@ -1621,19 +1623,22 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict, "%G%qD pointer overflow between offset %s " "and size %s accessing array %qD with type %qT", call, func, rangestr[0], rangestr[1], ref.base, type)) - inform (DECL_SOURCE_LOCATION (ref.base), - "array %qD declared here", ref.base); + { + inform (DECL_SOURCE_LOCATION (ref.base), + "array %qD declared here", ref.base); + warned = true; + } else - warning_at (loc, OPT_Warray_bounds, - "%G%qD pointer overflow between offset %s " - "and size %s", - call, func, rangestr[0], rangestr[1]); + warned = warning_at (loc, OPT_Warray_bounds, + "%G%qD pointer overflow between offset %s " + "and size %s", + call, func, rangestr[0], rangestr[1]); } else - warning_at (loc, OPT_Warray_bounds, - "%G%qD pointer overflow between offset %s " - "and size %s", - call, func, rangestr[0], rangestr[1]); + warned = warning_at (loc, OPT_Warray_bounds, + "%G%qD pointer overflow between offset %s " + "and size %s", + call, func, rangestr[0], rangestr[1]); } else if (oobref == ref.base) { @@ -1664,22 +1669,26 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict, "of object %qD with type %qT"), call, func, rangestr[0], ref.base, TREE_TYPE (ref.base))) - inform (DECL_SOURCE_LOCATION (ref.base), - "%qD declared here", ref.base); + { + inform (DECL_SOURCE_LOCATION (ref.base), + "%qD declared here", ref.base); + warned = true; + } } else if (ref.basesize < maxobjsize) - warning_at (loc, OPT_Warray_bounds, - form - ? G_("%G%qD forming offset %s is out of the bounds " - "[0, %wu]") - : G_("%G%qD offset %s is out of the bounds [0, %wu]"), - call, func, rangestr[0], ref.basesize.to_uhwi ()); + warned = warning_at (loc, OPT_Warray_bounds, + form + ? G_("%G%qD forming offset %s is out " + "of the bounds [0, %wu]") + : G_("%G%qD offset %s is out " + "of the bounds [0, %wu]"), + call, func, rangestr[0], ref.basesize.to_uhwi ()); else - warning_at (loc, OPT_Warray_bounds, - form - ? G_("%G%qD forming offset %s is out of bounds") - : G_("%G%qD offset %s is out of bounds"), - call, func, rangestr[0]); + warned = warning_at (loc, OPT_Warray_bounds, + form + ? G_("%G%qD forming offset %s is out of bounds") + : G_("%G%qD offset %s is out of bounds"), + call, func, rangestr[0]); } else if (TREE_CODE (ref.ref) == MEM_REF) { @@ -1688,24 +1697,25 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict, type = TREE_TYPE (type); type = TYPE_MAIN_VARIANT (type); - warning_at (loc, OPT_Warray_bounds, - "%G%qD offset %s from the object at %qE is out " - "of the bounds of %qT", - call, func, rangestr[0], ref.base, type); + warned = warning_at (loc, OPT_Warray_bounds, + "%G%qD offset %s from the object at %qE is out " + "of the bounds of %qT", + call, func, rangestr[0], ref.base, type); } else { - type = TYPE_MAIN_VARIANT (TREE_TYPE (ref.ref)); - - warning_at (loc, OPT_Warray_bounds, - "%G%qD offset %s from the object at %qE is out " - "of the bounds of referenced subobject %qD with type %qT " - "at offset %wu", - call, func, rangestr[0], ref.base, TREE_OPERAND (ref.ref, 1), - type, ref.refoff.to_uhwi ()); + tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ref.ref)); + + warned = warning_at (loc, OPT_Warray_bounds, + "%G%qD offset %s from the object at %qE is out " + "of the bounds of referenced subobject %qD with " + "type %qT at offset %wu", + call, func, rangestr[0], ref.base, + TREE_OPERAND (ref.ref, 1), type, + ref.refoff.to_uhwi ()); } - return true; + return warned; } /* Check a CALL statement for restrict-violations and issue warnings @@ -1815,12 +1825,7 @@ bool check_bounds_or_overlap (gcall *call, tree dst, tree src, tree dstsize, tree srcsize, bool bounds_only /* = false */) { - location_t loc = gimple_location (call); - - if (tree block = gimple_block (call)) - if (location_t *pbloc = block_nonartificial_location (block)) - loc = *pbloc; - + location_t loc = gimple_nonartificial_location (call); loc = expansion_point_location_if_in_system_header (loc); tree func = gimple_call_fndecl (call); |