diff options
author | Jakub Jelinek <jakub@redhat.com> | 2018-03-02 20:04:58 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2018-03-02 20:04:58 +0100 |
commit | 346114b54da37792ec1759a1e76626eb4d3a5594 (patch) | |
tree | 9e9f74834008088fe0782398fb88b476022001a6 /gcc/substring-locations.c | |
parent | 892870f9f3ae0fc4486e372c3db0a83b739ca572 (diff) | |
download | gcc-346114b54da37792ec1759a1e76626eb4d3a5594.zip gcc-346114b54da37792ec1759a1e76626eb4d3a5594.tar.gz gcc-346114b54da37792ec1759a1e76626eb4d3a5594.tar.bz2 |
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
Diffstat (limited to 'gcc/substring-locations.c')
-rw-r--r-- | gcc/substring-locations.c | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/gcc/substring-locations.c b/gcc/substring-locations.c index cf3ec4f..2d7f0c1 100644 --- a/gcc/substring-locations.c +++ b/gcc/substring-locations.c @@ -20,14 +20,17 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "intl.h" #include "diagnostic.h" #include "cpplib.h" #include "tree.h" #include "langhooks.h" #include "substring-locations.h" -/* Emit a warning governed by option OPT, using GMSGID as the format - string and AP as its arguments. +/* Emit a warning governed by option OPT, using SINGULAR_GMSGID as the + 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 literal from FMT_LOC. @@ -97,12 +100,13 @@ along with GCC; see the file COPYING3. If not see Return true if a warning was emitted, false otherwise. */ -ATTRIBUTE_GCC_DIAG (5,0) 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) +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) { bool substring_within_range = false; location_t primary_loc; @@ -143,7 +147,25 @@ format_warning_va (const substring_loc &fmt_loc, richloc.add_fixit_replace (fmt_substring_range, corrected_substring); 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; bool warned = diagnostic_report_diagnostic (global_dc, &diagnostic); @@ -162,6 +184,18 @@ format_warning_va (const substring_loc &fmt_loc, 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. */ bool @@ -179,6 +213,26 @@ format_warning_at_substring (const substring_loc &fmt_loc, 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. If successful, return NULL and write the source location to *OUT_LOC. Otherwise return an error message. Error messages are intended |