Patch for c/13801

Zack Weinberg zack@codesourcery.com
Mon Aug 2 22:32:00 GMT 2004


"Joseph S. Myers" <jsm@polyomino.org.uk> writes:

> This patch fixes bug 13801, that when entities with external or
> internal linkage are redeclared, their types in each block should only
> depend on the visible declarations.  It also fixes some related cases
> that may never have worked, and one regression from 3.3 perhaps of
> more note: a static declaration at file scope didn't get merged with
> an extern declaration at block scope.

You cannot do it this way.  At end of compilation, the decls must have
types which reflect all the details we have amassed from all
declarations seen -- possibly across multiple translation units.
Consider the case where the nested block scope declaration (or the
declaration in a different translation unit, equivalently) has an
initializer: DECL_INITIAL will be inconsistent with the type.  We'll
either ICE or fail to emit a correct initializer.

I also object to any solution to this bug which increases memory usage
for correct code.  The effect of this bug is to fail to diagnose
certain cases where a program is ill-formed; as such, correct code
never encounters the bug, so it is better to leave the bug unfixed
than to penalize compilation of correct code.  (Your 2.6% compile time
improvement is probably just noise -- unless you've been thorough
enough in your measurements that you can nail down the error bars, any
number that small should be viewed with great suspicion, never mind
the state of --enable-checking.)

A correct solution to this bug could take the form of a flag bit on
struct c_binding (there is room for two more of these without
increasing the size of the structure) which records whether or not the
declaration is incomplete in that scope.  This then has to propagate
to everywhere that issues diagnostics for inappropriate use of decls
with incomplete types.

I will approve the testsuite changes that just add explicit
declarations of built-ins where they are missing; that should cut the
size of the patch you're carrying around by a good two-thirds.  I'll
also preapprove testsuite patches which add test cases for the missing
diagnostics covered under 13801, provided that all the currently-
failing tests are XFAILed.

> There are also some extra diagnostics for incompatible implicit
> function declarations as part of making implicit function declarations
> work properly if the previous declaration is out of scope.  For
> discussion of that for incompatibly implicitly declaring a built-in
> function, see <http://gcc.gnu.org/ml/gcc/2004-08/msg00021.html>.

Submit this change separately.  With regard to the incompatible
declarations of built-ins, I agree with Geoff, and I'd add that you
should not diagnose incompatible redeclarations of built-ins that are
not covered by the currently selected standard.

zw



More information about the Gcc-patches mailing list