Commit a6fd2cd7 by Martin Sebor Committed by Martin Sebor

gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use…

gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use offset_int::from instead of wide_int::to_shwi.


gcc/ChangeLog:

	* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use
	offset_int::from instead of wide_int::to_shwi.
	(maybe_diag_overlap): Remove assertion.
	Use HOST_WIDE_INT_PRINT_DEC instead of %lli.
	* gimple-ssa-sprintf.c (format_directive): Same.
	(parse_directive): Same.
	(sprintf_dom_walker::compute_format_length): Same.
	(try_substitute_return_value): Same.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wrestrict-3.c: New test.

From-SVN: r256187
parent 830421fc
2018-01-03 Martin Sebor <msebor@redhat.com>
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use
offset_int::from instead of wide_int::to_shwi.
(maybe_diag_overlap): Remove assertion.
Use HOST_WIDE_INT_PRINT_DEC instead of %lli.
* gimple-ssa-sprintf.c (format_directive): Same.
(parse_directive): Same.
(sprintf_dom_walker::compute_format_length): Same.
(try_substitute_return_value): Same.
2017-01-03 Jeff Law <law@redhat.com> 2017-01-03 Jeff Law <law@redhat.com>
PR middle-end/83654 PR middle-end/83654
......
...@@ -2995,16 +2995,16 @@ format_directive (const sprintf_dom_walker::call_info &info, ...@@ -2995,16 +2995,16 @@ format_directive (const sprintf_dom_walker::call_info &info,
if (dump_file && *dir.beg) if (dump_file && *dir.beg)
{ {
fprintf (dump_file, " Result: %lli, %lli, %lli, %lli " fprintf (dump_file,
"(%lli, %lli, %lli, %lli)\n", " Result: "
(long long)fmtres.range.min, HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC ", "
(long long)fmtres.range.likely, HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC " ("
(long long)fmtres.range.max, HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC ", "
(long long)fmtres.range.unlikely, HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC ")\n",
(long long)res->range.min, fmtres.range.min, fmtres.range.likely,
(long long)res->range.likely, fmtres.range.max, fmtres.range.unlikely,
(long long)res->range.max, res->range.min, res->range.likely,
(long long)res->range.unlikely); res->range.max, res->range.unlikely);
} }
return true; return true;
...@@ -3035,11 +3035,12 @@ parse_directive (sprintf_dom_walker::call_info &info, ...@@ -3035,11 +3035,12 @@ parse_directive (sprintf_dom_walker::call_info &info,
if (dump_file) if (dump_file)
{ {
fprintf (dump_file, " Directive %u at offset %llu: \"%.*s\", " fprintf (dump_file, " Directive %u at offset "
"length = %llu\n", HOST_WIDE_INT_PRINT_UNSIGNED ": \"%.*s\", "
"length = " HOST_WIDE_INT_PRINT_UNSIGNED "\n",
dir.dirno, dir.dirno,
(unsigned long long)(size_t)(dir.beg - info.fmtstr), (unsigned HOST_WIDE_INT)(size_t)(dir.beg - info.fmtstr),
(int)dir.len, dir.beg, (unsigned long long)dir.len); (int)dir.len, dir.beg, dir.len);
} }
return len - !*str; return len - !*str;
...@@ -3411,25 +3412,34 @@ parse_directive (sprintf_dom_walker::call_info &info, ...@@ -3411,25 +3412,34 @@ parse_directive (sprintf_dom_walker::call_info &info,
if (dump_file) if (dump_file)
{ {
fprintf (dump_file, " Directive %u at offset %llu: \"%.*s\"", fprintf (dump_file,
dir.dirno, (unsigned long long)(size_t)(dir.beg - info.fmtstr), " Directive %u at offset " HOST_WIDE_INT_PRINT_UNSIGNED
": \"%.*s\"",
dir.dirno,
(unsigned HOST_WIDE_INT)(size_t)(dir.beg - info.fmtstr),
(int)dir.len, dir.beg); (int)dir.len, dir.beg);
if (star_width) if (star_width)
{ {
if (dir.width[0] == dir.width[1]) if (dir.width[0] == dir.width[1])
fprintf (dump_file, ", width = %lli", (long long)dir.width[0]); fprintf (dump_file, ", width = " HOST_WIDE_INT_PRINT_DEC,
dir.width[0]);
else else
fprintf (dump_file, ", width in range [%lli, %lli]", fprintf (dump_file,
(long long)dir.width[0], (long long)dir.width[1]); ", width in range [" HOST_WIDE_INT_PRINT_DEC
", " HOST_WIDE_INT_PRINT_DEC "]",
dir.width[0], dir.width[1]);
} }
if (star_precision) if (star_precision)
{ {
if (dir.prec[0] == dir.prec[1]) if (dir.prec[0] == dir.prec[1])
fprintf (dump_file, ", precision = %lli", (long long)dir.prec[0]); fprintf (dump_file, ", precision = " HOST_WIDE_INT_PRINT_DEC,
dir.prec[0]);
else else
fprintf (dump_file, ", precision in range [%lli, %lli]", fprintf (dump_file,
(long long)dir.prec[0], (long long)dir.prec[1]); ", precision in range [" HOST_WIDE_INT_PRINT_DEC
HOST_WIDE_INT_PRINT_DEC "]",
dir.prec[0], dir.prec[1]);
} }
fputc ('\n', dump_file); fputc ('\n', dump_file);
} }
...@@ -3455,8 +3465,10 @@ sprintf_dom_walker::compute_format_length (call_info &info, ...@@ -3455,8 +3465,10 @@ sprintf_dom_walker::compute_format_length (call_info &info,
LOCATION_FILE (callloc), LOCATION_LINE (callloc)); LOCATION_FILE (callloc), LOCATION_LINE (callloc));
print_generic_expr (dump_file, info.func, dump_flags); print_generic_expr (dump_file, info.func, dump_flags);
fprintf (dump_file, ": objsize = %llu, fmtstr = \"%s\"\n", fprintf (dump_file,
(unsigned long long)info.objsize, info.fmtstr); ": objsize = " HOST_WIDE_INT_PRINT_UNSIGNED
", fmtstr = \"%s\"\n",
info.objsize, info.fmtstr);
} }
/* Reset the minimum and maximum byte counters. */ /* Reset the minimum and maximum byte counters. */
...@@ -3682,13 +3694,14 @@ try_substitute_return_value (gimple_stmt_iterator *gsi, ...@@ -3682,13 +3694,14 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
const char *what = setrange ? "Setting" : "Discarding"; const char *what = setrange ? "Setting" : "Discarding";
if (retval[0] != retval[1]) if (retval[0] != retval[1])
fprintf (dump_file, fprintf (dump_file,
" %s %s-bounds return value range [%llu, %llu].\n", " %s %s-bounds return value range ["
what, inbounds, HOST_WIDE_INT_PRINT_UNSIGNED ", "
(unsigned long long)retval[0], HOST_WIDE_INT_PRINT_UNSIGNED "].\n",
(unsigned long long)retval[1]); what, inbounds, retval[0], retval[1]);
else else
fprintf (dump_file, " %s %s-bounds return value %llu.\n", fprintf (dump_file, " %s %s-bounds return value "
what, inbounds, (unsigned long long)retval[0]); HOST_WIDE_INT_PRINT_UNSIGNED ".\n",
what, inbounds, retval[0]);
} }
} }
......
...@@ -276,13 +276,13 @@ builtin_memref::builtin_memref (tree expr, tree size) ...@@ -276,13 +276,13 @@ builtin_memref::builtin_memref (tree expr, tree size)
value_range_type rng = get_range_info (offset, &min, &max); value_range_type rng = get_range_info (offset, &min, &max);
if (rng == VR_RANGE) if (rng == VR_RANGE)
{ {
offrange[0] = min.to_shwi (); offrange[0] = offset_int::from (min, SIGNED);
offrange[1] = max.to_shwi (); offrange[1] = offset_int::from (max, SIGNED);
} }
else if (rng == VR_ANTI_RANGE) else if (rng == VR_ANTI_RANGE)
{ {
offrange[0] = (max + 1).to_shwi (); offrange[0] = offset_int::from (max + 1, SIGNED);
offrange[1] = (min - 1).to_shwi (); offrange[1] = offset_int::from (min - 1, SIGNED);
} }
else else
{ {
...@@ -1233,25 +1233,31 @@ maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs) ...@@ -1233,25 +1233,31 @@ maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs)
if (dstref.offrange[0] == dstref.offrange[1] if (dstref.offrange[0] == dstref.offrange[1]
|| dstref.offrange[1] > HOST_WIDE_INT_MAX) || dstref.offrange[1] > HOST_WIDE_INT_MAX)
sprintf (offstr[0], "%lli", (long long) dstref.offrange[0].to_shwi ()); sprintf (offstr[0], HOST_WIDE_INT_PRINT_DEC,
dstref.offrange[0].to_shwi ());
else else
sprintf (offstr[0], "[%lli, %lli]", sprintf (offstr[0],
(long long) dstref.offrange[0].to_shwi (), "[" HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC "]",
(long long) dstref.offrange[1].to_shwi ()); dstref.offrange[0].to_shwi (),
dstref.offrange[1].to_shwi ());
if (srcref.offrange[0] == srcref.offrange[1] if (srcref.offrange[0] == srcref.offrange[1]
|| srcref.offrange[1] > HOST_WIDE_INT_MAX) || srcref.offrange[1] > HOST_WIDE_INT_MAX)
sprintf (offstr[1], "%lli", (long long) srcref.offrange[0].to_shwi ()); sprintf (offstr[1],
HOST_WIDE_INT_PRINT_DEC,
srcref.offrange[0].to_shwi ());
else else
sprintf (offstr[1], "[%lli, %lli]", sprintf (offstr[1],
(long long) srcref.offrange[0].to_shwi (), "[" HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC "]",
(long long) srcref.offrange[1].to_shwi ()); srcref.offrange[0].to_shwi (),
srcref.offrange[1].to_shwi ());
if (ovloff[0] == ovloff[1] || !ovloff[1]) if (ovloff[0] == ovloff[1] || !ovloff[1])
sprintf (offstr[2], "%lli", (long long) ovloff[0]); sprintf (offstr[2], HOST_WIDE_INT_PRINT_DEC, ovloff[0]);
else else
sprintf (offstr[2], "[%lli, %lli]", sprintf (offstr[2],
(long long) ovloff[0], (long long) ovloff[1]); "[" HOST_WIDE_INT_PRINT_DEC ", " HOST_WIDE_INT_PRINT_DEC "]",
ovloff[0], ovloff[1]);
const offset_int maxobjsize = tree_to_shwi (max_object_size ()); const offset_int maxobjsize = tree_to_shwi (max_object_size ());
bool must_overlap = ovlsiz[0] > 0; bool must_overlap = ovlsiz[0] > 0;
...@@ -1366,9 +1372,6 @@ maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs) ...@@ -1366,9 +1372,6 @@ maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs)
} }
/* Issue "may overlap" diagnostics below. */ /* Issue "may overlap" diagnostics below. */
gcc_assert (ovlsiz[0] == 0
&& ovlsiz[1] > 0
&& ovlsiz[1] <= maxobjsize.to_shwi ());
/* Use more concise wording when one of the offsets is unbounded /* Use more concise wording when one of the offsets is unbounded
to avoid confusing the user with large and mostly meaningless to avoid confusing the user with large and mostly meaningless
......
2018-01-03 Martin Sebor <msebor@redhat.com>
* gcc.dg/Wrestrict-3.c: New test.
2018-01-03 Jakub Jelinek <jakub@redhat.com> 2018-01-03 Jakub Jelinek <jakub@redhat.com>
PR c++/83555 PR c++/83555
......
/* Test to verify that the call below with the out-of-bounds offset
doesn't trigger an internal assertion and is diagnosed.
{ dg-do compile }
{ dg-options "-O2 -Wrestrict" } */
#define DIFF_MAX __PTRDIFF_MAX__
void test_no_ice (int *d, __PTRDIFF_TYPE__ i, __SIZE_TYPE__ n)
{
if (i < DIFF_MAX / sizeof *d - 1 || DIFF_MAX / sizeof *d + 2 < i)
i = DIFF_MAX / sizeof *d - 1;
if (n < DIFF_MAX)
n = DIFF_MAX / sizeof *d;
__builtin_strncpy ((char*)(d + i), (char*)d, n); /* { dg-warning "\\\[-Wrestrict]" } */
}
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