From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 23341386EC41 for ; Sun, 14 Mar 2021 08:12:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 23341386EC41 Received: by mail-pj1-x102e.google.com with SMTP id s21so7216118pjq.1 for ; Sun, 14 Mar 2021 00:12:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:references:in-reply-to :subject:date:mime-version:content-transfer-encoding:importance; bh=t2tzDwkqgqahz1beUKnAQTixLki1jQbraFMMGnqjPiQ=; b=g1nB/DcznyvbTrFkf2x+Qg+LtiH/NgrVT+2n+P8eFNRaljPSeo1rAfZt6GLi5cZADT +kKyIYBDFqepDkEpVEP933RnmOsDuSm4mNqn7REWs5clzR/5r3uYr4Xw7GjdEOEXGm7g GWoi7445NQioJB7qIi0ltWLoAfUFBTt5itIpqLYnwskbo0kGsvCWEQdUZ4VODEac/vlm seGBSQIRlOjx5OOQM81RYdu2uv+WYOSjGq40Fmh+hQDQMxAZfSGVwN37iLpVYc3OpS68 2tjpqWAVRjHPcTNqZrZv725BuZ33vNO2I4fl2sSypmUqQqQSILcf1J7N8A8xwpmplZsD dhfg== X-Gm-Message-State: AOAM5322bRiBgshxzZBU6V27JoaVZFuMhueACdjvdur+4L6LWRdDpEF7 6uA0QCFLiZR9ZdECRN5JFz9hUuxXq04= X-Google-Smtp-Source: ABdhPJzHELNeGLIt4xSGZS0PP+GZR6v6UKNfwW4MsjoJ0CGWUvZk9xqkTjdy8NJvlTlLT/DQMk98qQ== X-Received: by 2002:a17:90a:1696:: with SMTP id o22mr6906230pja.0.1615709526865; Sun, 14 Mar 2021 00:12:06 -0800 (PST) Received: from DESKTOP0OKG1VA ([202.169.113.201]) by smtp.gmail.com with ESMTPSA id 21sm9795928pgf.69.2021.03.14.00.12.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Mar 2021 00:12:06 -0800 (PST) Message-ID: From: "Paul Edwards" To: , "Richard Biener" References: <200911241405.nAOE5Jsd022678@d12av02.megacenter.de.ibm.com> <7B52F224E6EE465EB95237D5A0D9A15F@Paullaptop> <84fc9c000911280802j3a0be6b1p1241d81d91f0672e@mail.gmail.com> <7926CAF0-69E7-415D-B635-B7C004EC838A@gmail.com> In-Reply-To: <7926CAF0-69E7-415D-B635-B7C004EC838A@gmail.com> Subject: Re: negative indexes Date: Sun, 14 Mar 2021 19:12:01 +1100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 16.4.3528.331 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, STOX_REPLY_TYPE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Mar 2021 08:12:10 -0000 Hi Richard. Thanks for your reply, but if I understand you correctly, you are saying this fix is for situations where the size of an integer is different from the size of a pointer? That is not my issue. The size is the same. Absolutely everything is 32-bits in the program (long, int, char *, void *, code addresses). However, since I am running as AMODE 64, if someone attempts to do an index by adding two 32-bit registers together in a single instruction, that reference will actually take effect, and go up into the 4 GiB to 8 GiB region. Is your answer still applicable (I don't really understand your answer. :-) ). Thanks. Paul. -----Original Message----- From: Richard Biener Sent: Sunday, March 14, 2021 7:05 PM To: Paul Edwards ; Paul Edwards via Gcc ; gcc@gcc.gnu.org Subject: Re: negative indexes On March 14, 2021 6:55:32 AM GMT+01:00, Paul Edwards via Gcc wrote: >If I have code like this: > >char foo(char *p) >{ > return (p[-1]); >} > >It generates a negative index, like this: > >* Function foo code > L 2,=F'-1' > L 3,0(11) > SLR 15,15 > IC 15,0(2,3) >* Function foo epilogue > >See that (2,3) - that is adding both R2 + R3. >R3 is a pointer to a location in 4 GiB space. >R2 is now 0xFFFFFFFF > >In 64-bit mode, both of those values are added >together and there is no address wrap, so it >accesses memory above the 4 GiB boundary >(between 4 GiB and 8 GiB to be precise) >which I don't have access to. > >Is there a way of constraining index registers to positive >values? > >I want it to instead generate >ALR 3,2 >to add these two values together using 32-bit arithmetic, >causing truncation at 32 bits, then it can do >IC 15,0(3) >(ie no index) > >I'm using GCC 3.2.3 using the i370 target if it makes a difference. You are likely missing a fix that sign extends offsets on Pmode!=ptr_mode targets. 3.2.3 is really old now ;) Richard. >Thanks. Paul.