From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119992 invoked by alias); 23 Feb 2019 02:26:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 119950 invoked by uid 89); 23 Feb 2019 02:26:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:3371, analogously, digit X-HELO: mail-qk1-f193.google.com Received: from mail-qk1-f193.google.com (HELO mail-qk1-f193.google.com) (209.85.222.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 23 Feb 2019 02:25:58 +0000 Received: by mail-qk1-f193.google.com with SMTP id x9so2359634qkf.0 for ; Fri, 22 Feb 2019 18:25:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=ycPVHE1fQkOVcVgrVQLGAqBzL3d6L/yrT5s9Uigb5TY=; b=MFIXnEx6Jmvomz6Zy6WyBl9Nqmbjc5+sdBZvdWGmLLPnUhhpeLuEAf15uL8R+mOnjt DAVtkdGMsWaxe7dlPhZZpLztzrTCy+E2k5rLhOQ55iPEkFjwjXF6JQxetj6kqwPpnHEP vt0b2H4LA3MpfZh0gNkEBpgTluft4VTt7ePFKxcXMH6kBR9ROiCrvvHdxSbhOJkybOxG CDG/A+wqumVMaaTQBL+t9gBl/7DUE8d2Exs6YdvABeV5FgdOmxszCQ34lNJ//L/7mzqo cL0+hYmu4raFIhHMPrWGGpEiKlabh1aR22Q3VHWrLvRi0pmhYWUqaF3rwMfwres5QMHs 3Wng== Return-Path: Received: from [192.168.0.106] (174-16-104-92.hlrn.qwest.net. [174.16.104.92]) by smtp.gmail.com with ESMTPSA id f36sm1823135qtb.67.2019.02.22.18.25.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 18:25:55 -0800 (PST) To: "gcc-patches@gcc.gnu.org" From: Martin Sebor Subject: [PATCH] make -Wformat-overflow consistent between data models Message-ID: <24ae4245-ff17-4159-2bf4-c974b3ad823c@gmail.com> Date: Sat, 23 Feb 2019 03:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------76F667856B192A6FB5BFFFDA" X-IsSubscribed: yes X-SW-Source: 2019-02/txt/msg01877.txt.bz2 This is a multi-part message in MIME format. --------------76F667856B192A6FB5BFFFDA Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 517 A few tests recently added for PR 88993 introduced an assumption on the host compiler's data model that breaks between ILP32 and LP64, causing failures test run failures (see https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01867.html). Rather than avoiding the problem in the tests the attached patch removes the data model assumption from the sprintf pass itself, making the warnings emitted by the pass consistent regardless. Bootstrapped and tested on x86_64-linux, and smoke-tested with an i386-linux GCC. Martin --------------76F667856B192A6FB5BFFFDA Content-Type: text/x-patch; name="gcc-printf-excess-width.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-printf-excess-width.diff" Content-length: 3026 gcc/ChangeLog: * gimple-ssa-sprintf.c (target_strtol): Rename... (target_strtohwi): ...to this. Handle values up to HOST_WIDE_INT_MAX. (parse_directive): Adjust to name change. Use HOST_WIDE_INT_MAX to check for range error. Index: gcc/gimple-ssa-sprintf.c =================================================================== --- gcc/gimple-ssa-sprintf.c (revision 269136) +++ gcc/gimple-ssa-sprintf.c (working copy) @@ -411,12 +411,12 @@ target_to_host (char *hostr, size_t hostsz, const } /* Convert the sequence of decimal digits in the execution character - starting at S to a long, just like strtol does. Return the result - and set *END to one past the last converted character. On range - error set ERANGE to the digit that caused it. */ + starting at *PS to a HOST_WIDE_INT, analogously to strtol. Return + the result and set *PS to one past the last converted character. + On range error set ERANGE to the digit that caused it. */ -static inline long -target_strtol10 (const char **ps, const char **erange) +static inline HOST_WIDE_INT +target_strtowi (const char **ps, const char **erange) { unsigned HOST_WIDE_INT val = 0; for ( ; ; ++*ps) @@ -427,9 +427,9 @@ target_to_host (char *hostr, size_t hostsz, const c -= '0'; /* Check for overflow. */ - if (val > (LONG_MAX - c) / 10LU) + if (val > ((unsigned HOST_WIDE_INT) HOST_WIDE_INT_MAX - c) / 10LU) { - val = LONG_MAX; + val = HOST_WIDE_INT_MAX; *erange = *ps; /* Skip the remaining digits. */ @@ -3149,7 +3149,7 @@ parse_directive (sprintf_dom_walker::call_info &in width and sort it out later after the next character has been seen. */ pwidth = pf; - width = target_strtol10 (&pf, &werange); + width = target_strtowi (&pf, &werange); } else if (target_to_host (*pf) == '*') { @@ -3231,7 +3231,7 @@ parse_directive (sprintf_dom_walker::call_info &in { werange = 0; pwidth = pf; - width = target_strtol10 (&pf, &werange); + width = target_strtowi (&pf, &werange); } else if (target_to_host (*pf) == '*') { @@ -3264,7 +3264,7 @@ parse_directive (sprintf_dom_walker::call_info &in if (ISDIGIT (target_to_host (*pf))) { pprec = pf; - precision = target_strtol10 (&pf, &perange); + precision = target_strtowi (&pf, &perange); } else if (target_to_host (*pf) == '*') { @@ -3418,7 +3418,7 @@ parse_directive (sprintf_dom_walker::call_info &in } else { - if (width == LONG_MAX && werange) + if (width == HOST_WIDE_INT_MAX && werange) { size_t begin = dir.beg - info.fmtstr + (pwidth - pcnt); size_t caret = begin + (werange - pcnt); @@ -3451,7 +3451,7 @@ parse_directive (sprintf_dom_walker::call_info &in } else { - if (precision == LONG_MAX && perange) + if (precision == HOST_WIDE_INT_MAX && perange) { size_t begin = dir.beg - info.fmtstr + (pprec - pcnt) - 1; size_t caret = dir.beg - info.fmtstr + (perange - pcnt) - 1; --------------76F667856B192A6FB5BFFFDA--