From patchwork Sat Sep 21 22:38:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1165662 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-509411-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EcFXbOGx"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ENO2sSYD"; 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 46bQVj3lNRz9sP3 for ; Sun, 22 Sep 2019 08:39:06 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=NfjmvtE7BvBx09r257DathhLsbLzK4sPJaD9s9GLPiNcFkL2Ou PfAy1BvizCTXbrzTXDm/59+8VahgHMUKmePTWgyYJG5pkhTpvqzmdnGT2/73ya6e dvIHf+kn0oec7Zprv+KON3KMQgRUxlJxT9NmERiA0uKHnqcsgn7qPayDM= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=Jjftmbjv4FIt/xZJmhC4pLKtP+8=; b=EcFXbOGx+aBhnoEmnmTx 57QVextgBDHhcGdj+BEaqW9EgX0hsrbitnp9bUH6UNxBEYSe1khs3xb4UlI9SWg8 2zyC0xw96YCY1c7wk4bp0YAY1gRbfw3a2WRmvEpuv5AGMA8yKn5rcXhywFeSO6Z+ CwanesUQJP3nsuUvWfkPXOc= Received: (qmail 27093 invoked by alias); 21 Sep 2019 22:38:58 -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 27079 invoked by uid 89); 21 Sep 2019 22:38:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-io1-f43.google.com Received: from mail-io1-f43.google.com (HELO mail-io1-f43.google.com) (209.85.166.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 21 Sep 2019 22:38:54 +0000 Received: by mail-io1-f43.google.com with SMTP id b19so24485031iob.4 for ; Sat, 21 Sep 2019 15:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=lzjDvTx7JfgBk9k20FnDzLgi7W+I1tvkNY5zcSeKV5s=; b=ENO2sSYD5miAPaqx6VDXhXf6pcllIkjnCs8amY0vOjcZla0y+hLLGp453XiyklKOZ3 VzPjfBzdby9ILq7/CjuRF4LJM5wNA/OnbNM2pqraERSf/H5L7ayGWycKl/5QKMwjeD90 OPzyE7jaj8jOf4PSjceHcClbSv/ZG5CVEaZT0kICk24KWswnKYDCuKikOrK98pFuy29O U3dq8xm3vbemi2tZM2XmbDF0pGQU4TUWLUMYF7tqfMASq6y1GSUdDweOzKV55Gd6nypK lvSPGOpkAc4I+Jjf4+fIhL5IehGx2uvaPi69PhVCbAjULhomj6Euvi8pFznFAqvskL9T J6EQ== Received: from [192.168.0.41] (97-118-126-194.hlrn.qwest.net. [97.118.126.194]) by smtp.gmail.com with ESMTPSA id c6sm5435495iom.34.2019.09.21.15.38.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Sep 2019 15:38:51 -0700 (PDT) To: gcc-patches From: Martin Sebor Subject: [committed] avoid bogus warning on strcpy into nested member array (PR 91830) Message-ID: <3faa094e-8cf8-3915-0de2-25eca5bacde2@gmail.com> Date: Sat, 21 Sep 2019 16:38:50 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 X-IsSubscribed: yes The recent improvement to -Warray-bounds to detect past-the-end accesses by string functions to member subobjects had a bug that triggered a false positive in a Binutils build. In r276022 I've committed the attached trivial fix to correct the bug. Martin Index: gcc/ChangeLog =================================================================== Index: gcc/testsuite/gcc.dg/Warray-bounds-47.c =================================================================== --- gcc/testsuite/gcc.dg/Warray-bounds-47.c (nonexistent) +++ gcc/testsuite/gcc.dg/Warray-bounds-47.c (revision 276022) @@ -0,0 +1,429 @@ +/* PR middle-end/91830 - Bogus -Warray-bounds on strcpy into a member + of a subobject compiling binutils + { dg-do compile } + { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */ + +extern char* strcpy (char*, const char*); +extern void sink (void*); + +#define S36 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + +#define S(N) (S36 + sizeof (S36) - N - 1) + +/* In the test macro, prevent the strcpy to memcpy transformation + by using a local array initialized with the string literal. Without + it, GCC transforms the strcpy call with memcpy which (unfortunately) + permits accesses that cross subobject boundaries. */ +#define T(obj, mem, n) \ + do { \ + struct A *pa = &obj; \ + const char a[] = S36; \ + strcpy (pa->mem, a + sizeof a - n - 1); \ + sink (&obj); \ + } while (0) + + +struct A { char a[3]; char b[5]; }; +struct B { char c[7]; struct A a; struct A a2[2]; }; + +extern struct B b[]; + +void array_nowarn (int i) +{ + struct B *pb = b; + + T (pb[0].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[1].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[123].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[i].a, a, 0); + T (pb[i].a, a, 1); + T (pb[i].a, a, 2); + + + T (pb[0].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a, b, 0); + T (pb[i].a, b, 1); + T (pb[i].a, b, 2); + T (pb[i].a, b, 3); + T (pb[i].a, b, 4); + + + T (pb[0].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a2[0], b, 0); + T (pb[i].a2[0], b, 1); + T (pb[i].a2[0], b, 2); + T (pb[i].a2[0], b, 3); + T (pb[i].a2[0], b, 4); + + T (pb[i].a2[1], b, 0); + T (pb[i].a2[1], b, 1); + T (pb[i].a2[1], b, 2); + T (pb[i].a2[1], b, 3); + T (pb[i].a2[1], b, 4); +} + +void array_warn (int i) +{ + struct B *pb = b; + + T (pb[0].a, a, 3); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, a, 4); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, a, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, a, 8); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[0].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[0].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + T (pb[0].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } +} + +void ptr_nowarn (struct B *pb, int i) +{ + T (pb[-123].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[-2].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[-1].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[0].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[1].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[123].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, a, 2); // { dg-bogus "\\\[-W" } + + T (pb[i].a, a, 0); // { dg-bogus "\\\[-W" } + T (pb[i].a, a, 1); // { dg-bogus "\\\[-W" } + T (pb[i].a, a, 2); // { dg-bogus "\\\[-W" } + + + T (pb[-123].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[-123].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-2].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[-2].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-1].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[-1].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[0].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a, b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a, b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a, b, 0); + T (pb[i].a, b, 1); + T (pb[i].a, b, 2); + T (pb[i].a, b, 3); + T (pb[i].a, b, 4); + + + T (pb[-123].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-2].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-1].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[0].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[0], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[0], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a2[0], b, 0); + T (pb[i].a2[0], b, 1); + T (pb[i].a2[0], b, 2); + T (pb[i].a2[0], b, 3); + T (pb[i].a2[0], b, 4); + + T (pb[-123].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-123].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-2].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-2].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[-1].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[-1].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[0].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[0].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[1].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[1].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[123].a2[1], b, 0); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 1); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 2); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 3); // { dg-bogus "\\\[-W" } + T (pb[123].a2[1], b, 4); // { dg-bogus "\\\[-W" } + + T (pb[i].a2[1], b, 0); + T (pb[i].a2[1], b, 1); + T (pb[i].a2[1], b, 2); + T (pb[i].a2[1], b, 3); + T (pb[i].a2[1], b, 4); + + T (pb[i].a2[i], b, 0); + T (pb[i].a2[i], b, 1); + T (pb[i].a2[i], b, 2); + T (pb[i].a2[i], b, 3); + T (pb[i].a2[i], b, 4); +} + +void ptr_warn (struct B *pb, int i) +{ + T (pb[-987].a, a, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a, a, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a, a, 3); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a, a, 4); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a, a, 3); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, a, 4); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, a, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, a, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, a, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, a, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, a, 3); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, a, 4); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, a, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[-987].a, b, 10); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a, b, 9); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a, b, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a, b, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a, b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a, b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a, b, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a, b, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a, b, 9); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a, b, 10); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a, b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a, b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + + T (pb[-987].a2[0], b, 10); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a2[0], b, 9); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a2[0], b, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a2[0], b, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[0], b, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[0], b, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[0], b, 9); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[0], b, 10); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[0], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[0], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[0], b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + T (pb[-987].a2[1], b, 10); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-654].a2[1], b, 9); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-2].a2[1], b, 8); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-2].a2[1], b, 7); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[-1].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + T (pb[-1].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[0].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" } + T (pb[0].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[1].a2[1], b, 7); // { dg-warning "\\\[-Warray-bounds" } + T (pb[1].a2[1], b, 8); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[789].a2[1], b, 9); // { dg-warning "\\\[-Warray-bounds" } + T (pb[789].a2[1], b, 10); // { dg-warning "\\\[-Warray-bounds" } + + T (pb[i].a2[1], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[1], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[1], b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + + T (pb[i].a2[i], b, 5); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[i], b, 6); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } + T (pb[i].a2[i], b, 7); // { dg-warning "\\\[-Warray-bounds" "pr91848" { xfail *-*-* } } +} Index: gcc/testsuite/ChangeLog =================================================================== Index: gcc/gimple-ssa-warn-restrict.c =================================================================== --- gcc/gimple-ssa-warn-restrict.c (revision 276021) +++ gcc/gimple-ssa-warn-restrict.c (revision 276022) @@ -517,14 +517,8 @@ builtin_memref::set_base_and_offset (tree expr) struct S { char a, b[3]; } s[2]; strcpy (s[1].b, "1234"); REFOFF is set to s[1].b - (char*)s. */ - tree basetype = TREE_TYPE (TREE_TYPE (base)); - if (tree basesize = TYPE_SIZE_UNIT (basetype)) - if (TREE_CODE (basesize) == INTEGER_CST) - { - offset_int size = wi::to_offset (basesize); - offset_int off = tree_to_shwi (memrefoff); - refoff += size * (off / size); - } + offset_int off = tree_to_shwi (memrefoff); + refoff += off; } if (!integer_zerop (memrefoff))