From patchwork Fri Dec 2 08:31:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 86246 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp192636obb; Fri, 2 Dec 2016 00:31:47 -0800 (PST) X-Received: by 10.84.149.139 with SMTP id m11mr93562025pla.38.1480667507863; Fri, 02 Dec 2016 00:31:47 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id m25si4229069pgd.246.2016.12.02.00.31.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Dec 2016 00:31:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443298-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-443298-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443298-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; q=dns; s=default; b=PJjPeo3AMKq6a3O/ SGpwICK203j+1cjw4rYqKguQcd5tE9vqDEYIIUgHrdETqNXzVr78mVu8OxXFEGDN 14L2z9Hqj1g9d2E3xGBwgMbHcGfGO/P9zIuYbR4wJPdro+uZluFvUJm73V9WKRXw dTn4EUG2oyO/07pdj8vZiuBN/pI= 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:from :to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; s=default; bh=QlsSMZL9pdvEkxZwqPwzxo /7tFM=; b=YVuegC/yS+UvXajHStYQSWkEZhG7PyPg8DoGBzXcGWlx1V0tPoHd/G OI8PNImBTjL7s4bdpg2p6E9lacVH+nnbtB95DcM4JgIIMlB053fx5myRRhs+rxSJ t0oxdQH53Q444LYpY8vT4hVMRfFJAmLJY2o9dSVi19mmjBW0/oYKY= Received: (qmail 89802 invoked by alias); 2 Dec 2016 08:31:33 -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 89780 invoked by uid 89); 2 Dec 2016 08:31:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=adjusts, 2016-12-02 X-HELO: smtp.CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE (HELO smtp.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Dec 2016 08:31:21 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 2B93792A; Fri, 2 Dec 2016 09:31:19 +0100 (CET) Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id tYlncTUzAkcB; Fri, 2 Dec 2016 09:31:16 +0100 (CET) Received: from fuego.CeBiTec.Uni-Bielefeld.DE (p5DCE3560.dip0.t-ipconnect.de [93.206.53.96]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPSA id 1CE2F928; Fri, 2 Dec 2016 09:31:16 +0100 (CET) From: Rainer Orth To: Martin Sebor Cc: Gcc Patch List Subject: Re: [PATCH] correct handling of non-constant width and precision (pr 78521) References: <9b412cbb-1cb0-6341-5b85-78f235f7ae6f@gmail.com> Date: Fri, 02 Dec 2016 09:31:14 +0100 In-Reply-To: <9b412cbb-1cb0-6341-5b85-78f235f7ae6f@gmail.com> (Martin Sebor's message of "Sun, 27 Nov 2016 20:34:35 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Hi Martin, > PR 78521 notes that the gimple-ssa-sprintf pass doesn't do the right > thing (i.e., the -Wformat-length and -fprintf-return-value options > behave incorrectly) when a conversion specification includes a width > or precision with a non-constant value. The code treats such cases > as if they were not provided which is incorrect and results in > the wrong bytes counts in warning messages and in the wrong ranges > being generated for such calls (or in the case sprintf(0, 0, ...) > for some such calls being eliminated). > > The attached patch corrects the handling of these cases, plus a couple > of other edge cases in the same area: it adjusts the parser to accept > precision in the form of just a period with no asterisk or decimal > digits after it (this sets the precision to zero), and corrects the > handling of zero precision and zero argument in integer directives > to produce no bytes on output. > > Finally, the patch also tightens up the constraint on the upper bound > of bounded functions like snprintf to be INT_MAX. The functions cannot > produce output in excess of INT_MAX + 1 bytes and some implementations > (e.g., Solaris) fail with EINVAL when the bound is INT_MAX or more. > This is the subject of PR 78520. this patch broke Solaris bootstrap: /vol/gcc/src/hg/trunk/local/gcc/gimple-ssa-sprintf.c: In function 'void {anonymous}::get_width_and_precision(const {anonymous}::conversion_spec&, long long int*, long long int*)': /vol/gcc/src/hg/trunk/local/gcc/gimple-ssa-sprintf.c:777:45: error: call of overloaded 'abs(long long int)' is ambiguous width = abs (tree_to_shwi (spec.star_width)); ^ /vol/gcc/src/hg/trunk/local/gcc/gimple-ssa-sprintf.c:777:45: note: candidates are: In file included from /usr/include/stdlib.h:12:0, from /vol/gcc/src/hg/trunk/local/gcc/system.h:258, from /vol/gcc/src/hg/trunk/local/gcc/gimple-ssa-sprintf.c:49: /usr/include/iso/stdlib_iso.h:205:16: note: long int std::abs(long int) inline long abs(long _l) { return labs(_l); } ^ /usr/include/iso/stdlib_iso.h:160:12: note: int std::abs(int) extern int abs(int); ^ The following patch fixed this for me, but I've no idea if it's right. It bootstrapped successfully on sparc-sun-solaris2.12, i386-pc-solaris2.12, and x86_64-pc-linux-gnu. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University 2016-12-02 Rainer Orth * gimple-ssa-sprintf.c (get_width_and_precision): Use std::abs. diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -774,7 +774,7 @@ get_width_and_precision (const conversio if (spec.star_width) { if (TREE_CODE (spec.star_width) == INTEGER_CST) - width = abs (tree_to_shwi (spec.star_width)); + width = std::abs (tree_to_shwi (spec.star_width)); else width = HOST_WIDE_INT_MIN; }