From patchwork Thu May 18 09:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 95732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp366100vqo; Thu, 18 May 2023 02:51:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GYwfXits4zBJ6HK+oPTJkqq9SSutGqaI5J6DEy1ZdPsNsgoupKOQ0z4YoDg59k5LStzxt X-Received: by 2002:a17:907:7da9:b0:966:538f:843b with SMTP id oz41-20020a1709077da900b00966538f843bmr36344179ejc.77.1684403516420; Thu, 18 May 2023 02:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684403516; cv=none; d=google.com; s=arc-20160816; b=iiXl/3SsHWxIbPHemdx2vapeu8BaNHQtC2t6t7T+Nc2qWZJhx2avOG+ghl61yzs59a UR48TCIwdwRbOOOrTECAz66aLp2M7jGSHhYuLF+rgcip3czbLDrHkRAoKz2vMQhZOTbi sFqpLL7IJpKYAug6ZdJVmBI2ZF5SMZNJULqvmVaLwXz31SGzZ8mcPl5qnos9rZwCoGWO 48i+GtOxGY/6pUkAAkf3kenwVJ744VYKQogkR5VgNUH7RqbHE9lqG5oLWhKw78DjzFSs wzPEI/GQT5bCiURmos+69NLEIgVF7MRXU8WVdDcGAGwoL+bSFpSPOGKjanpKEv+lpT28 utZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=974t5yJOUUIAuS0FmdylNC7LzCJTaDjsBgG8FBTXmU0=; b=OWQgxmEAsCfW/QTyBPWVx78j+lS/t5utox7ISQwcZtY0U8r1LeU6ofYkfuQ58uINqE 6iWGB1zMUiQF2h64I11Fd9DEAXEZlzTfZ5gNOssXXRbuKtxYYEiWPqNfi7kN89/ijNRu YVQQHPqR2K1rZG/s4cKAxGfN1cCcpXGO4yrEyW00ukDfbLySHwLSKHjb1F9I9/sXHB2q B5QArZojN5esAKriy+vvF8P9XLyhC3gNV+HUixQsMnsa1Z+Rp3kBPk0GF4ZFQywlAdiZ tnHxAo0K4CQ975KpBATAVtyVlB6q7quVLPxFmjM85cP/w1NC+zFt1sH+u7ELVsaGUbaZ WaMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KDUTWUFY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j8-20020a170906474800b00965f9352c46si1070114ejs.372.2023.05.18.02.51.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 02:51:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KDUTWUFY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51A74385770F for ; Thu, 18 May 2023 09:51:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51A74385770F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684403515; bh=974t5yJOUUIAuS0FmdylNC7LzCJTaDjsBgG8FBTXmU0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KDUTWUFYUS7NGtv7F5ja1br4nKbiWFOhqQ6SyQt5b8iZ7lSZ1CoaHL8iubQC5nymO joFaE7Ag4L3g3E6Y+i8hCGxH7EX/3B2r0m8xmYvAsU6mcSKtAb8MvPDDEri0TxmZr/ AYoIusJR/aSkxcyXW3MwT+H9saCZHjZqYWYLdFo8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 8FF203858CDB for ; Thu, 18 May 2023 09:51:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FF203858CDB Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-306dbad5182so1194741f8f.1 for ; Thu, 18 May 2023 02:51:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684403467; x=1686995467; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=974t5yJOUUIAuS0FmdylNC7LzCJTaDjsBgG8FBTXmU0=; b=WNqdD4ICeTP25gt7uCmLtx4sWZ1TeheuJGwhrjJPZ7u3RUKfCWdPpB8qC46RoaCFbE 7LK1VTLYYtw50jh7S3z8IGflOh9xnlOgYXYuVRKgtk7scg5HgWgN1E+SrrLt7amm0HeE FwqzWKBMAeuNDsrspuJ119dI76Gr+ZJMF4vB6XOU+OUfKaKO2C70tOI7IvIuxkkNpAOr F7u/mRa0yVXdeCtiqRQEiukvoBAgW6rbYfMN2rQawypgzSjK1iD44uZHxfjIV7QNO7dO hideK0z7z5YwdWu5JprOE/Tq1nceDJ+PtUZvFHKBb7SNapgOc+VKAohSiygZhBlgJDOD pBWA== X-Gm-Message-State: AC+VfDxFATk9jJEMOexN5Lf3ErHs9ELyVtwrbOXoncShmgikDogU2loQ /63bMLX6NtjQZbA0h/Hw8NmLQpHsBfzHwYhb/rfNpQ== X-Received: by 2002:a5d:574b:0:b0:306:3286:69a2 with SMTP id q11-20020a5d574b000000b00306328669a2mr894764wrw.48.1684403467206; Thu, 18 May 2023 02:51:07 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id e18-20020a056000121200b0030796e103a1sm1665293wrx.5.2023.05.18.02.51.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 02:51:06 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix internal error on small array with negative lower bound Date: Thu, 18 May 2023 11:28:51 +0200 Message-ID: <4801877.GXAFRqVoOG@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766225101584097617?= X-GMAIL-MSGID: =?utf-8?q?1766225101584097617?= Hi, Ada supports arrays with negative indices, although the internal index type is sizetype like in other languages, which is unsigned. This means that negative values are represented by very large numbers, which works with a bit of care. The attached test exposes a small loophole in output_constructor_bitfield. Tested on x86-64/Linux, OK for the mainline? 2023-05-18 Eric Botcazou * varasm.cc (output_constructor_bitfield): Call tree_to_uhwi instead of tree_to_shwi on array indices. Minor tweaks. 2023-05-18 Eric Botcazou * gnat.dg/specs/array6.ads: New test. diff --git a/gcc/varasm.cc b/gcc/varasm.cc index 2256194d934..478cbfe6736 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -5585,19 +5585,18 @@ output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset) /* Relative index of this element if this is an array component. */ HOST_WIDE_INT relative_index - = (!local->field - ? (local->index - ? (tree_to_shwi (local->index) - - tree_to_shwi (local->min_index)) - : local->last_relative_index + 1) - : 0); + = (local->field + ? 0 + : (local->index + ? tree_to_uhwi (local->index) - tree_to_uhwi (local->min_index) + : local->last_relative_index + 1)); /* Bit position of this element from the start of the containing constructor. */ HOST_WIDE_INT constructor_relative_ebitpos - = (local->field - ? int_bit_position (local->field) - : ebitsize * relative_index); + = (local->field + ? int_bit_position (local->field) + : ebitsize * relative_index); /* Bit position of this element from the start of a possibly ongoing outer byte buffer. */