This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[ipa-comdat] put symbol in new comdat group if it's referenced from multiple comdat groups


Hi,
I was trying to address first TODO from ipa-comdats.c (attached patch)
TODO: When symbol is used only by comdat symbols, but from different groups,
it would make sense to produce a new comdat group for it with anonymous name.

The patch introduces new lattice value ANON "between" COMDAT and BOTTOM values.
The meet operation is rewritten in merge_comdat_group().
Does the approach look reasonable ?

For comdat-1.C (attached) q is referenced from both i1 and i2
and hence is put in it's own comdat-section.
I suppose that's the expected result ?

However it fails for comdat-2.C with the error below.
error: comdat-local function called by int i1() outside its comdat

However in case of comdat-1.C, i1() calls q() which is also placed
in another comdat group but doesn't give error for that case.
It also works if r() is referenced from another comdat group
and not just from q (comdat-3.C).
I am not able to understand why the error occurs for comdat-2.C.

Could someone please have a look at it ?
Thanks!

Assembling functions:

comdat-2.C: At global scope:
comdat-2.C:33:15: error: comdat-local function called by int i2()
outside its comdat
 int (*f2)()=i2;
               ^
comdat-2.C:33:15: error: comdat-local function called by int i1()
outside its comdat
_ZL1qv/1 (int q()) @0x7fe19ccde170
  Type: function definition analyzed
  Visibility: prevailing_def_ironly comdat_group:q
  Same comdat group as: _ZL1rv/0
  References:
  Referring:
  Availability: local
  First run: 0
  Function flags: body local
  Called by: _Z2i2v/3 (1.00 per call) (can throw external) _Z2i1v/2
(1.00 per call) (can throw external)
  Calls: _ZL1rv/0 (1.00 per call) (can throw external) _Z6printfPKcz/6
(1.00 per call) (can throw external)

comdat-2.C:33:15: internal compiler error: verify_cgraph_node failed
0x936083 cgraph_node::verify_node()
../../gcc/gcc/cgraph.c:3233
0x92b6df symtab_node::verify()
../../gcc/gcc/symtab.c:1177
0x92b7cf symtab_node::verify_symtab_nodes()
../../gcc/gcc/symtab.c:1197
0x93e736 symtab_node::checking_verify_symtab_nodes()
../../gcc/gcc/cgraph.h:602
0x93e736 symbol_table::compile()
../../gcc/gcc/cgraphunit.c:2431
0x940a57 symbol_table::compile()
../../gcc/gcc/cgraphunit.c:2538
0x940a57 symbol_table::finalize_compilation_unit()
../../gcc/gcc/cgraphunit.c:2564

Thanks,
Prathamesh

Attachment: patch-1.diff
Description: Text document

/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
/* { dg-options "-O2 -fdump-ipa-comdats"  } */

int printf (const char *, ...);

/* q should be placed in anon comdat group.  */

__attribute__ ((noinline))
static int q(void)
{
  printf ("test");
}

inline int i1(void)
{
  return q();
}

inline int i2(void)
{
  return q();
}

int (*f)()=i1;
int (*f2)()=i2;
/* { dg-final { scan-ipa-dump-times "Localizing symbol" 1 "comdats"  } } */
/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
/* { dg-options "-O2 -fdump-ipa-comdats"  } */

/* q should be put in anonymous comdat group since it's referenced from i1 and i2.
   r should be put in same comdat group as q.  */

int printf (const char *, ...);

__attribute__ ((noinline))
static int r(void)
{
  return printf ("world");
}

__attribute__ ((noinline))
static int q(void)
{
  printf ("test");
  return r();
}

inline int i1(void)
{
  return q();
}

inline int i2(void)
{
  return q();
}

int (*f)()=i1;
int (*f2)()=i2;
/* { dg-final { scan-ipa-dump-times "Localizing symbol" 1 "comdats"  } } */
/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
/* { dg-options "-O2 -fdump-ipa-comdats"  } */

int printf (const char *, ...);

/* q and r should be placed in anonymous groups.  */

__attribute__ ((noinline))
static int r(void)
{
  return printf ("world");
}

__attribute__ ((noinline))
static int q(void)
{
  printf ("test");
  return r();
}

inline int i1(void)
{
  return q();
}

inline int i2(void)
{
  return q();
}

inline int i3(void)
{
  return r();
}

int (*f)()=i1;
int (*f2)()=i2;
int (*f3)()=i3;
/* { dg-final { scan-ipa-dump-times "Localizing symbol" 1 "comdats"  } } */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]