Commit 346114b5 by Jakub Jelinek Committed by Jakub Jelinek

substring-locations.h (format_warning_va): Formatting fix for ATTRIBUTE_GCC_DIAG.

	* substring-locations.h (format_warning_va): Formatting fix for
	ATTRIBUTE_GCC_DIAG.
	(format_warning_at_substring): Fix up ATTRIBUTE_GCC_DIAG second
	argument.
	(format_warning_n_va, format_warning_at_substring_n): New prototypes.
	* substring-locations.c: Include intl.h.
	(format_warning_va): Turned into small wrapper around
	format_warning_n_va, renamed to ...
	(format_warning_n_va): ... this, add N and PLURAL_GMSGID arguments,
	rename GMSGID to SINGULAR_GMSGID, if SINGULAR_GMSGID != PLURAL_GMSGID,
	use ngettext.
	(format_warning_at_substring_n): New function.
	* gimple-ssa-sprintf.c: Remove GCC diagnostic ignored pragma.
	(fmtwarn): Add ATTRIBUTE_GCC_DIAG.  Turn into a copy of
	format_warning_at_substring with just a shorter name instead of
	const function pointer.
	(fmtwarn_n): New function.
	(maybe_warn, format_directive, parse_directive): Use fmtwarn_n where
	appropriate, get rid of all the fmtstr temporaries, move conditionals
	with G_() wrapped string literals directly into fmtwarn arguments,
	cast dir.len to (int), formatting fixes.

