[cfe-commits] r155490 - in /cfe/trunk: lib/Headers/stddef.h test/Headers/ms-null-ms-header-vs-stddef.cpp

Nico Weber nicolasweber at gmx.de
Tue Apr 24 14:27:02 PDT 2012


Author: nico
Date: Tue Apr 24 16:27:01 2012
New Revision: 155490

URL: http://llvm.org/viewvc/llvm-project?rev=155490&view=rev
Log:
Let NULL and MSVC headers coexist better.

Fixes the two issues mentioned in PR12146.


Added:
    cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
Modified:
    cfe/trunk/lib/Headers/stddef.h

Modified: cfe/trunk/lib/Headers/stddef.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stddef.h?rev=155490&r1=155489&r2=155490&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/stddef.h (original)
+++ cfe/trunk/lib/Headers/stddef.h Tue Apr 24 16:27:01 2012
@@ -43,10 +43,13 @@
 
 #undef NULL
 #ifdef __cplusplus
-#undef __null  // VC++ hack.
-#define NULL __null
+#  if !defined(__MINGW32__) && !defined(_MSC_VER)
+#    define NULL __null
+#  else
+#    define NULL 0
+#  endif
 #else
-#define NULL ((void*)0)
+#  define NULL ((void*)0)
 #endif
 
 #define offsetof(t, d) __builtin_offsetof(t, d)

Added: cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp?rev=155490&view=auto
==============================================================================
--- cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp (added)
+++ cfe/trunk/test/Headers/ms-null-ms-header-vs-stddef.cpp Tue Apr 24 16:27:01 2012
@@ -0,0 +1,16 @@
+// RUN: %clang -fsyntax-only -target i686-pc-win32 %s
+// RUN: %clang -fsyntax-only -target i386-mingw32 %s
+
+// Something in MSVC's headers (pulled in e.g. by <crtdefs.h>) defines __null
+// to something, mimick that.
+#define __null
+
+#include <stddef.h>
+
+// __null is used as a type annotation in MS headers, with __null defined to
+// nothing in regular builds. This should continue to work even with stddef.h
+// included.
+void f(__null void* p) { }
+
+// NULL should work fine even with __null defined to nothing.
+void* p = NULL;





More information about the cfe-commits mailing list