From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40996 invoked by alias); 24 Apr 2017 23:35:37 -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 40869 invoked by uid 89); 24 Apr 2017 23:35:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=numbered, dollar X-HELO: mail-qk0-f172.google.com Received: from mail-qk0-f172.google.com (HELO mail-qk0-f172.google.com) (209.85.220.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Apr 2017 23:35:31 +0000 Received: by mail-qk0-f172.google.com with SMTP id h123so46154286qke.0 for ; Mon, 24 Apr 2017 16:35:33 -0700 (PDT) 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=lj9HftgkeSGipo2HjeXcKH9axbO5pcirtD6oaa88n60=; b=HWu13rBfHALoOqBpemXx4KZYoT0qgIpX0+NEXi/BQlZa/ZBHf+MbWKB1FgAUEpC7+2 oYiZ7uTWy3SzKw414luWXb8AwWNg2MFlvO9PKij9+fSgM11+LzKWBP3tl3pZywdX9juw WpK103qaJ72f5GQHWcmy7zBuyNEzwSTVKWfexMMKZeIlugORZFLKGavoJ6REyPRM1DL2 SENpnArJSMjY7hfxVpAMJYqvFhfzCQcLgwNXrBgvCV4lpPqOrUOesADu+nPfvUd3cOGn OV9O8MnSa5Q9ahnOtOR3ObFHXYek37SVii+ksoI5Ph8fgwmdrRJThD2J/kQXbssGXwmC twjQ== X-Gm-Message-State: AN3rC/7zrV9RxGoF0r48O3FkuIRO6iAj+S4d03jZiTFAZ2oXIIFSX46K NYhcEfqvtPyyjdBy X-Received: by 10.55.22.160 with SMTP id 32mr15785627qkw.89.1493076932169; Mon, 24 Apr 2017 16:35:32 -0700 (PDT) Received: from localhost.localdomain (75-166-101-229.hlrn.qwest.net. [75.166.101.229]) by smtp.gmail.com with ESMTPSA id j1sm13932469qkf.57.2017.04.24.16.35.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Apr 2017 16:35:31 -0700 (PDT) To: Gcc Patch List From: Martin Sebor Subject: [PATCH] avoid assuming all integers are representable in HOST_WIDE_INT (PR #80497) Message-ID: Date: Tue, 25 Apr 2017 06:07:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------A966E237AF24C637A47FAE7E" X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg01085.txt.bz2 This is a multi-part message in MIME format. --------------A966E237AF24C637A47FAE7E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 446 Bug 80497 brings to light that my fix for PR 80364 where I corrected the handling for int128_t was incomplete. I handled the non-constant case but missed the INTEGER_CST case just a few lines above. The attached patch also corrects that problem plus one more elsewhere in the pass. Both of the changes in this patch seem safe enough to make even now in GCC 7 but since they are ice-on-invalid-code perhaps it's better to wait for 7.1? Martin --------------A966E237AF24C637A47FAE7E Content-Type: text/x-patch; name="gcc-80497.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-80497.diff" Content-length: 2792 PR tree-optimization/80497 - ICE at -O1 and above on valid code on x86_64-linux-gnu in tree_to_uhwi gcc/ChangeLog: PR tree-optimization/80497 * gimple-ssa-sprintf.c (get_int_range): Avoid assuming all integer constants are representable in HOST_WIDE_INT. (parse_directive): Ditto. gcc/testsuite/ChangeLog: PR tree-optimization/80497 * gcc.dg/tree-ssa/builtin-sprintf-warn-17.c: New test. diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index 2e62086..d3771dd 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -948,7 +948,8 @@ get_int_range (tree arg, HOST_WIDE_INT *pmin, HOST_WIDE_INT *pmax, *pmin = tree_to_shwi (TYPE_MIN_VALUE (type)); *pmax = tree_to_shwi (TYPE_MAX_VALUE (type)); } - else if (TREE_CODE (arg) == INTEGER_CST) + else if (TREE_CODE (arg) == INTEGER_CST + && TYPE_PRECISION (TREE_TYPE (arg)) <= TYPE_PRECISION (type)) { /* For a constant argument return its value adjusted as specified by NEGATIVE and NEGBOUND and return true to indicate that the @@ -2916,7 +2917,9 @@ parse_directive (pass_sprintf_length::call_info &info, if (width != -1) dollar = width + info.argidx; else if (star_width - && TREE_CODE (star_width) == INTEGER_CST) + && TREE_CODE (star_width) == INTEGER_CST + && (TYPE_PRECISION (TREE_TYPE (star_width)) + <= TYPE_PRECISION (integer_type_node))) dollar = width + tree_to_shwi (star_width); /* Bail when the numbered argument is out of range (it will diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-17.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-17.c new file mode 100644 index 0000000..27aa839 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-17.c @@ -0,0 +1,42 @@ +/* PR tree-optimization/80497 - ICE at -O1 and above on valid code on + x86_64-linux-gnu in "tree_to_uhwi" + { dg-do compile } + { dg-options "-O2 -Wall -Wformat-overflow" } + { dg-require-effective-target int128 } */ + +extern char buf[]; + +const __int128_t sint128_max + = (__int128_t)1 << (sizeof sint128_max * __CHAR_BIT__ - 2); + +void fn0 (void) +{ + __int128_t si128 = 0; + + __builtin_sprintf (buf, "%*i", si128, 0); + + __builtin_sprintf (buf, "%.*i", si128, 0); + + __builtin_sprintf (buf, "%i", si128); + + __builtin_sprintf (buf, "%2$*1$i", si128, 0); + + __builtin_sprintf (buf, "%2$.*1$i", si128, 0); +} + +void fn1 (void) +{ + __int128_t si128 = sint128_max; + + __builtin_sprintf (buf, "%*i", si128, 0); + + __builtin_sprintf (buf, "%.*i", si128, 0); + + __builtin_sprintf (buf, "%i", si128); + + __builtin_sprintf (buf, "%2$*1$i", si128, 0); + + __builtin_sprintf (buf, "%2$.*1$i", si128, 0); +} + +/* { dg-prune-output "expects argument of type .int." } */ --------------A966E237AF24C637A47FAE7E--