This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: TRANSLATION_UNIT_DECL breaks bootstrap
- From: Geoff Keating <geoffk at geoffk dot org>
- To: mark at codesourcery dot com
- Cc: gcc at gcc dot gnu dot org, Steven Bosscher <s dot bosscher at student dot tudelft dot nl>
- Date: 11 Jul 2003 18:13:31 -0700
- Subject: Re: TRANSLATION_UNIT_DECL breaks bootstrap
- References: <200307112114.h6BLEUEe000872@minax.codesourcery.com>
Mark Mitchell <mark@codesourcery.com> writes:
> Geoff --
>
> Your patch breaks i686-pc-linux-gnu.
>
> The problem is that there is code that expects that file-scope
> variables have NULL DECL_CONTEXT, and that is no longer true.
I hope not. I thought I got all those places.
> The proximate failure is in make_decl_rtl:
>
> int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
This is intentional. Suppose you compile two files together,
==========a.c==========
static int x = 3;
int bar(void) { return x++; }
==========b.c==========
static int x = 22;
int foo(void) { return x++; }
=======================
What are you going to call 'x'? Happily, the compiler already
supports this, in the following kind of construct:
int bar(void) {
static int x = 3;
return x++;
}
int foo(void) {
static int x = 22;
return x++;
}
and I re-used that code to make this work.
In fact, this is the whole purpose of TRANSLATION_UNIT_DECL; I added
it so that this piece of code would do what it does now.
> However, it looks like there are other places where that assumption is
> being made as well:
>
> For example, integrate.c does:
>
> /* Set the context for the new declaration. */
> if (!DECL_CONTEXT (decl))
> /* Globals stay global. */
> ;
I looked at that one and believe this is also correct as-is, although
the logic is somewhat convoluted and I might be wrong.
> and dwarfout.c does:
>
> if (! DECL_CONTEXT (decl))
> {
> if (pending_types != 0)
> abort ();
> }
I missed this one. What does it do in the case of the second example
above, that is where the context of the decl is a FUNCTION_DECL or a
BLOCK?
I thought we'd stopped supporting DWARF 1.x?
> Presumably, these kinds of things all need to change.
Generally, yes, but not always.
> I will fix the make_decl_rtl problem to see if that allows me to make
> progress.
Please don't.
Steven commented:
> Maybe there should be a macro HAS_FILE_SCOPE in tree.h??
I haven't yet found a need for it. I think file scope (or,
technically, translation unit scope) is a language-specific
concept---I can certainly imagine languages where it is
meaningless---and so it probably shouldn't appear in the middle-end.
Usually, you want TREE_PUBLIC or TREE_STATIC or DECL_EXTERNAL instead.
--
- Geoffrey Keating <geoffk@geoffk.org>