aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-02-27 22:06:03 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-02-27 15:06:03 -0700
commit1c89478aef3ef9576f40013c3969179b3189ee95 (patch)
tree8c1be1842ced105c7f3ce3afef09764b30ff037a /gcc/diagnostic.c
parent76bd270a7df7dbf5a02046072947802365bb67f6 (diff)
downloadgcc-1c89478aef3ef9576f40013c3969179b3189ee95.zip
gcc-1c89478aef3ef9576f40013c3969179b3189ee95.tar.gz
gcc-1c89478aef3ef9576f40013c3969179b3189ee95.tar.bz2
PR translation/84207 - Hard coded plural in gimple-fold.c
gcc/ChangeLog: PR translation/84207 * diagnostic-core.h (warning_n, error_n, inform_n): Change n argument to unsigned HOST_WIDE_INT. * diagnostic.c (warning_n, error_n, inform_n): Ditto. (diagnostic_n_impl): Ditto. Handle arguments in excess of LONG_MAX. * gimple-ssa-sprintf.c (format_directive): Simplify inform_n call. * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Use warning_n. From-SVN: r258044
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r--gcc/diagnostic.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index acc44b1..e22c17b 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -51,8 +51,8 @@ along with GCC; see the file COPYING3. If not see
/* Prototypes. */
static bool diagnostic_impl (rich_location *, int, const char *,
va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(3,0);
-static bool diagnostic_n_impl (rich_location *, int, int, const char *,
- const char *, va_list *,
+static bool diagnostic_n_impl (rich_location *, int, unsigned HOST_WIDE_INT,
+ const char *, const char *, va_list *,
diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
@@ -1111,15 +1111,24 @@ diagnostic_impl (rich_location *richloc, int opt,
/* Implement inform_n, warning_n, and error_n, as documented and
defined below. */
static bool
-diagnostic_n_impl (rich_location *richloc, int opt, int n,
+diagnostic_n_impl (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
const char *plural_gmsgid,
va_list *ap, diagnostic_t kind)
{
diagnostic_info diagnostic;
- diagnostic_set_info_translated (&diagnostic,
- ngettext (singular_gmsgid, plural_gmsgid, n),
- ap, richloc, kind);
+ 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, kind);
if (kind == DK_WARNING)
diagnostic.option_index = opt;
return diagnostic_report_diagnostic (global_dc, &diagnostic);
@@ -1176,8 +1185,8 @@ inform (rich_location *richloc, const char *gmsgid, ...)
/* An informative note at LOCATION. Use this for additional details on an
error message. */
void
-inform_n (location_t location, int n, const char *singular_gmsgid,
- const char *plural_gmsgid, ...)
+inform_n (location_t location, unsigned HOST_WIDE_INT n,
+ const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
va_list ap;
va_start (ap, plural_gmsgid);
@@ -1233,7 +1242,7 @@ warning_at (rich_location *richloc, int opt, const char *gmsgid, ...)
/* Same as warning_n plural variant below, but using RICHLOC. */
bool
-warning_n (rich_location *richloc, int opt, int n,
+warning_n (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n,
const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
gcc_assert (richloc);
@@ -1252,8 +1261,8 @@ warning_n (rich_location *richloc, int opt, int n,
Returns true if the warning was printed, false if it was inhibited. */
bool
-warning_n (location_t location, int opt, int n, const char *singular_gmsgid,
- const char *plural_gmsgid, ...)
+warning_n (location_t location, int opt, unsigned HOST_WIDE_INT n,
+ const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
va_list ap;
va_start (ap, plural_gmsgid);
@@ -1350,8 +1359,8 @@ error (const char *gmsgid, ...)
/* A hard error: the code is definitely ill-formed, and an object file
will not be produced. */
void
-error_n (location_t location, int n, const char *singular_gmsgid,
- const char *plural_gmsgid, ...)
+error_n (location_t location, unsigned HOST_WIDE_INT n,
+ const char *singular_gmsgid, const char *plural_gmsgid, ...)
{
va_list ap;
va_start (ap, plural_gmsgid);