From patchwork Tue Feb 13 03:10:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 872554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-473131-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EUovJBws"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zgSGl0H9Nz9sPk for ; Tue, 13 Feb 2018 14:10:54 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=eW9Six/AB69ut4aq9GEtvcAaLkFpis+KDFO/z7N6qcHq1pwpNK cVB8jSvdC115ZdJ5fymG83yav7hRxu+aWX6LAClcXxUjXGtz3TjehMxy4bt4ip+i OB+sZDM03Zr0M1c1opio3AZbysPGLryJN+yM1DV0t/wowwc97oypFdFJI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=RB8bEQN178OVLaB9EPZjHEQmJbc=; b=EUovJBwsngS5fs6Sv4ev Kikjpmf+zaWRzKRrR2QtRNsGIVxJeGe9yGQkLf1dpjJZI/1JZzYz1XAj/t6nxFbA qeXYepzmytF/g8OVCj+EtDTlpDvy1wMlfLi6LtwXVhSMFKk6i+AU6NR8/O+pZ7K9 2f70WPUiifq1lvJEqTMRNfc= Received: (qmail 38215 invoked by alias); 13 Feb 2018 03:10:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 38180 invoked by uid 89); 13 Feb 2018 03:10:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=cha X-HELO: mail-ot0-f172.google.com Received: from mail-ot0-f172.google.com (HELO mail-ot0-f172.google.com) (74.125.82.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Feb 2018 03:10:39 +0000 Received: by mail-ot0-f172.google.com with SMTP id r23so15984188ote.8 for ; Mon, 12 Feb 2018 19:10:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=W3aAOJST62lEbu0Sjf+rLB62bACd6DW9GyJky4uSSy0=; b=MkfKWOWGACWWd8biiafzaNGB5PjaAwbBIwFgrNU6dfCg/WaobZbI8Ad8R+DtYLVnku +GVFFvMDlxU4qHKRkmgxNPKgYZGLvS0aMPZh58Nyl4Ve13x14lvH/FoPCVVs25ENRI2f viAhw5vrb/x9zyYIhBybXHTCMMwr6/yWCzBApeyp+qsSTU+rCiPtX2jR74P6Vgq4AOIQ 74g5bU7M0+kqZs7vk124NFWkDJqpunuA9jjEUePLCkudFpDt6KuEATCC4KwZc8nUp6gN vs8tSFQQ3W+qxGDbS2FYs+CRQW6xm7KCn7xcawGBsH7NIb8JXBHtWcbWJAFtTCbN/k8Z mPSw== X-Gm-Message-State: APf1xPA8ujFdtO0WsWOz/MJGfP6fGr35Wah+oOE7SHSt+HzC0vKaCf00 cSONV2ioBJZxIMurLdtY4DqClg== X-Google-Smtp-Source: AH8x227zeNsXjlEhWnYOTJcsAhi8+AZa3164xI5gIf/XVJ/+z187g0vSR8M02Mq15++WMxEI42w5ew== X-Received: by 10.157.11.3 with SMTP id a3mr10700532ota.398.1518491437928; Mon, 12 Feb 2018 19:10:37 -0800 (PST) Received: from localhost.localdomain (75-171-228-29.hlrn.qwest.net. [75.171.228.29]) by smtp.gmail.com with ESMTPSA id q62sm330819oig.31.2018.02.12.19.10.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Feb 2018 19:10:36 -0800 (PST) To: Gcc Patch List From: Martin Sebor Subject: [PATCH] adjust warning_n() to take uhwi (PR 84207) Message-ID: <7c200219-2d6e-02ca-e720-9d3a8616a1e6@gmail.com> Date: Mon, 12 Feb 2018 20:10:35 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Bug 84207 - Hard coded plural in gimple-fold.c points out one of a number of warning_at() calls where warning_n() should have been used. The attached patch both replaces the calls and also changes the signatures of the warning_n(), error_n(), and inform_n() functions to take an unsigned HOST_WIDE_INT argument instead of int. I also changed the implementation of diagnostic_n_impl() to deal with unsigned HOST_WIDE_INT values in excess of ULONG_MAX (the maximum value ngettext handles) so callers don't need to. Bootstrapped/regtested on x86_64-linux. Martin PS Is there any reason why diagnostic-core.h and diagnostic.c does not/should not include tree.h and other GCC headers? 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-fold.c (gimple_fold_builtin_strncpy): Use warning_n. Index: gcc/diagnostic-core.h =================================================================== --- gcc/diagnostic-core.h (revision 257607) +++ gcc/diagnostic-core.h (working copy) @@ -59,10 +59,11 @@ extern void internal_error_no_backtrace (const cha ATTRIBUTE_GCC_DIAG(1,2) ATTRIBUTE_NORETURN; /* Pass one of the OPT_W* from options.h as the first parameter. */ extern bool warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); -extern bool warning_n (location_t, int, int, const char *, const char *, ...) +extern bool warning_n (location_t, int, unsigned HOST_WIDE_INT, + const char *, const char *, ...) ATTRIBUTE_GCC_DIAG(4,6) ATTRIBUTE_GCC_DIAG(5,6); -extern bool warning_n (rich_location *, int, int, const char *, - const char *, ...) +extern bool warning_n (rich_location *, int, unsigned HOST_WIDE_INT, + const char *, const char *, ...) ATTRIBUTE_GCC_DIAG(4, 6) ATTRIBUTE_GCC_DIAG(5, 6); extern bool warning_at (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); @@ -69,7 +70,8 @@ extern bool warning_at (location_t, int, const cha extern bool warning_at (rich_location *, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); -extern void error_n (location_t, int, const char *, const char *, ...) +extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5); extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern void error_at (rich_location *, const char *, ...) @@ -87,7 +89,8 @@ extern bool permerror (rich_location *, const char extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3); -extern void inform_n (location_t, int, const char *, const char *, ...) +extern void inform_n (location_t, unsigned HOST_WIDE_INT, const char *, + const char *, ...) ATTRIBUTE_GCC_DIAG(3,5) ATTRIBUTE_GCC_DIAG(4,5); extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2); extern bool emit_diagnostic (diagnostic_t, location_t, int, Index: gcc/diagnostic.c =================================================================== --- gcc/diagnostic.c (revision 257607) +++ gcc/diagnostic.c (working copy) @@ -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,22 @@ 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. */ + gtn = n <= ULONG_MAX ? n : ULONG_MAX; + + 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 +1183,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 +1240,7 @@ warning_at (rich_location *richloc, int opt, const /* 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 +1259,8 @@ bool 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 +1357,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); Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 257607) +++ gcc/gimple-fold.c (working copy) @@ -1694,13 +1694,13 @@ gimple_fold_builtin_strncpy (gimple_stmt_iterator tree fndecl = gimple_call_fndecl (stmt); gcall *call = as_a (stmt); - warning_at (loc, OPT_Wstringop_truncation, - (tree_int_cst_equal (size_one_node, len) - ? G_("%G%qD output truncated copying %E byte " - "from a string of length %E") - : G_("%G%qD output truncated copying %E bytes " - "from a string of length %E")), - call, fndecl, len, slen); + warning_n (loc, OPT_Wstringop_truncation, + tree_to_uhwi (len), + "%G%qD output truncated copying %E byte " + "from a string of length %E", + "%G%qD output truncated copying %E bytes " + "from a string of length %E", + call, fndecl, len, slen); } else if (tree_int_cst_equal (len, slen)) { @@ -1707,15 +1707,15 @@ gimple_fold_builtin_strncpy (gimple_stmt_iterator tree fndecl = gimple_call_fndecl (stmt); gcall *call = as_a (stmt); - warning_at (loc, OPT_Wstringop_truncation, - (tree_int_cst_equal (size_one_node, len) - ? G_("%G%qD output truncated before terminating nul " - "copying %E byte from a string of the same " - "length") - : G_("%G%qD output truncated before terminating nul " - "copying %E bytes from a string of the same " - "length")), - call, fndecl, len); + warning_n (loc, OPT_Wstringop_truncation, + tree_to_uhwi (len), + "%G%qD output truncated before terminating nul " + "copying %E byte from a string of the same " + "length", + "%G%qD output truncated before terminating nul " + "copying %E bytes from a string of the same " + "length", + call, fndecl, len); } }