[cfe-commits] [patch] Add support for weakref

Eli Friedman eli.friedman at gmail.com
Mon Feb 22 12:40:47 PST 2010


On Sat, Feb 20, 2010 at 9:01 PM, Rafael Espindola <espindola at google.com> wrote:
>> I don't understand enough about weakref to evaluate the semantics of
>> this, but from the docs it seems to not be just equivalent to weak +
>> alias?
>
> At the C/C++ level? It is not, they have different warnings and are
> supported in different cases. I update the patch with comments and
> tests to try to show where exactly it is supported.
>
> At the llvm level it gets represented as "alias weak", that is why I
> implemented it with WeakAttr + AliasAttr. I can add a WeakRefAttr and
> codegen it as "weak" if you want.

That's a bug in llvm-gcc; there's a PR in Bugzilla on it, although
it's down at the moment.  The correct semantics for weakref if we
implement it purely in clang are as follows:

1. Emit weakref variables as external declarations, and put them on a
list to go through after everything is emitted.
2. For each weakref variable, see if there is an existing declaration
of the target: if there isn't, build a weak declaration of the target.
3. Replace all uses of the weakref with the target.

The only issue with this is that it doesn't interact with inline asm correctly.

-Eli



More information about the cfe-commits mailing list