[cs] rewrite duplicate_decls to not modify olddecl
Per Bothner
per@bothner.com
Fri Nov 7 21:32:00 GMT 2003
I checked in the following patch to the compile server branch. It does
have a few places where I'm not sure what is wanted. (Look for the #if 0
sections.) However, the patch is independent of (though needed by) the
compile server, and could probably be merged into (say) the tree-ssa
branch with a little more polishing and testing.
The duplicate_decls function is typically called when we see an actual
definition after seeing a forward declaration. After some error
checking, the function tries to combine the properties of the old and
new declaration into a single declaration. The "obvious" and "clean"
solution is to add properties from the old declaration into the new
declaration, and subsequently use the new decl. However, the old code
would do the opposite: add properties from the new decl into the old
decl, and subsequently use the old decl as the combined decl. The basic
reason for that (as I understand it) is there are various places that
reference the old decl, and it would be difficult to fix them all up.
Unfortunately, the old implementation messes up the compile server.
Consider a forward declaration in a header file, followed by a
definition in a main file (or an inline in a later header file). When
we get to the next main file, and re-use the old forward declaration, it
has been "polluted" with properties from the new definition. For
example we might get a duplicate definition error if we re-parse the
definition.
These problems can be fixed in various ways. For example the compile
server could use an "undo buffer", and use that to "un-merge" the
declarations before starting on a new main file. But the clean and
"right" solution would be to not destructively modify the forward
declaration in the first place. Instead the old declaration records the
properties we saw in the original forward declaration, and the new
declaration records the combined state the compiler knows at that point.
To handle old pointers to the old decl that might for various reaons
(such as optimizatiom) want to know about the new declaration, the new
algorithm chains the new decl immediately after the old decl. I use
this in c_write_global_declarations to skip the old declaration.
The resulting algorithm seems cleaner that the old one, and works quite
well. There are a modest number of testsuite failures, but they could
be due to other bugs in the compile server branch. I don't know if
there are regressions in terms of code quality.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: c-decl.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20031107/74e55158/attachment.ksh>
More information about the Gcc-patches
mailing list