From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 0D7E53858D37 for ; Wed, 17 Aug 2022 11:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D7E53858D37 Received: by mail-ej1-x632.google.com with SMTP id gk3so23980244ejb.8 for ; Wed, 17 Aug 2022 04:27:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=/UK90EvmOc/6BxJkRKDPKtGDvooKavNaJZGLZrPI34A=; b=5Br/G3PclqWYMlZTMNt0aGuZLBJsVf2U32blnOQuB3TMcUd1IJEIf4gu00P+zfGrOm o5RUvm88v1ExkLFtvHJQJ3K0fQd1ilaGkg7qCR7l07EZ8lh3dO0Z2Mkl6mceOYveujQ6 67Kk1daakYPIlWyjahORIRGM9MAdqT7FkPXYly95XqpwHrlPl7Tb2mWc0/58p1zqhRV+ 849KBW7slniQaUKFXcT/lhLE5GoyW6uYAsB5ARDTzSOlunkcdLFIVRfmHU14bRsJgNOt NDUMHvzjCxwXJD0wPZ48upDe78lIJuL5r4nnS6Fz1nDtcWZ7rk9eCvdUsrQw4VWttmqC WWrQ== X-Gm-Message-State: ACgBeo3YPSUNnJ62DbrqWDC5n4+j/VrjJ/U2zpyark/lAmUFHATguIZ5 wRehOT7MYbWxgBUQXzOGSdro+FKt5lMsTBGllDg= X-Google-Smtp-Source: AA6agR6V4ObB7PU5M7RHnibxedpLC5yRmwBby8+wjV6ynmqA00sfkPZSf4fzQDCb/YeYm8rKYmt7inwC2bCxjxpGXuU= X-Received: by 2002:a17:907:9712:b0:731:67db:1b48 with SMTP id jg18-20020a170907971200b0073167db1b48mr16256088ejc.754.1660735635460; Wed, 17 Aug 2022 04:27:15 -0700 (PDT) MIME-Version: 1.0 References: <3184807.aeNJFYEL58@arcturus> In-Reply-To: <3184807.aeNJFYEL58@arcturus> From: Richard Biener Date: Wed, 17 Aug 2022 13:27:03 +0200 Message-ID: Subject: Re: [PATCH] Fix bogus -Wstringop-overflow warning in Ada To: Eric Botcazou Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.3 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, 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-List-Received-Date: Wed, 17 Aug 2022 11:27:18 -0000 On Tue, Aug 16, 2022 at 3:57 PM Eric Botcazou via Gcc-patches wrote: > > Hi, > > the following bogus warning: > > In function 'lto26', > inlined from 'main' at /home/eric/gnat/bugs/V721-018/b~lto26.adb:237:7: > lto26.adb:11:13: warning: writing 1 byte into a region of size 0 [-Wstringop- > overflow=] > 11 | Set (R, (7, 0, 84, Stream_Element (I), 0, 0, 0), 1); > | ^ > lto26.adb: In function 'main': > lto26.adb:11:50: note: at offset -9223372036854775808 into destination object > 'A.0' of size 7 > 11 | Set (R, (7, 0, 84, Stream_Element (I), 0, 0, 0), 1); > | ^ > > comes from a discrepancy between get_offset_range, which uses a signed type, > and handle_array_ref, which uses an unsigned one, to do offset computations. > > Tested on x86-64/Linux, OK for the mainline? Hmm, can we instead do if (!integer_zerop (lowbnd) && tree_fits_shwi_p (lowbnd)) { const offset_int lb = offset_int::from (lowbnd, SIGNED); ... ? In particular interpreting the unsigned lowbnd as SIGNED when not wlb.get_precision () < TYPE_PRECISION (sizetype), offset_int should handle all positive and negative byte offsets since it can also represent them measured in bits. Unfortunately the wide_int classes do not provide the maximum precision they can handle. That said, the check, if any, should guard the whole orng adjustment, no? (in fact I wonder why we just ignore lowbnd if it doesn't fit or is variable...) > > > 2022-08-16 Eric Botcazou > > * pointer-query.cc (handle_array_ref): Fix handling of low bound. > > > 2022-08-16 Eric Botcazou > > * gnat.dg/lto26.adb: New test. > * gnat.dg/lto26_pkg1.ads, gnat.dg/lto26_pkg1.adb: New helper. > * gnat.dg/lto26_pkg2.ads, gnat.dg/lto26_pkg2.adb: Likewise. > > -- > Eric Botcazou