From-SVN: r258154
parent 892870f9
2018-03-02 Jakub Jelinek <jakub@redhat.com>
* substring-locations.h (format_warning_va): Formatting fix for
ATTRIBUTE_GCC_DIAG.
(format_warning_at_substring): Fix up ATTRIBUTE_GCC_DIAG second
argument.
(format_warning_n_va, format_warning_at_substring_n): New prototypes.
* substring-locations.c: Include intl.h.
(format_warning_va): Turned into small wrapper around
format_warning_n_va, renamed to ...
(format_warning_n_va): ... this, add N and PLURAL_GMSGID arguments,
rename GMSGID to SINGULAR_GMSGID, if SINGULAR_GMSGID != PLURAL_GMSGID,
use ngettext.
(format_warning_at_substring_n): New function.
* gimple-ssa-sprintf.c: Remove GCC diagnostic ignored pragma.
(fmtwarn): Add ATTRIBUTE_GCC_DIAG. Turn into a copy of
format_warning_at_substring with just a shorter name instead of
const function pointer.
(fmtwarn_n): New function.
(maybe_warn, format_directive, parse_directive): Use fmtwarn_n where
appropriate, get rid of all the fmtstr temporaries, move conditionals
with G_() wrapped string literals directly into fmtwarn arguments,
cast dir.len to (int), formatting fixes.
2018-03-02 Thomas Schwinge <thomas@codesourcery.com> 2018-03-02 Thomas Schwinge <thomas@codesourcery.com>
* doc/invoke.texi: Remove "Cilk Plus" references. * doc/invoke.texi: Remove "Cilk Plus" references.
......
...@@ -589,18 +589,40 @@ get_format_string (tree format, location_t *ploc) ...@@ -589,18 +589,40 @@ get_format_string (tree format, location_t *ploc)
return fmtstr; return fmtstr;
} }
/* The format_warning_at_substring function is not used here in a way /* For convenience and brevity, shorter named entrypoints of
that makes using attribute format viable. Suppress the warning. */ format_warning_at_substring and format_warning_at_substring_n.
These have to be functions with the attribute so that exgettext
works properly. */
#pragma GCC diagnostic push static bool
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" ATTRIBUTE_GCC_DIAG (5, 6)
fmtwarn (const substring_loc &fmt_loc, location_t param_loc,
const char *corrected_substring, int opt, const char *gmsgid, ...)
{
va_list ap;
va_start (ap, gmsgid);
bool warned = format_warning_va (fmt_loc, param_loc, corrected_substring,
opt, gmsgid, &ap);
va_end (ap);
/* For convenience and brevity. */ return warned;
}
static bool static bool
(* const fmtwarn) (const substring_loc &, location_t, ATTRIBUTE_GCC_DIAG (6, 8) ATTRIBUTE_GCC_DIAG (7, 8)
const char *, int, const char *, ...) fmtwarn_n (const substring_loc &fmt_loc, location_t param_loc,
= format_warning_at_substring; const char *corrected_substring, int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
va_list ap;
va_start (ap, plural_gmsgid);
bool warned = format_warning_n_va (fmt_loc, param_loc, corrected_substring,
opt, n, singular_gmsgid, plural_gmsgid,
&ap);
va_end (ap);
return warned;
}
/* Format length modifiers. */ /* Format length modifiers. */
...@@ -2489,113 +2511,105 @@ maybe_warn (substring_loc &dirloc, location_t argloc, ...@@ -2489,113 +2511,105 @@ maybe_warn (substring_loc &dirloc, location_t argloc,
/* This is the terminating nul. */ /* This is the terminating nul. */
gcc_assert (res.min == 1 && res.min == res.max); gcc_assert (res.min == 1 && res.min == res.max);
const char *fmtstr
= (info.bounded
? (maybe
? G_("%qE output may be truncated before the last format "
"character")
: G_("%qE output truncated before the last format character"))
: (maybe
? G_("%qE may write a terminating nul past the end "
"of the destination")
: G_("%qE writing a terminating nul past the end "
"of the destination")));
return fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (), return fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (),
fmtstr, info.func); info.bounded
? (maybe
? G_("%qE output may be truncated before the "
"last format character")
: G_("%qE output truncated before the last "
"format character"))
: (maybe
? G_("%qE may write a terminating nul past the "
"end of the destination")
: G_("%qE writing a terminating nul past the "
"end of the destination")),
info.func);
} }
if (res.min == res.max) if (res.min == res.max)
{ {
const char* fmtstr const char *d = target_to_host (hostdir, sizeof hostdir, dir.beg);
= (res.min == 1 if (!info.bounded)
? (info.bounded return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min,
? (maybe "%<%.*s%> directive writing %wu byte into a "
? G_("%<%.*s%> directive output may be truncated writing " "region of size %wu",
"%wu byte into a region of size %wu") "%<%.*s%> directive writing %wu bytes into a "
: G_("%<%.*s%> directive output truncated writing " "region of size %wu",
"%wu byte into a region of size %wu")) (int) dir.len, d, res.min, navail);
: G_("%<%.*s%> directive writing %wu byte " else if (maybe)
"into a region of size %wu")) return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min,
: (info.bounded "%<%.*s%> directive output may be truncated "
? (maybe "writing %wu byte into a region of size %wu",
? G_("%<%.*s%> directive output may be truncated writing " "%<%.*s%> directive output may be truncated "
"%wu bytes into a region of size %wu") "writing %wu bytes into a region of size %wu",
: G_("%<%.*s%> directive output truncated writing " (int) dir.len, d, res.min, navail);
"%wu bytes into a region of size %wu")) else
: G_("%<%.*s%> directive writing %wu bytes " return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min,
"into a region of size %wu"))); "%<%.*s%> directive output truncated writing "
return fmtwarn (dirloc, argloc, NULL, "%wu byte into a region of size %wu",
info.warnopt (), fmtstr, dir.len, "%<%.*s%> directive output truncated writing "
target_to_host (hostdir, sizeof hostdir, dir.beg), "%wu bytes into a region of size %wu",
res.min, navail); (int) dir.len, d, res.min, navail);
} }
if (res.min == 0 && res.max < maxbytes) if (res.min == 0 && res.max < maxbytes)
{ return fmtwarn (dirloc, argloc, NULL,
const char* fmtstr info.warnopt (),
= (info.bounded info.bounded
? (maybe ? (maybe
? G_("%<%.*s%> directive output may be truncated writing " ? G_("%<%.*s%> directive output may be truncated "
"up to %wu bytes into a region of size %wu") "writing up to %wu bytes into a region of "
: G_("%<%.*s%> directive output truncated writing " "size %wu")
"up to %wu bytes into a region of size %wu")) : G_("%<%.*s%> directive output truncated writing "
: G_("%<%.*s%> directive writing up to %wu bytes " "up to %wu bytes into a region of size %wu"))
"into a region of size %wu")); : G_("%<%.*s%> directive writing up to %wu bytes "
return fmtwarn (dirloc, argloc, NULL, "into a region of size %wu"), (int) dir.len,
info.warnopt (), fmtstr, dir.len, target_to_host (hostdir, sizeof hostdir, dir.beg),
target_to_host (hostdir, sizeof hostdir, dir.beg), res.max, navail);
res.max, navail);
}
if (res.min == 0 && maxbytes <= res.max) if (res.min == 0 && maxbytes <= res.max)
{ /* This is a special case to avoid issuing the potentially
/* This is a special case to avoid issuing the potentially confusing warning:
confusing warning: writing 0 or more bytes into a region of size 0. */
writing 0 or more bytes into a region of size 0. */ return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char* fmtstr info.bounded
= (info.bounded ? (maybe
? (maybe ? G_("%<%.*s%> directive output may be truncated "
? G_("%<%.*s%> directive output may be truncated writing " "writing likely %wu or more bytes into a "
"likely %wu or more bytes into a region of size %wu") "region of size %wu")
: G_("%<%.*s%> directive output truncated writing " : G_("%<%.*s%> directive output truncated writing "
"likely %wu or more bytes into a region of size %wu")) "likely %wu or more bytes into a region of "
: G_("%<%.*s%> directive writing likely %wu or more bytes " "size %wu"))
"into a region of size %wu")); : G_("%<%.*s%> directive writing likely %wu or more "
return fmtwarn (dirloc, argloc, NULL, "bytes into a region of size %wu"), (int) dir.len,
info.warnopt (), fmtstr, dir.len, target_to_host (hostdir, sizeof hostdir, dir.beg),
target_to_host (hostdir, sizeof hostdir, dir.beg), res.likely, navail);
res.likely, navail);
}
if (res.max < maxbytes) if (res.max < maxbytes)
{ return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char* fmtstr info.bounded
= (info.bounded ? (maybe
? (maybe ? G_("%<%.*s%> directive output may be truncated "
? G_("%<%.*s%> directive output may be truncated writing " "writing between %wu and %wu bytes into a "
"between %wu and %wu bytes into a region of size %wu") "region of size %wu")
: G_("%<%.*s%> directive output truncated writing " : G_("%<%.*s%> directive output truncated "
"between %wu and %wu bytes into a region of size %wu")) "writing between %wu and %wu bytes into a "
: G_("%<%.*s%> directive writing between %wu and " "region of size %wu"))
"%wu bytes into a region of size %wu")); : G_("%<%.*s%> directive writing between %wu and "
return fmtwarn (dirloc, argloc, NULL, "%wu bytes into a region of size %wu"),
info.warnopt (), fmtstr, dir.len, (int) dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg), target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, res.max, navail); res.min, res.max, navail);
}
return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char* fmtstr info.bounded
= (info.bounded ? (maybe
? (maybe ? G_("%<%.*s%> directive output may be truncated "
? G_("%<%.*s%> directive output may be truncated writing " "writing %wu or more bytes into a region of "
"%wu or more bytes into a region of size %wu") "size %wu")
: G_("%<%.*s%> directive output truncated writing " : G_("%<%.*s%> directive output truncated writing "
"%wu or more bytes into a region of size %wu")) "%wu or more bytes into a region of size %wu"))
: G_("%<%.*s%> directive writing %wu or more bytes " : G_("%<%.*s%> directive writing %wu or more bytes "
"into a region of size %wu")); "into a region of size %wu"), (int) dir.len,
return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg), target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, navail); res.min, navail);
} }
...@@ -2617,122 +2631,111 @@ maybe_warn (substring_loc &dirloc, location_t argloc, ...@@ -2617,122 +2631,111 @@ maybe_warn (substring_loc &dirloc, location_t argloc,
{ {
gcc_assert (res.min == 1 && res.min == res.max); gcc_assert (res.min == 1 && res.min == res.max);
const char *fmtstr return fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (),
= (info.bounded info.bounded
? (maybe ? (maybe
? G_("%qE output may be truncated before the last format " ? G_("%qE output may be truncated before the last "
"character") "format character")
: G_("%qE output truncated before the last format character")) : G_("%qE output truncated before the last format "
: (maybe "character"))
? G_("%qE may write a terminating nul past the end " : (maybe
"of the destination") ? G_("%qE may write a terminating nul past the end "
: G_("%qE writing a terminating nul past the end " "of the destination")
"of the destination"))); : G_("%qE writing a terminating nul past the end "
"of the destination")), info.func);
return fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (), fmtstr,
info.func);
} }
if (res.min == res.max) if (res.min == res.max)
{ {
const char* fmtstr const char *d = target_to_host (hostdir, sizeof hostdir, dir.beg);
= (res.min == 1 if (!info.bounded)
? (info.bounded return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min,
? (maybe "%<%.*s%> directive writing %wu byte into a region "
? G_("%<%.*s%> directive output may be truncated writing " "of size between %wu and %wu",
"%wu byte into a region of size between %wu and %wu") "%<%.*s%> directive writing %wu bytes into a region "
: G_("%<%.*s%> directive output truncated writing " "of size between %wu and %wu", (int) dir.len, d,
"%wu byte into a region of size between %wu and %wu")) res.min, avail_range.min, avail_range.max);
: G_("%<%.*s%> directive writing %wu byte " else if (maybe)
"into a region of size between %wu and %wu")) return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min,
: (info.bounded "%<%.*s%> directive output may be truncated writing "
? (maybe "%wu byte into a region of size between %wu and %wu",
? G_("%<%.*s%> directive output may be truncated writing " "%<%.*s%> directive output may be truncated writing "
"%wu bytes into a region of size between %wu and %wu") "%wu bytes into a region of size between %wu and "
: G_("%<%.*s%> directive output truncated writing " "%wu", (int) dir.len, d, res.min, avail_range.min,
"%wu bytes into a region of size between %wu and %wu")) avail_range.max);
: G_("%<%.*s%> directive writing %wu bytes " else
"into a region of size between %wu and %wu"))); return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min,
"%<%.*s%> directive output truncated writing %wu "
return fmtwarn (dirloc, argloc, NULL, "byte into a region of size between %wu and %wu",
info.warnopt (), fmtstr, dir.len, "%<%.*s%> directive output truncated writing %wu "
target_to_host (hostdir, sizeof hostdir, dir.beg), "bytes into a region of size between %wu and %wu",
res.min, avail_range.min, avail_range.max); (int) dir.len, d, res.min, avail_range.min,
avail_range.max);
} }
if (res.min == 0 && res.max < maxbytes) if (res.min == 0 && res.max < maxbytes)
{ return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char* fmtstr info.bounded
= (info.bounded ? (maybe
? (maybe ? G_("%<%.*s%> directive output may be truncated "
? G_("%<%.*s%> directive output may be truncated writing " "writing up to %wu bytes into a region of size "
"up to %wu bytes into a region of size between " "between %wu and %wu")
"%wu and %wu") : G_("%<%.*s%> directive output truncated writing "
: G_("%<%.*s%> directive output truncated writing " "up to %wu bytes into a region of size between "
"up to %wu bytes into a region of size between " "%wu and %wu"))
"%wu and %wu")) : G_("%<%.*s%> directive writing up to %wu bytes "
: G_("%<%.*s%> directive writing up to %wu bytes " "into a region of size between %wu and %wu"),
"into a region of size between %wu and %wu")); (int) dir.len,
return fmtwarn (dirloc, argloc, NULL, target_to_host (hostdir, sizeof hostdir, dir.beg),
info.warnopt (), fmtstr, dir.len, res.max, avail_range.min, avail_range.max);
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.max, avail_range.min, avail_range.max);
}
if (res.min == 0 && maxbytes <= res.max) if (res.min == 0 && maxbytes <= res.max)
{ /* This is a special case to avoid issuing the potentially confusing
/* This is a special case to avoid issuing the potentially confusing warning:
warning: writing 0 or more bytes into a region of size between 0 and N. */
writing 0 or more bytes into a region of size between 0 and N. */ return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char* fmtstr info.bounded
= (info.bounded ? (maybe
? (maybe ? G_("%<%.*s%> directive output may be truncated "
? G_("%<%.*s%> directive output may be truncated writing " "writing likely %wu or more bytes into a region "
"likely %wu or more bytes into a region of size between " "of size between %wu and %wu")
"%wu and %wu") : G_("%<%.*s%> directive output truncated writing "
: G_("%<%.*s%> directive output truncated writing likely " "likely %wu or more bytes into a region of size "
"%wu or more bytes into a region of size between " "between %wu and %wu"))
"%wu and %wu")) : G_("%<%.*s%> directive writing likely %wu or more bytes "
: G_("%<%.*s%> directive writing likely %wu or more bytes " "into a region of size between %wu and %wu"),
"into a region of size between %wu and %wu")); (int) dir.len,
return fmtwarn (dirloc, argloc, NULL, target_to_host (hostdir, sizeof hostdir, dir.beg),
info.warnopt (), fmtstr, dir.len, res.likely, avail_range.min, avail_range.max);
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.likely, avail_range.min, avail_range.max);
}
if (res.max < maxbytes) if (res.max < maxbytes)
{ return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char* fmtstr info.bounded
= (info.bounded ? (maybe
? (maybe ? G_("%<%.*s%> directive output may be truncated "
? G_("%<%.*s%> directive output may be truncated writing " "writing between %wu and %wu bytes into a region "
"between %wu and %wu bytes into a region of size " "of size between %wu and %wu")
"between %wu and %wu") : G_("%<%.*s%> directive output truncated writing "
: G_("%<%.*s%> directive output truncated writing " "between %wu and %wu bytes into a region of size "
"between %wu and %wu bytes into a region of size " "between %wu and %wu"))
"between %wu and %wu")) : G_("%<%.*s%> directive writing between %wu and "
: G_("%<%.*s%> directive writing between %wu and " "%wu bytes into a region of size between %wu and "
"%wu bytes into a region of size between %wu and %wu")); "%wu"), (int) dir.len,
return fmtwarn (dirloc, argloc, NULL, target_to_host (hostdir, sizeof hostdir, dir.beg),
info.warnopt (), fmtstr, dir.len, res.min, res.max, avail_range.min, avail_range.max);
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, res.max, avail_range.min, avail_range.max); return fmtwarn (dirloc, argloc, NULL, info.warnopt (),
} info.bounded
? (maybe
const char* fmtstr ? G_("%<%.*s%> directive output may be truncated writing "
= (info.bounded "%wu or more bytes into a region of size between "
? (maybe "%wu and %wu")
? G_("%<%.*s%> directive output may be truncated writing " : G_("%<%.*s%> directive output truncated writing "
"%wu or more bytes into a region of size between " "%wu or more bytes into a region of size between "
"%wu and %wu") "%wu and %wu"))
: G_("%<%.*s%> directive output truncated writing " : G_("%<%.*s%> directive writing %wu or more bytes "
"%wu or more bytes into a region of size between " "into a region of size between %wu and %wu"),
"%wu and %wu")) (int) dir.len,
: G_("%<%.*s%> directive writing %wu or more bytes "
"into a region of size between %wu and %wu"));
return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg), target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, avail_range.min, avail_range.max); res.min, avail_range.min, avail_range.max);
} }
...@@ -2883,27 +2886,22 @@ format_directive (const sprintf_dom_walker::call_info &info, ...@@ -2883,27 +2886,22 @@ format_directive (const sprintf_dom_walker::call_info &info,
(like Glibc does under some conditions). */ (like Glibc does under some conditions). */
if (fmtres.range.min == fmtres.range.max) if (fmtres.range.min == fmtres.range.max)
warned = fmtwarn (dirloc, argloc, NULL, warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (),
info.warnopt (),
"%<%.*s%> directive output of %wu bytes exceeds " "%<%.*s%> directive output of %wu bytes exceeds "
"minimum required size of 4095", "minimum required size of 4095", dirlen,
dirlen,
target_to_host (hostdir, sizeof hostdir, dir.beg), target_to_host (hostdir, sizeof hostdir, dir.beg),
fmtres.range.min); fmtres.range.min);
else else
{ warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char *fmtstr minunder4k
= (minunder4k ? G_("%<%.*s%> directive output between %wu and %wu "
? G_("%<%.*s%> directive output between %wu and %wu " "bytes may exceed minimum required size of "
"bytes may exceed minimum required size of 4095") "4095")
: G_("%<%.*s%> directive output between %wu and %wu " : G_("%<%.*s%> directive output between %wu and %wu "
"bytes exceeds minimum required size of 4095")); "bytes exceeds minimum required size of 4095"),
dirlen,
warned = fmtwarn (dirloc, argloc, NULL, target_to_host (hostdir, sizeof hostdir, dir.beg),
info.warnopt (), fmtstr, dirlen, fmtres.range.min, fmtres.range.max);
target_to_host (hostdir, sizeof hostdir, dir.beg),
fmtres.range.min, fmtres.range.max);
}
} }
/* Has the likely and maximum directive output exceeded INT_MAX? */ /* Has the likely and maximum directive output exceeded INT_MAX? */
...@@ -2929,29 +2927,24 @@ format_directive (const sprintf_dom_walker::call_info &info, ...@@ -2929,29 +2927,24 @@ format_directive (const sprintf_dom_walker::call_info &info,
if (fmtres.range.min == fmtres.range.max) if (fmtres.range.min == fmtres.range.max)
warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (), warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (),
"%<%.*s%> directive output of %wu bytes causes " "%<%.*s%> directive output of %wu bytes causes "
"result to exceed %<INT_MAX%>", "result to exceed %<INT_MAX%>", dirlen,
dirlen,
target_to_host (hostdir, sizeof hostdir, dir.beg), target_to_host (hostdir, sizeof hostdir, dir.beg),
fmtres.range.min); fmtres.range.min);
else else
{ warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (),
const char *fmtstr fmtres.range.min > target_int_max ()
= (fmtres.range.min > target_int_max () ? G_ ("%<%.*s%> directive output between %wu and "
? G_ ("%<%.*s%> directive output between %wu and %wu " "%wu bytes causes result to exceed "
"bytes causes result to exceed %<INT_MAX%>") "%<INT_MAX%>")
: G_ ("%<%.*s%> directive output between %wu and %wu " : G_ ("%<%.*s%> directive output between %wu and "
"bytes may cause result to exceed %<INT_MAX%>")); "%wu bytes may cause result to exceed "
warned = fmtwarn (dirloc, argloc, NULL, "%<INT_MAX%>"), dirlen,
info.warnopt (), fmtstr, dirlen, target_to_host (hostdir, sizeof hostdir, dir.beg),
target_to_host (hostdir, sizeof hostdir, dir.beg), fmtres.range.min, fmtres.range.max);
fmtres.range.min, fmtres.range.max);
}
} }
if (warned && fmtres.range.min < fmtres.range.likely if (warned && fmtres.range.min < fmtres.range.likely
&& fmtres.range.likely < fmtres.range.max) && fmtres.range.likely < fmtres.range.max)
/* Some languages have special plural rules even for large values,
but it is periodic with period of 10, 100, 1000 etc. */
inform_n (info.fmtloc, fmtres.range.likely, inform_n (info.fmtloc, fmtres.range.likely,
"assuming directive output of %wu byte", "assuming directive output of %wu byte",
"assuming directive output of %wu bytes", "assuming directive output of %wu bytes",
...@@ -3022,8 +3015,6 @@ format_directive (const sprintf_dom_walker::call_info &info, ...@@ -3022,8 +3015,6 @@ format_directive (const sprintf_dom_walker::call_info &info,
return true; return true;
} }
#pragma GCC diagnostic pop
/* Parse a format directive in function call described by INFO starting /* Parse a format directive in function call described by INFO starting
at STR and populate DIR structure. Bump up *ARGNO by the number of at STR and populate DIR structure. Bump up *ARGNO by the number of
arguments extracted for the directive. Return the length of arguments extracted for the directive. Return the length of
...@@ -3373,9 +3364,9 @@ parse_directive (sprintf_dom_walker::call_info &info, ...@@ -3373,9 +3364,9 @@ parse_directive (sprintf_dom_walker::call_info &info,
substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format), substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format),
caret, begin, end); caret, begin, end);
fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (),
info.warnopt (), "%<%.*s%> directive width out of range", "%<%.*s%> directive width out of range", (int) dir.len,
dir.len, target_to_host (hostdir, sizeof hostdir, dir.beg)); target_to_host (hostdir, sizeof hostdir, dir.beg));
} }
dir.set_width (width); dir.set_width (width);
...@@ -3407,9 +3398,9 @@ parse_directive (sprintf_dom_walker::call_info &info, ...@@ -3407,9 +3398,9 @@ parse_directive (sprintf_dom_walker::call_info &info,
substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format), substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format),
caret, begin, end); caret, begin, end);
fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (),
info.warnopt (), "%<%.*s%> directive precision out of range", "%<%.*s%> directive precision out of range", (int) dir.len,
dir.len, target_to_host (hostdir, sizeof hostdir, dir.beg)); target_to_host (hostdir, sizeof hostdir, dir.beg));
} }
dir.set_precision (precision); dir.set_precision (precision);
......
...@@ -20,14 +20,17 @@ along with GCC; see the file COPYING3. If not see ...@@ -20,14 +20,17 @@ along with GCC; see the file COPYING3. If not see
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "coretypes.h" #include "coretypes.h"
#include "intl.h"
#include "diagnostic.h" #include "diagnostic.h"
#include "cpplib.h" #include "cpplib.h"
#include "tree.h" #include "tree.h"
#include "langhooks.h" #include "langhooks.h"
#include "substring-locations.h" #include "substring-locations.h"
/* Emit a warning governed by option OPT, using GMSGID as the format /* Emit a warning governed by option OPT, using SINGULAR_GMSGID as the
string and AP as its arguments. format string (or if PLURAL_GMSGID is different from SINGULAR_GMSGID,
using SINGULAR_GMSGID, PLURAL_GMSGID and N as arguments to ngettext)
and AP as its arguments.
Attempt to obtain precise location information within a string Attempt to obtain precise location information within a string
literal from FMT_LOC. literal from FMT_LOC.
...@@ -97,12 +100,13 @@ along with GCC; see the file COPYING3. If not see ...@@ -97,12 +100,13 @@ along with GCC; see the file COPYING3. If not see
Return true if a warning was emitted, false otherwise. */ Return true if a warning was emitted, false otherwise. */
ATTRIBUTE_GCC_DIAG (5,0)
bool bool
format_warning_va (const substring_loc &fmt_loc, format_warning_n_va (const substring_loc &fmt_loc,
location_t param_loc, location_t param_loc,
const char *corrected_substring, const char *corrected_substring,
int opt, const char *gmsgid, va_list *ap) int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid, va_list *ap)
{ {
bool substring_within_range = false; bool substring_within_range = false;
location_t primary_loc; location_t primary_loc;
...@@ -143,7 +147,25 @@ format_warning_va (const substring_loc &fmt_loc, ...@@ -143,7 +147,25 @@ format_warning_va (const substring_loc &fmt_loc,
richloc.add_fixit_replace (fmt_substring_range, corrected_substring); richloc.add_fixit_replace (fmt_substring_range, corrected_substring);
diagnostic_info diagnostic; diagnostic_info diagnostic;
diagnostic_set_info (&diagnostic, gmsgid, ap, &richloc, DK_WARNING); if (singular_gmsgid != plural_gmsgid)
{
unsigned long gtn;
if (sizeof n <= sizeof gtn)
gtn = n;
else
/* Use the largest number ngettext can handle, otherwise
preserve the six least significant decimal digits for
languages where the plural form depends on them. */
gtn = n <= ULONG_MAX ? n : n % 1000000LU + 1000000LU;
const char *text = ngettext (singular_gmsgid, plural_gmsgid, gtn);
diagnostic_set_info_translated (&diagnostic, text, ap, &richloc,
DK_WARNING);
}
else
diagnostic_set_info (&diagnostic, singular_gmsgid, ap, &richloc,
DK_WARNING);
diagnostic.option_index = opt; diagnostic.option_index = opt;
bool warned = diagnostic_report_diagnostic (global_dc, &diagnostic); bool warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
...@@ -162,6 +184,18 @@ format_warning_va (const substring_loc &fmt_loc, ...@@ -162,6 +184,18 @@ format_warning_va (const substring_loc &fmt_loc,
return warned; return warned;
} }
/* Singular-only version of the above. */
bool
format_warning_va (const substring_loc &fmt_loc,
location_t param_loc,
const char *corrected_substring,
int opt, const char *gmsgid, va_list *ap)
{
return format_warning_n_va (fmt_loc, param_loc, corrected_substring, opt,
0, gmsgid, gmsgid, ap);
}
/* Variadic call to format_warning_va. */ /* Variadic call to format_warning_va. */
bool bool
...@@ -179,6 +213,26 @@ format_warning_at_substring (const substring_loc &fmt_loc, ...@@ -179,6 +213,26 @@ format_warning_at_substring (const substring_loc &fmt_loc,
return warned; return warned;
} }
/* Variadic call to format_warning_n_va. */
bool
format_warning_at_substring_n (const substring_loc &fmt_loc,
location_t param_loc,
const char *corrected_substring,
int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid, ...)
{
va_list ap;
va_start (ap, plural_gmsgid);
bool warned = format_warning_n_va (fmt_loc, param_loc, corrected_substring,
opt, n, singular_gmsgid, plural_gmsgid,
&ap);
va_end (ap);
return warned;
}
/* Attempt to determine the source location of the substring. /* Attempt to determine the source location of the substring.
If successful, return NULL and write the source location to *OUT_LOC. If successful, return NULL and write the source location to *OUT_LOC.
Otherwise return an error message. Error messages are intended Otherwise return an error message. Error messages are intended
......
...@@ -80,13 +80,29 @@ extern bool format_warning_va (const substring_loc &fmt_loc, ...@@ -80,13 +80,29 @@ extern bool format_warning_va (const substring_loc &fmt_loc,
location_t param_loc, location_t param_loc,
const char *corrected_substring, const char *corrected_substring,
int opt, const char *gmsgid, va_list *ap) int opt, const char *gmsgid, va_list *ap)
ATTRIBUTE_GCC_DIAG (5,0); ATTRIBUTE_GCC_DIAG (5, 0);
extern bool format_warning_n_va (const substring_loc &fmt_loc,
location_t param_loc,
const char *corrected_substring,
int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid, va_list *ap)
ATTRIBUTE_GCC_DIAG (6, 0) ATTRIBUTE_GCC_DIAG (7, 0);
extern bool format_warning_at_substring (const substring_loc &fmt_loc, extern bool format_warning_at_substring (const substring_loc &fmt_loc,
location_t param_loc, location_t param_loc,
const char *corrected_substring, const char *corrected_substring,
int opt, const char *gmsgid, ...) int opt, const char *gmsgid, ...)
ATTRIBUTE_GCC_DIAG (5,0); ATTRIBUTE_GCC_DIAG (5, 6);
extern bool format_warning_at_substring_n (const substring_loc &fmt_loc,
location_t param_loc,
const char *corrected_substring,
int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid, ...)
ATTRIBUTE_GCC_DIAG (6, 8) ATTRIBUTE_GCC_DIAG (7, 8);
/* Implementation detail, for use when implementing /* Implementation detail, for use when implementing
LANG_HOOKS_GET_SUBSTRING_LOCATION. */ LANG_HOOKS_GET_SUBSTRING_LOCATION. */
......
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