From patchwork Thu Aug 1 08:27:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1140343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505961-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IHvvNKyM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45zk1x6sRNz9sN6 for ; Thu, 1 Aug 2019 18:27:47 +1000 (AEST) 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 :content-transfer-encoding; q=dns; s=default; b=FXHJwj45Ys74zpfv p/p1ZDCbI0bsAKrzdohXTCeP96eD7ELp6IbAbcRg8mLzd34CfkncDD8WXt+P415E HqhzgxXW/SY6KUwai9K5pcOZlpL7GT5eqEWY/++fM+mpWqUCAhBMfXkk+VyGmCN2 GqxD6lx4OsA4Rg/ZumgVsFt5EKI= 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 :content-transfer-encoding; s=default; bh=3dvCH1EVSJScCRGeI/p2R4 275SQ=; b=IHvvNKyM5/96flAoG9PY1Ze3J5AMhzgR5OrC8hP+dmHeCDfhNDFROp pNxL88D+RFqFAIQ8Ev2R6Je+fFnUcsHqEXh+OulHqxW495Zp34ukI85Ny4TpdpcA H3u/Y1JVWA0YrQzoU8QdgrfZUq5W6obRakc4QCvcTsmwNgAHUszRc= Received: (qmail 12437 invoked by alias); 1 Aug 2019 08:27:41 -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 12428 invoked by uid 89); 1 Aug 2019 08:27:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=respectfully, H*M:home, H*MI:home, fold-const.c X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Aug 2019 08:27:39 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 8DEB18137F for ; Thu, 1 Aug 2019 10:27:36 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7LG8etlbmHMD for ; Thu, 1 Aug 2019 10:27:36 +0200 (CEST) Received: from arcturus.home (adijon-653-1-80-34.w90-33.abo.wanadoo.fr [90.33.75.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 5DDC581368 for ; Thu, 1 Aug 2019 10:27:36 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix tree-optimization/91169 Date: Thu, 01 Aug 2019 10:27:43 +0200 Message-ID: <1764855.0oU1eeNi03@arcturus.home> MIME-Version: 1.0 Hi, this fixes the cd2a31a regression in the ACATS testsuite on 32-bit targets introduced by the recent change to get_array_ctor_element_at_index: * fold-const.h (get_array_ctor_element_at_index): Adjust. * fold-const.c (get_array_ctor_element_at_index): Add ctor_idx output parameter informing the caller where in the constructor the element was (not) found. Add early exit for when the ctor is sorted. This change overlooks that the index can wrap around during the traversal of the CONSTRUCTOR and therefore causes the function to return bogus values as soon as this happens. Moreover, given this chunk of added code: else if (in_gimple_form) /* We're past the element we search for. Note during parsing the elements might not be sorted. ??? We should use a binary search and a flag on the CONSTRUCTOR as to whether elements are sorted in declaration order. */ break; I would respectfully suggest that the author thinks about redoing things from scratch here. In the meantime, the attached patch kludges around the issue. Tested on x86_64-suse-linux, OK for the mainline? 2019-08-01 Eric Botcazou PR tree-optimization/91169 * fold-const.c (get_array_ctor_element_at_index): Remove early exit and do not return a bogus ctor_idx when the index wraps around. Index: fold-const.c =================================================================== --- fold-const.c (revision 273907) +++ fold-const.c (working copy) @@ -11841,9 +11841,9 @@ fold_ternary_loc (location_t loc, enum tree_code c /* Gets the element ACCESS_INDEX from CTOR, which must be a CONSTRUCTOR of an array (or vector). *CTOR_IDX if non-NULL is updated with the constructor element index of the value returned. If the element is - not found NULL_TREE is returned and *CTOR_IDX is updated to - the index of the element after the ACCESS_INDEX position (which - may be outside of the CTOR array). */ + not found, then NULL_TREE is returned and *CTOR_IDX is updated to + the index of the element after the ACCESS_INDEX position (which may + be outside of the CTOR array). */ tree get_array_ctor_element_at_index (tree ctor, offset_int access_index, @@ -11874,8 +11874,9 @@ get_array_ctor_element_at_index (tree ctor, offset TYPE_SIGN (index_type)); offset_int max_index; - unsigned cnt; + unsigned cnt, after_cnt; tree cfield, cval; + bool after_cnt_valid = false; FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), cnt, cfield, cval) { @@ -11895,10 +11896,15 @@ get_array_ctor_element_at_index (tree ctor, offset } else { + const offset_int old_index = index; index += 1; if (index_type) - index = wi::ext (index, TYPE_PRECISION (index_type), - TYPE_SIGN (index_type)); + { + index = wi::ext (index, TYPE_PRECISION (index_type), + TYPE_SIGN (index_type)); + if (wi::cmpu (index, old_index) <= 0) + after_cnt_valid = false; + } max_index = index; } @@ -11912,16 +11918,20 @@ get_array_ctor_element_at_index (tree ctor, offset return cval; } } - else if (in_gimple_form) - /* We're past the element we search for. Note during parsing - the elements might not be sorted. - ??? We should use a binary search and a flag on the - CONSTRUCTOR as to whether elements are sorted in declaration - order. */ - break; + + /* We may be past the element we search for. Note that during parsing + the elements might not be sorted. Note also that the index may wrap + around during the traversal of the constructor if it was signed. + ??? We should use a binary search and a flag on the CONSTRUCTOR as + to whether elements are sorted in declaration order. */ + else if (in_gimple_form && !after_cnt_valid) + { + after_cnt = cnt; + after_cnt_valid = true; + } } if (ctor_idx) - *ctor_idx = cnt; + *ctor_idx = after_cnt_valid ? after_cnt : cnt; return NULL_TREE; }