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]

Re: intermodule and comptypes - need some help


"Zack Weinberg" <zack@codesourcery.com> writes:

> A patch I'm working on has, as a side effect, that (in intermodule
> mode) duplicate_decls may encounter two declarations from different
> translation units at any time, not just during
> merge_translation_unit_decls.

I'd be interested to hear more details about how this happens.

>  It therefore cannot simply be told when
> to invoke comptypes with the special COMPARE_DIFFERENT_TU flag.  I
> tried to write a function which would detect when two types came from
> different translation units, but it doesn't work: --enable-intermodule
> bootstrap blows up with tons of spurious duplicate declarations.
> 
> This is the code I wrote:-
> 
> /* Determine whether two types derive from the same translation unit.
>    If the CONTEXT chain ends in a null, that type's context is still
>    being parsed, so if two types have context chains ending in null,
>    they're in the same translation unit.  */
> static int
> same_translation_unit_p (tree t1, tree t2)
> {
>   while (t1 && TREE_CODE (t1) != TRANSLATION_UNIT_DECL)
>     switch (TREE_CODE_CLASS (TREE_CODE (t1)))
>       {
>       case 'd': t1 = DECL_CONTEXT (t1); break;
>       case 't': t1 = TYPE_CONTEXT (t1); break;
>       case 'b': t1 = BLOCK_SUPERCONTEXT (t1); break;
>       default: abort ();
>       }
> 
>   while (t2 && TREE_CODE (t2) != TRANSLATION_UNIT_DECL)
>     switch (TREE_CODE_CLASS (TREE_CODE (t2)))
>       {
>       case 'd': t2 = DECL_CONTEXT (t1); break;
>       case 't': t2 = TYPE_CONTEXT (t2); break;
>       case 'b': t2 = BLOCK_SUPERCONTEXT (t2); break;
>       default: abort ();
>       }
> 
> 
>   return t1 == t2;
> }
> 
> This replaces the flags check guarding the call to
> tagged_types_tu_compatible_p.  What am I doing wrong?

I expect that at some point, some type gets created without the right
context.  This would never have mattered before because nothing ever
looked at the context of types (except in the objc compiler and then
only in pretty special circumstances).

If bootstrapping GCC is getting to be a pain, you might find the
attached testcase helpful; you can modify it by assigning between x_1
and x_2 in the different translation units, the assignment is valid in
-6b but invalid (and requires a diagnostic) in -6a, and yet as written
the two files are valid ISO C.  Build it with

gcc -O3 imi-6a.c imi-6b.c -c -o imi-6.o
gcc imi-6.o -o imi-6
./imi-6

-- 
- Geoffrey Keating <geoffk@geoffk.org>

====================imi-6a.c
/* { dg-do run } */
/* { dg-options "-O3" } */

/* An obscure aliasing testcase: In this file, the types of 'x_1' and
   'x_2' and 'x' are not compatible.  But in the other file, they are
   all compatible.  */

extern struct 
{
  int x;
} *x_1;

extern struct 
{
  int x;
} *x_2;

extern struct 
{
  int x;
} x;

void foo(void)
{
  x.x = 4;
  x_2->x = 3;
  if (x.x != 3)
    abort ();
  x_1->x = 1;
  if (x_2->x != 1)
    abort ();
  if ((void *)x_1 != (void *)x_2)
    abort ();
  if ((void *)x_1 != &x)
    abort ();
}
====================
====================imi-6b.c
struct 
{
  int x;
} x, *x_1 = &x, *x_2 = &x;

extern void foo(void);

int main(void)
{
  foo();
}
====================


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