[cfe-dev] Weak pointer support on 32-bit platforms
Aaron Ballman
aaron at aaronballman.com
Mon May 12 17:18:48 PDT 2014
On Mon, May 12, 2014 at 6:29 PM, Reid Kleckner <rnk at google.com> wrote:
> On Mon, May 12, 2014 at 12:18 PM, Hovik Melikyan <hovik.melikyan at gmail.com>
> wrote:
>>
>> On Mon, May 12, 2014 at 7:20 PM, Reid Kleckner <rnk at google.com> wrote:
>> >
>> > You can probably work around this with -D__GNUC__=4.
>> >
>> > However, why do you need -fms-compatibility if you are using MinGW?
>> >
>>
>> Clang puts itself into MS compatibility mode when the target is e.g.
>> i686-pc-win32. A better workaround for me was to use
>> -fno-ms-compatibility.
>
>
> So, you're using MinGW headers with i686-pc-win32 instead of
> i686-pc-mingw32. The former target aims for MSVC compatibility and the
> latter MinGW/GCC compatibility.
>
> Using MinGW headers with -win32 is crossing the streams, and I don't
> recommend doing it, unless you have a really good reason. You are probably
> going to have problems linking C++ binaries or passing structs across ABI
> boundaries.
>
>>
>> In any case, I don't think this
>>
>> Builder.defineMacro("__weak",
>> "__attribute__((objc_ownership(weak)))");
>>
>> was a good idea, as it makes some of the most critical attributes in
>> Objective C dependent on a compiler extension (__attribute__) which is
>> not always available at compile time!
>
>
> Well, Clang always provides __attribute__, so it's perfectly reasonable to
> implement __weak this way. MinGW shouldn't be messing with the implementors
> namespace this way.
>
> That said, I'm in favor of making these contextual keywords. We have the
> infrastructure to do it, so let's avoid the pre-processor cruftiness.
Certainly plausible -- the fun part is in figuring out what attribute
to create when. __weak is defined as:
* __attribute__((objc_gc(weak))) when the frontend is rewriting ObjC
* __attribute__((objc_ownership(weak))) when ObjCAutoRefCount is true
* __attribute__((objc_gc(weak))) when ObjCAutoRefCount is false and
building for Darwin
* not defined otherwise
Similar shenanigans for __strong, et al. So it's not that this isn't
possible to do, but it may have some surprises too.
~Aaron
More information about the cfe-dev
mailing list