[cfe-dev] [PATCH] Function redeclaration and PR2360

Argiris Kirtzidis akyrtzi at gmail.com
Sun May 25 04:13:19 PDT 2008


Hi Eli,

Eli Friedman wrote:
> The issue in PR2360 (http://llvm.org/bugs/show_bug.cgi?id=2360) is
> essentially that the destruction sees the first function definition
> multiple times, so the program essentially crashes trying to free it
> twice.  The first function definition is seen multiple times because
> of the funny rearrangements that
>
> [...]
>
> I know there was an extremely long mailing list discussion related to
> this stuff, but I'm not entirely sure if any of it is relevant to this
> patch.
>   

These kind of issues with "swapping" decls triggered that discussion.

> This patch rearranges things so that each top-level declaration is
> added to the scope in the usual way, rather than messing with the old
> declaration.  This means that references to a function before a
> redeclaration refer to the old declaration, and references to a
> function after a redeclaration refer to the new declaration.  The
> original arrangement where the old declaration was rearranged to look
> like new declaration was done in r50021; however, that rearrangement
> isn't needed to fix the original bug (test/Sema/redefinition.c).
>
> A nice side effect of this patch is that it makes the representation
> of function declarations in the AST more faithful to the original
> source, which might be useful for other purposes.

The consensus was that the same declaration node should be used 
throughout the AST for the same function, regardless of the redeclarations.
The purpose of "swapping" decls were to allow only one declaration node 
to be visible in scope and also allow walking through all redeclarations 
if the client needs them.
During that discussion in mailing list, a better alternative was 
suggested to accomplish this:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-May/001644.html

IMHO, your patch should go in until someone implements that "proper" 
solution.


-Argiris



More information about the cfe-dev mailing list