https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67666
Bug ID: 67666 Summary: single restrict pointer in struct looses restrict Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- Consider testcase test.c: ... struct ps { int *__restrict__ p; }; void f (struct ps &__restrict__ ps1) { *(ps1.p) = 1; } ... Compile the test-case with g++ -O2, and we get one clique/base annotation at ealias (the one for ps1, not the one for p): ... void f(ps&) (struct psD.2252 & restrict ps1D.2255) { intD.9 * _3; # VUSE <.MEM_1(D)> # PT = nonlocal escaped _3 = MEM[(struct psD.2252 &)ps1_2(D) clique 1 base 1].pD.2254; # .MEM_4 = VDEF <.MEM_1(D)> *_3 = 1; ... After applying the patch: ... --- test7.c.orig 2015-09-21 11:38:30.607225802 +0200 +++ test7.c 2015-09-21 11:29:40.891234983 +0200 @@ -1,6 +1,7 @@ struct ps { int *__restrict__ p; + int a; }; void ... we get both clique/base annotations at ealias: ... void f(ps&) (struct psD.2252 & restrict ps1D.2256) { intD.9 * _3; # VUSE <.MEM_1(D)> # PT = { D.2263 } (nonlocal) _3 = MEM[(struct psD.2252 &)ps1_2(D) clique 1 base 1].pD.2254; # .MEM_4 = VDEF <.MEM_1(D)> MEM[(intD.9 *)_3 clique 1 base 2] = 1; # VUSE <.MEM_4> ... Using this demonstrator patch, I manage to get both clique/base annotations at ealias, without adding an 'int a' field to the struct: ... diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index b5b9d0a..e99feeb 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -5675,8 +5675,7 @@ create_variable_info_for_1 (tree decl, const char *name) /* If we didn't end up collecting sub-variables create a full variable for the decl. */ - if (fieldstack.length () <= 1 - || fieldstack.length () > MAX_FIELDS_FOR_FIELD_SENSITIVE) + if (fieldstack.length () > MAX_FIELDS_FOR_FIELD_SENSITIVE) { vi = new_var_info (decl, name); vi->offset = 0; ...