From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11119 invoked by alias); 29 Nov 2017 08:13:57 -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 11103 invoked by uid 89); 29 Nov 2017 08:13:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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; Wed, 29 Nov 2017 08:13:55 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71517796E5; Wed, 29 Nov 2017 08:13:54 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 064435C54A; Wed, 29 Nov 2017 08:13:53 +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 vAT8DpCP022375; Wed, 29 Nov 2017 09:13:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vAT8Dpw1022374; Wed, 29 Nov 2017 09:13:51 +0100 Date: Wed, 29 Nov 2017 08:24:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Improve build_simple_mem_ref_loc (PR middle-end/83185) Message-ID: <20171129081351.GU2353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02473.txt.bz2 Hi! This PR is about forwprop propagating: _17 = __builtin_alloca_with_align (_16, 256); _18 = _17 + 32; __builtin___asan_alloca_poison (_18, _8); _7 = &*_18[4]; __builtin_va_start (_7, 0); to: _17 = __builtin_alloca_with_align (_16, 256); _18 = _17 + 32; __builtin___asan_alloca_poison (_18, _8); _7 = &MEM[(struct [0:D.2257][1] *)_17 + 32B][4]; __builtin_va_start (_7, 0); which is something the verifiers allow and then backend VA_START handling calling build_simple_mem_ref_loc on the ADDR_EXPR it got. get_addr_base_and_unit_offset only looks through a MEM_REF if it has ADDR_EXPR as the first operand, which is not the case here, so nothing sums up the 96 offset from the [4] ARRAY_REF with the extra 32 from the MEM_REF. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-11-29 Jakub Jelinek PR middle-end/83185 * tree.c (build_simple_mem_ref_loc): Handle get_addr_base_and_unit_offset returning a MEM_REF. * gcc.dg/asan/pr83185.c: New test. --- gcc/tree.c.jj 2017-11-28 12:11:38.000000000 +0100 +++ gcc/tree.c 2017-11-28 17:22:01.800939050 +0100 @@ -4692,7 +4692,13 @@ build_simple_mem_ref_loc (location_t loc { ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset); gcc_assert (ptr); - ptr = build_fold_addr_expr (ptr); + if (TREE_CODE (ptr) == MEM_REF) + { + offset += mem_ref_offset (ptr).to_short_addr (); + ptr = TREE_OPERAND (ptr, 0); + } + else + ptr = build_fold_addr_expr (ptr); gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr)); } tem = build2 (MEM_REF, TREE_TYPE (ptype), --- gcc/testsuite/gcc.dg/asan/pr83185.c.jj 2017-11-28 17:24:15.540329283 +0100 +++ gcc/testsuite/gcc.dg/asan/pr83185.c 2017-11-28 17:24:19.851277394 +0100 @@ -0,0 +1,14 @@ +/* PR middle-end/83185 */ +/* { dg-do compile } */ + +#include + +int bar (void); + +void +foo (int i, ...) +{ + va_list aps[bar()]; + va_start (aps[4], i); + va_end (aps[4]); +} Jakub