From patchwork Thu Oct 27 07:41:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 79626 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp481757qge; Thu, 27 Oct 2016 00:42:01 -0700 (PDT) X-Received: by 10.99.204.5 with SMTP id x5mr9723766pgf.96.1477554121259; Thu, 27 Oct 2016 00:42:01 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k21si6490466pgj.268.2016.10.27.00.42.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 00:42:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439679-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-439679-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439679-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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=WGAVh4Dqoq0u6M/WIJ2x+7Td+yCExnMUqMr0pshau2J1oyT2MR ucvcVrudZSp89u/kclv0LvdN0ZMbz4r4eAOhdT9WzZVfxA6KmBbQpbzlornyLWpU qK7HIKzOwpEr2CHUg08/yj21sqUb8B3WMeo9YxuJuFL90jXTQQ9iNzeaA= 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=FbXBRuomJ+DAYrLbp4JINjPqeOQ=; b=Xk7czWsEfLkgi43ua4WC Vm5bqHxabonFBHyjGj2Vu0tU7CEcZmXZUcDTU7uFx1JDDBn7TBpYJnnYABxHfmar 6k9g7c5lbUEc1m/0q5JeocGkJzo0kJIaFJZpaJI270mSP/tEslVRQV9G7UP9d+0h 75AfPHEdj/d+V/MwDP+AIsE= Received: (qmail 80465 invoked by alias); 27 Oct 2016 07:41:49 -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 80451 invoked by uid 89); 27 Oct 2016 07:41:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=1512, 58, 7, UD:builtins.c, builtinsc X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Oct 2016 07:41:38 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EDFD5AB9D for ; Thu, 27 Oct 2016 07:41:35 +0000 (UTC) To: GCC Patches From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Fix host_size_t_cst_p predicate Message-ID: <5ec537b5-6c63-503c-3480-28ac6cab2699@suse.cz> Date: Thu, 27 Oct 2016 09:41:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Running simple test-case w/o the proper header file causes ICE: strncmp ("a", "b", -1); 0xe74462 tree_to_uhwi(tree_node const*) ../../gcc/tree.c:7324 0x90a23f host_size_t_cst_p ../../gcc/fold-const-call.c:63 0x90a23f fold_const_call(combined_fn, tree_node*, tree_node*, tree_node*, tree_node*) ../../gcc/fold-const-call.c:1512 0x787b01 fold_builtin_3 ../../gcc/builtins.c:8385 0x787b01 fold_builtin_n(unsigned int, tree_node*, tree_node**, int, bool) ../../gcc/builtins.c:8465 0x9052b1 fold(tree_node*) ../../gcc/fold-const.c:11919 0x6de2bb c_fully_fold_internal ../../gcc/c/c-fold.c:185 0x6e1f6b c_fully_fold(tree_node*, bool, bool*) ../../gcc/c/c-fold.c:90 0x67cbbf c_process_expr_stmt(unsigned int, tree_node*) ../../gcc/c/c-typeck.c:10369 0x67cfbd c_finish_expr_stmt(unsigned int, tree_node*) ../../gcc/c/c-typeck.c:10414 0x6cb578 c_parser_statement_after_labels ../../gcc/c/c-parser.c:5430 0x6cd333 c_parser_compound_statement_nostart ../../gcc/c/c-parser.c:4944 0x6cdbde c_parser_compound_statement ../../gcc/c/c-parser.c:4777 0x6c93ac c_parser_declaration_or_fndef ../../gcc/c/c-parser.c:2176 0x6d51ab c_parser_external_declaration ../../gcc/c/c-parser.c:1574 0x6d5c09 c_parser_translation_unit ../../gcc/c/c-parser.c:1454 0x6d5c09 c_parse_file() ../../gcc/c/c-parser.c:18173 0x72ffd2 c_common_parse_file() ../../gcc/c-family/c-opts.c:1087 Following patch improves the host_size_t_cst_p predicate. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin >From 839da4bfdb9505d9f7893c9d22003f93736b9582 Mon Sep 17 00:00:00 2001 From: marxin Date: Wed, 26 Oct 2016 13:48:39 +0200 Subject: [PATCH] Fix host_size_t_cst_p predicat gcc/ChangeLog: 2016-10-26 Martin Liska * fold-const-call.c (host_size_t_cst_p): Test whether it can fit to uhwi. gcc/testsuite/ChangeLog: 2016-10-26 Martin Liska * gcc.dg/tree-ssa/builtins-folding-gimple-ub.c (main): Add test case. --- gcc/fold-const-call.c | 3 ++- gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index 05a15f9..fce9976 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -58,7 +58,8 @@ static inline bool host_size_t_cst_p (tree t, size_t *size_out) { if (integer_cst_p (t) - && wi::min_precision (t, UNSIGNED) <= sizeof (size_t) * CHAR_BIT) + && wi::min_precision (t, UNSIGNED) <= sizeof (size_t) * CHAR_BIT + && tree_fits_uhwi_p (t)) { *size_out = tree_to_uhwi (t); return true; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c index df0ede2..e1658d1 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtins-folding-gimple-ub.c @@ -17,6 +17,10 @@ main (void) if (__builtin_memchr (foo1, 'x', 1000)) /* Not folded away. */ __builtin_abort (); + /* STRNCMP. */ + if (strncmp ("a", "b", -1)) /* { dg-warning "implicit declaration of function" } */ + __builtin_abort (); + return 0; } -- 2.10.1