Geoff Keating <geoffk@geoffk.org> writes:
[...]
This is expected to compile and not abort(), since it is strictly
conforming C (if you fix the closing brace). According to your
description of the patch:
Declarations with internal linkage at file scope in the first input
file get DECL_ASSEMBLER_NAME set equal to DECL_NAME.
So, in a.c, 'x' will get DECL_ASSEMBLER_NAME of 'x', since a.c is the
first input file.
Now, I presume that declarations with external linkage will continue
to get their own name, too, so in b.c and c.c, 'x' will also get
DECL_ASSEMBLER_NAME of 'x'. (They'd better have the same name, since
they are the same object.)
This is a problem, since the 'x' in a.c and the one in c.c are
different objects. I expect that this code won't compile under IMA;
the assembler will choke.
Thanks for the explanation. I figured out what you meant about 15
minutes after sending the previous message, but at that point I had
already left the house and it was too late to say so. (Had to spend
all day helping friends move.)
You're right, this won't work. I've thought of three possible fixes.
All entail reverting most of the behavior change in
lhd_set_decl_assembler_name (but I'd prefer to keep the bit where we
use the DECL_UID for the disambiguating suffix.)
1) Put back c_static_assembler_name. Hope that all the places where
DECL_CONTEXT wasn't getting set right have been found.
2) Don't put back c_static_assembler_name, instead have pop_scope give
!TREE_PUBLIC file-scope decls a NULL DECL_CONTEXT when there's only
one translation unit in play, thus getting backward-compatible
behavior from the default hook. Again we have to hope that all the
places where DECL_CONTEXT wasn't getting set right have been found.
3) Again don't put back c_static_assembler_name. Have
c_write_global_declarations scan all declarations in all file
scopes and the externals scope, and clear DECL_CONTEXT for all
!TREE_PUBLIC file-scope decls except those which actually need
disambiguation (i.e. either two !TREE_PUBLIC decls with the same
name appear in different translation units, or a !TREE_PUBLIC decl
appears in one TU and a TREE_PUBLIC decl with the same name appears
in the external scope). This guarantees that DECL_CONTEXT is
correct for everything, but does involve adding a big chunk of
code, two more iterations over all file-scope declarations, and
probably using tree_common flags on IDENTIFIER_NODE, which we're
trying to get away from.
I think that all the places where DECL_CONTEXT wasn't getting set
right have in fact been found, so I currently prefer option 2. What
do you think?