From: Marc Glisse Date: Fri, 18 May 2018 22:21:20 +0000 (+0200) Subject: Aliasing 'this' in a C++ constructor X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dc2ebc998a679294a672ecb4f585d66c9f10f56e;p=gcc.git Aliasing 'this' in a C++ constructor 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. From-SVN: r260383 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 241e42a4a65..581f05076bc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-05-18 Marc Glisse + + PR c++/82899 + * tree-ssa-structalias.c (create_variable_info_for_1): Extra argument. + (intra_create_variable_infos): Handle C++ constructors. + 2018-05-18 Martin Liska * passes.def: Remove a redundant pass. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6ce3c16edf7..76e01699007 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-05-18 Marc Glisse + + PR c++/82899 + * g++.dg/pr82899.C: New testcase. + 2018-05-18 Martin Liska * gcc.dg/pr68766.c: Change pruned output. diff --git a/gcc/testsuite/g++.dg/pr82899.C b/gcc/testsuite/g++.dg/pr82899.C new file mode 100644 index 00000000000..0dee25f36e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr82899.C @@ -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" } } */ diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index d3b38c3eaf2..8fb13a0cdf8 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -5935,11 +5935,14 @@ check_for_overlaps (vec fieldstack) 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); @@ -6013,7 +6016,7 @@ create_variable_info_for_1 (tree decl, const char *name, bool add_id, 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)) @@ -6242,6 +6245,7 @@ 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 @@ -6253,10 +6257,12 @@ intra_create_variable_infos (struct function *fn) 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)