[patch] Let stddef.h redefine NULL if __need_NULL is set

Richard Smith richard at metafoo.co.uk
Tue Apr 29 17:34:37 PDT 2014


On Tue, Apr 29, 2014 at 5:22 PM, Nico Weber <thakis at chromium.org> wrote:

> That's good to know!
>
> I checked that the problem reproduces on debian wheezy (debian's current
> stable, a bit less than a year old), but it is fixed on debian sid.
>
> So applications could work around this by doing "mkdir -p hack/linux;
> touch hack/linux/stddef.h" and then adding "-Ihack" to all their
> commandlines until this is fixed. Since this is only needed for a limited
> time (2 years-ish), that seems preferable to me over adding hacks to
> clang's headers. Any other opinions? If not, I'll drop this patch.
>
>
> In any case, it's probably a good idea to change stddef.h so that the
> already-present __need_wint_t behaves like in gcc's version: if that's
> defined, stddef.h only provides win_t and does nothing else. Should I send
> a patch for just that?
>

No, we still want your complete (updated) -3 patch because it fixes the
behavior of the glibc headers that export part of stddef.h's names.
Consider:

#include <stdlib.h>
int ptrdiff_t = 0;

In C, this is a valid translation unit. GCC accepts, Clang rejects, because
our builtin headers don't support the __need_FOO mechanism properly that
glibc's stdlib.h uses to import only part of stddef.h.


> On Tue, Apr 29, 2014 at 7:35 AM, Lubos Lunak <l.lunak at centrum.cz> wrote:
>
>> On Monday 28 of April 2014, Reid Kleckner wrote:
>> > Even if we commit this workaround, can we report this as a bug to
>> upstream
>> > Linux?
>>
>>  Already done (http://comments.gmane.org/gmane.linux.kernel/1281756). And
>> there's actually no public #define NULL in recent Linux headers.
>>
>> > The test case you have shows how this definition of NULL is broken
>> > on x86_64, even in C with gcc:
>> >
>> > $ cat t.c
>> > #define NULL 0
>> > int printf(const char *, ...);
>> > int main() {
>> >   printf("%d %d %d %d %d %d %p\n", 1, 2, 3, 4, 5, 6,
>> > 0xdeadbeefdeadbeefULL); printf("%d %d %d %d %d %d %p\n", 1, 2, 3, 4, 5,
>> 6,
>> > NULL);
>> > }
>> >
>> > $ gcc -w t.c -o t && ./t
>> > 1 2 3 4 5 6 0xdeadbeefdeadbeef
>> > 1 2 3 4 5 6 0xdeadbeef00000000
>>
>> --
>>  Lubos Lunak
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140429/31c10114/attachment.html>


More information about the cfe-commits mailing list