From patchwork Sun Oct 1 16:13:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 114536 Delivered-To: patch@linaro.org Received: by 10.140.104.133 with SMTP id a5csp2937841qgf; Sun, 1 Oct 2017 09:14:01 -0700 (PDT) X-Received: by 10.99.53.206 with SMTP id c197mr10472900pga.440.1506874441761; Sun, 01 Oct 2017 09:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506874441; cv=none; d=google.com; s=arc-20160816; b=ubxPiozr1KDKXyqvYdQSuJnqUEg0rsQ/eDGUbJETOgiqGRroiDVSWJfaWN0H0uyx6M UtqGIwIgYXxWObGzgj+j1oOewMX7ixRBSCkAppl+qfc3U96ZE3EsfI6mt30ljExrap1U vn9TWuI8zS5bbrC6Z+pIrEwrG4c3NLPCde0mgSKwpcHTIoCYFIPm6Ij5k6zTydbQrdxW yd0darc4O6dylIFaXifyK7PJHQzcBPgTyRPb5FIbwtirJAcV6Rq5+PfnDkvXxCPf7hDf rDflCmYvYSM9Qi2+ZH3qCg3sZmAjTKeWvmqOqUNPxRPQ1ZbxAHEYWLwLNZOdMWRL1eZh DC7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=v03Uk5pEEqNspLsAi6WaKjeAztcLzADNJMMyIg4mBR8=; b=wagSYwPrEUNysaoDwOMLd06qgMT5EtPw9YlRRn7blvESn5h4TfgAeYBg8XlGhizhOO 7O6kOtNkhRp2yhhVw2URN3hwNA53NLONObyvMwg9132YnAs6Ks2Ap8grLFNhFH4UpPq7 Q85QgjsyrZO5fVoO4/uSLRHDVlTadUF/NTYdez26fVtcQB3cQtoNHq/DdSY81YQDiuKO BF8VLvHacttoMsfuGFbF8DeuJOqLJ04OH6EwXSPx4srFU7qMihaurmv1o47LrXv7qX16 yAAPuBydqnFrbq4KIjohWefKDCI2YwRnlQW5OWtb0dd6z/DGypp/bPcuYMn5hrdjvZSI 3YoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DBGfpf7X; spf=pass (google.com: domain of gcc-patches-return-463292-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-463292-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id c20si6185742pfc.275.2017.10.01.09.14.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Oct 2017 09:14:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-463292-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 header.s=default header.b=DBGfpf7X; spf=pass (google.com: domain of gcc-patches-return-463292-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-463292-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=ZKgW0ctG318/UVLnJBV3ZFzzRb7sVDi7PnLY4BJad82KfiQuHc/Vj 8wKno5I8ePtC6bIr4WO7FhUkF2QCWO6Ea+nll375JPOCLGbAToaGoe+vtcO8Doaq hQq7jg6t8xZCc9w4+bnzHHmULcVR1/De4vqnIXz5r/1DTEHO+xGPZM= 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:subject:date:message-id:mime-version:content-type; s= default; bh=PY0JwnY7RnlHCWciTtxQTAVmjdQ=; b=DBGfpf7XC8J8osXz4ALJ w0pYEhFOau+s6P0/uVQ1dh8tZTNlO8WTZIObpnQChf5595FTgpdRVuJm+NYFuF4W sr262jlnioWjY5ITfStP2PPBO4wuimiFTV9hdSaH9cpxYQ4lBiIXBbY0hoizS/03 FBM5ye3+E++3R8aN0aQzWc8= Received: (qmail 107045 invoked by alias); 1 Oct 2017 16:13:45 -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 107035 invoked by uid 89); 1 Oct 2017 16:13:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=buff, unaffected, 35515, 35517 X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Oct 2017 16:13:42 +0000 Received: by mail-wm0-f49.google.com with SMTP id e195so2759431wma.5 for ; Sun, 01 Oct 2017 09:13:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=v03Uk5pEEqNspLsAi6WaKjeAztcLzADNJMMyIg4mBR8=; b=Wh6EaKl8+hYqqWM4h+en853mQva0hs840GQibCLag1PbbHhil9UQ9CR8X5tTb7xaBM SwETBY02zrME1mfkhc/KN6TDN7ZithagR8h1P+8wgjIY8CgEpjPaqszoRgCOqfRb4Oaf cs/QiilNmZuUkbeU5BvcfQiHkfTieBge9v7wiCeXEMj2zEa9w/tfHdVFTNKNhm8BQ5nQ 4Fcmi4ew9qV3irtaTdzrWqm9EbXOEpiBY1qRvqnAiJEjHdD+YgPDMJ15TY5IKmAwFXY2 zjlvHncuO5JWWW7S5V37ttZQyULIK7Ka8ohE756ZuAEPniJ4r2PTkk8Y6TpQKa5IdPl8 c88Q== X-Gm-Message-State: AMCzsaXn5Y3qpuxamgsEVrf3SY9kimL9SUmV0ElVAkp2CC7U6+XK/JCy zamAyfbB4FxBU0tqsg7S6vmpyB2RaOU= X-Google-Smtp-Source: AOwi7QAS4aAd9DZ3uOxOZiDaJc474U95v78UKNXG/vsadH6ntWfSoEvKXN0fy0BE9YNU/vIjg4UgGg== X-Received: by 10.28.125.206 with SMTP id y197mr1622001wmc.85.1506874419437; Sun, 01 Oct 2017 09:13:39 -0700 (PDT) Received: from localhost ([2.26.27.252]) by smtp.gmail.com with ESMTPSA id 2sm3491171wrg.58.2017.10.01.09.13.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 01 Oct 2017 09:13:38 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Fix mismatched precisions in tree arithmetic Date: Sun, 01 Oct 2017 17:13:36 +0100 Message-ID: <87o9pqx2vj.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 The tree wi:: decompose routine wasn't asserting that the requested precision matched the tree's precision. This could make a difference for unsigned trees that are exactly N HWIs wide and that have the upper bit set, since we then need an extra zero HWI when extending it to wider precisions (as for wi::to_widest). This patch adds the assert and fixes the fallout shown by the testsuite. Go seems to be unaffected. Other fixed-precision decompose routines already had an assert. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. Also tested by comparing the testsuite assembly output on at least one target per CPU directory. OK to install? Richard 2017-10-01 Richard Sandiford gcc/ * tree.h (wi::int_traits ::decompose): Assert that the requested precision matches the type's. * calls.c (alloc_max_size): Calculate the new candidate size as a widest_int and use wi::to_widest when comparing it with the current candidate size. * gimple-ssa-warn-alloca.c (pass_walloca::execute): Compare with zero rather than integer_zero_node. * match.pd: Check for a no-op conversion before using wi::add rather than after. Use tree_to_uhwi when summing small shift counts into an unsigned int. gcc/c-family/ * c-warn.c (warn_tautological_bitwise_comparison): Use wi::to_widest when combining the original unconverted comparison operands. gcc/cp/ * constexpr.c (cxx_eval_store_expression): Use wi::to_widest when comparing the array bounds with an ARRAY_REF index. gcc/ada/ * gcc-interface/decl.c (annotate_value): Use wi::to_widest when handling the form (plus/mult (convert @0) @1). Index: gcc/tree.h =================================================================== --- gcc/tree.h 2017-09-25 13:33:39.989814299 +0100 +++ gcc/tree.h 2017-10-01 17:08:55.827120507 +0100 @@ -5176,6 +5176,7 @@ wi::int_traits ::get_precisi wi::int_traits ::decompose (HOST_WIDE_INT *, unsigned int precision, const_tree x) { + gcc_checking_assert (precision == TYPE_PRECISION (TREE_TYPE (x))); return wi::storage_ref (&TREE_INT_CST_ELT (x, 0), TREE_INT_CST_NUNITS (x), precision); } Index: gcc/calls.c =================================================================== --- gcc/calls.c 2017-09-21 12:13:48.336399601 +0100 +++ gcc/calls.c 2017-10-01 17:08:55.825112782 +0100 @@ -1252,9 +1252,8 @@ alloc_max_size (void) if (unit) { - wide_int w = wi::uhwi (limit, HOST_BITS_PER_WIDE_INT + 64); - w *= unit; - if (wi::ltu_p (w, alloc_object_size_limit)) + widest_int w = wi::mul (limit, unit); + if (w < wi::to_widest (alloc_object_size_limit)) alloc_object_size_limit = wide_int_to_tree (ssizetype, w); } } Index: gcc/gimple-ssa-warn-alloca.c =================================================================== --- gcc/gimple-ssa-warn-alloca.c 2017-03-28 16:19:28.000000000 +0100 +++ gcc/gimple-ssa-warn-alloca.c 2017-10-01 17:08:55.826116645 +0100 @@ -491,7 +491,7 @@ pass_walloca::execute (function *fun) is_vla ? G_("argument to variable-length array " "may be too large") : G_("argument to % may be too large")) - && t.limit != integer_zero_node) + && t.limit != 0) { print_decu (t.limit, buff); inform (loc, G_("limit is %u bytes, but argument " @@ -504,7 +504,7 @@ pass_walloca::execute (function *fun) is_vla ? G_("argument to variable-length array " "is too large") : G_("argument to % is too large")) - && t.limit != integer_zero_node) + && t.limit != 0) { print_decu (t.limit, buff); inform (loc, G_("limit is %u bytes, but argument is %s"), Index: gcc/match.pd =================================================================== --- gcc/match.pd 2017-09-25 13:57:11.698158636 +0100 +++ gcc/match.pd 2017-10-01 17:08:55.827120507 +0100 @@ -358,8 +358,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (div (convert? (bit_and @0 INTEGER_CST@1)) INTEGER_CST@2) (if (integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0 - && wi::add (@2, @1) == 0 - && tree_nop_conversion_p (type, TREE_TYPE (@0))) + && tree_nop_conversion_p (type, TREE_TYPE (@0)) + && wi::add (@2, @1) == 0) (rshift (convert @0) { build_int_cst (integer_type_node, wi::exact_log2 (@2)); })))) @@ -1871,7 +1871,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && wi::lt_p (@1, prec, TYPE_SIGN (TREE_TYPE (@1))) && wi::ge_p (@2, 0, TYPE_SIGN (TREE_TYPE (@2))) && wi::lt_p (@2, prec, TYPE_SIGN (TREE_TYPE (@2)))) - (with { unsigned int low = wi::add (@1, @2).to_uhwi (); } + (with { unsigned int low = (tree_to_uhwi (@1) + + tree_to_uhwi (@2)); } /* Deal with a OP (c1 + c2) being undefined but (a OP c1) OP c2 being well defined. */ (if (low >= prec) Index: gcc/c-family/c-warn.c =================================================================== --- gcc/c-family/c-warn.c 2017-09-05 20:55:56.402037612 +0100 +++ gcc/c-family/c-warn.c 2017-10-01 17:08:55.824108920 +0100 @@ -355,15 +355,17 @@ warn_tautological_bitwise_comparison (lo else return; - wide_int res; + /* Note that the two operands are from before the usual integer + conversions, so their types might not be the same. */ + widest_int res; if (TREE_CODE (bitop) == BIT_AND_EXPR) - res = wi::bit_and (bitopcst, cst); + res = wi::to_widest (bitopcst) & wi::to_widest (cst); else - res = wi::bit_or (bitopcst, cst); + res = wi::to_widest (bitopcst) | wi::to_widest (cst); /* For BIT_AND only warn if (CST2 & CST1) != CST1, and for BIT_OR only if (CST2 | CST1) != CST1. */ - if (res == cst) + if (res == wi::to_widest (cst)) return; if (code == EQ_EXPR) Index: gcc/cp/constexpr.c =================================================================== --- gcc/cp/constexpr.c 2017-09-16 21:38:21.073925724 +0100 +++ gcc/cp/constexpr.c 2017-10-01 17:08:55.826116645 +0100 @@ -3379,7 +3379,7 @@ cxx_eval_store_expression (const constex VERIFY_CONSTANT (nelts); gcc_assert (TREE_CODE (nelts) == INTEGER_CST && TREE_CODE (TREE_OPERAND (probe, 1)) == INTEGER_CST); - if (wi::eq_p (TREE_OPERAND (probe, 1), nelts)) + if (wi::to_widest (TREE_OPERAND (probe, 1)) == wi::to_widest (nelts)) { diag_array_subscript (ctx, ary, TREE_OPERAND (probe, 1)); *non_constant_p = true; Index: gcc/ada/gcc-interface/decl.c =================================================================== --- gcc/ada/gcc-interface/decl.c 2017-09-11 17:10:55.549140040 +0100 +++ gcc/ada/gcc-interface/decl.c 2017-10-01 17:08:55.823105057 +0100 @@ -8153,11 +8153,13 @@ annotate_value (tree gnu_size) { tree inner_op_op1 = TREE_OPERAND (inner_op, 1); tree gnu_size_op1 = TREE_OPERAND (gnu_size, 1); - wide_int op1; + widest_int op1; if (TREE_CODE (gnu_size) == MULT_EXPR) - op1 = wi::mul (inner_op_op1, gnu_size_op1); + op1 = (wi::to_widest (inner_op_op1) + * wi::to_widest (gnu_size_op1)); else - op1 = wi::add (inner_op_op1, gnu_size_op1); + op1 = (wi::to_widest (inner_op_op1) + + wi::to_widest (gnu_size_op1)); ops[1] = UI_From_gnu (wide_int_to_tree (sizetype, op1)); ops[0] = annotate_value (TREE_OPERAND (inner_op, 0)); }