From patchwork Fri May 18 12:24:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 916264 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-477921-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="csf5mgLh"; 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 40nS6p3FsYz9s33 for ; Fri, 18 May 2018 22:25:05 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=SWCN6wHjAHT2x4iRi1M+RZ0t2qXSv0z0wMXkAUk7Of5Nt3KFnOOS0 TitrSDtbgjZPBfBPEiy5yiMm/HVrBLCaf5AfS00xO1GAubnRKhDYk8NBLiv8hdax si4AyDX6bUbkhsXv1D8tG7VSCSqfh2/BAu4pGavq5XONkpXSoCxyZs= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=QeFcazSLBWuYSDLR0TOjpByOlL4=; b=csf5mgLhtFz+Eab3IqGb M+enRIK0CMZOCYEOYJdgTB6u2UmL8vpQugtadKKB4hquy+gUtb1H9mT1jUdjkwgX NSsoMwh3bj+KV5CRs3YzHWfBUJp5dnemmcgMymZiiSG5eJj8CUSZvtZaNxVKOXx5 wWeA17AdUA8SqW22WpTK0VM= Received: (qmail 82957 invoked by alias); 18 May 2018 12:24:57 -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 82913 invoked by uid 89); 18 May 2018 12:24:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=pretend, DECL_P, H*c:HHHHHHH, H*c:HHHH X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 May 2018 12:24:50 +0000 Received: from ip-34.net-89-2-101.rev.numericable.fr (HELO stedding) ([89.2.101.34]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 May 2018 14:24:47 +0200 Date: Fri, 18 May 2018 14:24:43 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Aliasing 'this' in a C++ constructor Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, this lets alias analysis handle the implicit 'this' parameter in C++ constructors as if it was restrict. Bootstrap+regtest on powerpc64le-unknown-linux-gnu. 2018-05-18 Marc Glisse PR c++/82899 gcc/ * tree-ssa-structalias.c (create_variable_info_for_1): Extra argument. (intra_create_variable_infos): Handle C++ constructors. gcc/testsuite/ * g++.dg/pr82899.C: New testcase. Index: gcc/testsuite/g++.dg/pr82899.C =================================================================== --- gcc/testsuite/g++.dg/pr82899.C (nonexistent) +++ gcc/testsuite/g++.dg/pr82899.C (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +struct A { + int i; + A(A&); +}; +int X; +A::A(A&a):i(42){ + a.i=0; + X=i; +} + +/* { dg-final { scan-tree-dump "X = 42;" "optimized" } } */ Index: gcc/tree-ssa-structalias.c =================================================================== --- gcc/tree-ssa-structalias.c (revision 260347) +++ gcc/tree-ssa-structalias.c (working copy) @@ -5928,25 +5928,28 @@ check_for_overlaps (vec fiel return true; lastoffset = fo->offset; } return false; } /* Create a varinfo structure for NAME and DECL, and add it to VARMAP. This will also create any varinfo structures necessary for fields of DECL. DECL is a function parameter if HANDLE_PARAM is set. HANDLED_STRUCT_TYPE is used to register struct types reached by following - restrict pointers. This is needed to prevent infinite recursion. */ + restrict pointers. This is needed to prevent infinite recursion. + If ADD_RESTRICT, pretend that the pointer NAME is restrict even if DECL + does not advertise it. */ static varinfo_t create_variable_info_for_1 (tree decl, const char *name, bool add_id, - bool handle_param, bitmap handled_struct_type) + bool handle_param, bitmap handled_struct_type, + bool add_restrict = false) { varinfo_t vi, newvi; tree decl_type = TREE_TYPE (decl); tree declsize = DECL_P (decl) ? DECL_SIZE (decl) : TYPE_SIZE (decl_type); auto_vec fieldstack; fieldoff_s *fo; unsigned int i; if (!declsize || !tree_fits_uhwi_p (declsize)) @@ -6006,21 +6009,21 @@ create_variable_info_for_1 (tree decl, c if (fieldstack.length () == 0 || fieldstack.length () > MAX_FIELDS_FOR_FIELD_SENSITIVE) { vi = new_var_info (decl, name, add_id); vi->offset = 0; vi->may_have_pointers = true; vi->fullsize = tree_to_uhwi (declsize); vi->size = vi->fullsize; vi->is_full_var = true; if (POINTER_TYPE_P (decl_type) - && TYPE_RESTRICT (decl_type)) + && (TYPE_RESTRICT (decl_type) || add_restrict)) vi->only_restrict_pointers = 1; if (vi->only_restrict_pointers && !type_contains_placeholder_p (TREE_TYPE (decl_type)) && handle_param && !bitmap_bit_p (handled_struct_type, TYPE_UID (TREE_TYPE (decl_type)))) { varinfo_t rvi; tree heapvar = build_fake_var_decl (TREE_TYPE (decl_type)); DECL_EXTERNAL (heapvar) = 1; @@ -6235,35 +6238,38 @@ make_param_constraints (varinfo_t vi) } /* Create varinfo structures for all of the variables in the function for intraprocedural mode. */ static void intra_create_variable_infos (struct function *fn) { tree t; bitmap handled_struct_type = NULL; + bool this_parm_in_ctor = DECL_CXX_CONSTRUCTOR_P (fn->decl); /* For each incoming pointer argument arg, create the constraint ARG = NONLOCAL or a dummy variable if it is a restrict qualified passed-by-reference argument. */ for (t = DECL_ARGUMENTS (fn->decl); t; t = DECL_CHAIN (t)) { if (handled_struct_type == NULL) handled_struct_type = BITMAP_ALLOC (NULL); varinfo_t p = create_variable_info_for_1 (t, alias_get_name (t), false, true, - handled_struct_type); + handled_struct_type, this_parm_in_ctor); insert_vi_for_tree (t, p); make_param_constraints (p); + + this_parm_in_ctor = false; } if (handled_struct_type != NULL) BITMAP_FREE (handled_struct_type); /* Add a constraint for a result decl that is passed by reference. */ if (DECL_RESULT (fn->decl) && DECL_BY_REFERENCE (DECL_RESULT (fn->decl))) { varinfo_t p, result_vi = get_vi_for_tree (DECL_RESULT (fn->decl));