Skip to content

Commit dc2ebc9

Browse files
mglisseMarc Glisse
authored andcommitted
Aliasing 'this' in a C++ constructor
2018-05-18 Marc Glisse <[email protected]> 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
1 parent 8b0cd47 commit dc2ebc9

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

gcc/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-05-18 Marc Glisse <[email protected]>
2+
3+
PR c++/82899
4+
* tree-ssa-structalias.c (create_variable_info_for_1): Extra argument.
5+
(intra_create_variable_infos): Handle C++ constructors.
6+
17
2018-05-18 Martin Liska <[email protected]>
28

39
* passes.def: Remove a redundant pass.

gcc/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-05-18 Marc Glisse <[email protected]>
2+
3+
PR c++/82899
4+
* g++.dg/pr82899.C: New testcase.
5+
16
2018-05-18 Martin Liska <[email protected]>
27

38
* gcc.dg/pr68766.c: Change pruned output.

gcc/testsuite/g++.dg/pr82899.C

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O -fdump-tree-optimized" } */
3+
4+
struct A {
5+
int i;
6+
A(A&);
7+
};
8+
int X;
9+
A::A(A&a):i(42){
10+
a.i=0;
11+
X=i;
12+
}
13+
14+
/* { dg-final { scan-tree-dump "X = 42;" "optimized" } } */

gcc/tree-ssa-structalias.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5935,11 +5935,14 @@ check_for_overlaps (vec<fieldoff_s> fieldstack)
59355935
This will also create any varinfo structures necessary for fields
59365936
of DECL. DECL is a function parameter if HANDLE_PARAM is set.
59375937
HANDLED_STRUCT_TYPE is used to register struct types reached by following
5938-
restrict pointers. This is needed to prevent infinite recursion. */
5938+
restrict pointers. This is needed to prevent infinite recursion.
5939+
If ADD_RESTRICT, pretend that the pointer NAME is restrict even if DECL
5940+
does not advertise it. */
59395941

59405942
static varinfo_t
59415943
create_variable_info_for_1 (tree decl, const char *name, bool add_id,
5942-
bool handle_param, bitmap handled_struct_type)
5944+
bool handle_param, bitmap handled_struct_type,
5945+
bool add_restrict = false)
59435946
{
59445947
varinfo_t vi, newvi;
59455948
tree decl_type = TREE_TYPE (decl);
@@ -6013,7 +6016,7 @@ create_variable_info_for_1 (tree decl, const char *name, bool add_id,
60136016
vi->size = vi->fullsize;
60146017
vi->is_full_var = true;
60156018
if (POINTER_TYPE_P (decl_type)
6016-
&& TYPE_RESTRICT (decl_type))
6019+
&& (TYPE_RESTRICT (decl_type) || add_restrict))
60176020
vi->only_restrict_pointers = 1;
60186021
if (vi->only_restrict_pointers
60196022
&& !type_contains_placeholder_p (TREE_TYPE (decl_type))
@@ -6242,6 +6245,7 @@ intra_create_variable_infos (struct function *fn)
62426245
{
62436246
tree t;
62446247
bitmap handled_struct_type = NULL;
6248+
bool this_parm_in_ctor = DECL_CXX_CONSTRUCTOR_P (fn->decl);
62456249

62466250
/* For each incoming pointer argument arg, create the constraint ARG
62476251
= NONLOCAL or a dummy variable if it is a restrict qualified
@@ -6253,10 +6257,12 @@ intra_create_variable_infos (struct function *fn)
62536257

62546258
varinfo_t p
62556259
= create_variable_info_for_1 (t, alias_get_name (t), false, true,
6256-
handled_struct_type);
6260+
handled_struct_type, this_parm_in_ctor);
62576261
insert_vi_for_tree (t, p);
62586262

62596263
make_param_constraints (p);
6264+
6265+
this_parm_in_ctor = false;
62606266
}
62616267

62626268
if (handled_struct_type != NULL)

0 commit comments

Comments
 (0)