From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 85915 invoked by alias); 25 Jan 2018 21:58:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 85240 invoked by uid 89); 25 Jan 2018 21:58:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2520 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Jan 2018 21:58:27 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B404F4FCCF; Thu, 25 Jan 2018 21:58:25 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-22.ams2.redhat.com [10.36.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D2A660462; Thu, 25 Jan 2018 21:58:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w0PLwM6A003977; Thu, 25 Jan 2018 22:58:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0PLwKHR003976; Thu, 25 Jan 2018 22:58:20 +0100 Date: Thu, 25 Jan 2018 22:20:00 -0000 From: Jakub Jelinek To: Richard Biener , Jeff Law , Martin Sebor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix -Wrestrict SSA_NAME handling (PR c/83989) Message-ID: <20180125215820.GS2063@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg02137.txt.bz2 Hi! builtin_memref ctor for a SSA_NAME with non-NULL SSA_NAME_VAR returns the underlying variable, rather than just the SSA_NAME. Later on the code checks if the bases are equal and then compares corresponding offsets. The fact that two different SSA_NAMEs have the same underlying variable says nothing at all whether they have the same value, as the testcase shows, either the SSA_NAMEs can be completely unrelated, or related, but with different offsets. The code already has code to handle POINTER_PLUS_EXPR with a constant offset, to look through that. Perhaps in the future there can be other cases we'd special case, but generally we should compare as bases the SSA_NAMEs, if they have the same or different base says nothing about them. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-01-25 Jakub Jelinek PR c/83989 * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Don't use SSA_NAME_VAR as base for SSA_NAMEs with non-NULL SSA_NAME_VAR. * c-c++-common/Wrestrict-3.c: New test. --- gcc/gimple-ssa-warn-restrict.c.jj 2018-01-17 11:54:17.000000000 +0100 +++ gcc/gimple-ssa-warn-restrict.c 2018-01-25 14:10:26.182498552 +0100 @@ -373,9 +373,6 @@ builtin_memref::builtin_memref (tree exp offrange[1] += off; } } - - if (TREE_CODE (base) == SSA_NAME && SSA_NAME_VAR (base)) - base = SSA_NAME_VAR (base); } if (size) --- gcc/testsuite/c-c++-common/Wrestrict-3.c.jj 2018-01-25 14:16:01.574563425 +0100 +++ gcc/testsuite/c-c++-common/Wrestrict-3.c 2018-01-25 14:14:39.273547506 +0100 @@ -0,0 +1,48 @@ +/* PR c/83989 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wrestrict" } */ + +__attribute__((__malloc__)) extern void *my_malloc (__SIZE_TYPE__); +void baz (void *); + +#define SIZE 32 + +void +foo (void) +{ + void *recmem = __builtin_malloc (SIZE); + baz (recmem); + while (1) + { + void *oldrecmem = recmem; + recmem = __builtin_malloc (SIZE); + if (!recmem) + { + __builtin_free (oldrecmem); + return; + } + __builtin_memcpy (recmem, oldrecmem, SIZE); /* { dg-bogus "accessing" } */ + baz (recmem); + __builtin_free (oldrecmem); + } +} + +void +bar (void) +{ + void *recmem = my_malloc (SIZE); + baz (recmem); + while (1) + { + void *oldrecmem = recmem; + recmem = my_malloc (SIZE); + if (!recmem) + { + __builtin_free (oldrecmem); + return; + } + __builtin_memcpy (recmem, oldrecmem, SIZE); /* { dg-bogus "accessing" } */ + baz (recmem); + __builtin_free (oldrecmem); + } +} Jakub