Aliasing 'this' in a C++ constructor

2018-05-18  Marc Glisse  <marc.glisse@inria.fr>

	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
This commit is contained in:
Marc Glisse 2018-05-19 00:21:20 +02:00 committed by Marc Glisse
parent 8b0cd47a1c
commit dc2ebc998a
4 changed files with 35 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2018-05-18 Marc Glisse <marc.glisse@inria.fr>
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 <mliska@suse.cz>
* passes.def: Remove a redundant pass.

View File

@ -1,3 +1,8 @@
2018-05-18 Marc Glisse <marc.glisse@inria.fr>
PR c++/82899
* g++.dg/pr82899.C: New testcase.
2018-05-18 Martin Liska <mliska@suse.cz>
* gcc.dg/pr68766.c: Change pruned output.

View File

@ -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" } } */

View File

@ -5935,11 +5935,14 @@ check_for_overlaps (vec<fieldoff_s> 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)