From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-306dbad5182so1194741f8f.1 for ; Thu, 18 May 2023 02:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684403467; x=1686995467; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=974t5yJOUUIAuS0FmdylNC7LzCJTaDjsBgG8FBTXmU0=; b=PucDW3kbUEprD5eba0KjQsW+jXdmDUmivLRrv2qebG+t3+sqXgtED7uXhfwHyBsS27 gNBlmSo8U/crd+/S8xWCCYPBq5+agGwC/cYQiWvwjNdhw4i9mxeVydAjrB3MT50i4Pvu KbbmECvE2zz/08eC+VQGHDBdAkJziqfEio7sHSQRHEUndUicQbSIj3Vmvi1+BnHhW797 +17aD+U0EZgB6nZJSusmrMG9MVZ/V644MG1m84K2z5UklsVJGdq31V+DJHDICjEAKZg+ 3aNuIVo4su0+0RRXmPh3nfkBgsFWmK6YY+qBnkqmvoVTyNe5gWCdkgHxQLwL+P6lRktj HJ7g== 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-Google-Smtp-Source: ACHHUZ6HUAArW0mcRXyfrZAsOWg+aO9KENRkTNfIC8hjBZC9JsgBlAOH5upC0lcF1eHFCvFOOd9P+g== 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) From: Eric Botcazou 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 Content-Type: multipart/mixed; boundary="nextPart1851970.tdWV9SEqCh" Content-Transfer-Encoding: 7Bit 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 List-Id: This is a multi-part message in MIME format. --nextPart1851970.tdWV9SEqCh Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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. -- Eric Botcazou --nextPart1851970.tdWV9SEqCh Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" 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. */ --nextPart1851970.tdWV9SEqCh Content-Disposition: attachment; filename="array6.ads" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="array6.ads" -- { dg-do compile } package Array6 is type Range_Type is range -10 .. 10; type Array_Type is array (Range_Type range <> ) of Short_Short_Integer; type Record_Type is record A : Array_Type(-2..4); end record ; Rec : Record_Type := (A => (others => -1)); end Array6; --nextPart1851970.tdWV9SEqCh--