Commit Graph

25 Commits

Author SHA1 Message Date
Richard Smith ef99e4d88a Fix interaction of max_align_t and modules.
When building with modules enabled, we were defining max_align_t as a typedef
for a different anonymous struct type each time it was included, resulting in
an error if <stddef.h> is not covered by a module map and is included more than
once in the same modules-enabled compilation of C11 or C++11 code.

llvm-svn: 218931
2014-10-03 00:31:35 +00:00
Nico Weber 272bcf6768 Let stddef.h respect __need_{wchar_t, size_t, NULL, ptrdiff_t, wint_t}.
glibc expects that stddef.h only defines a single thing if either of these
defines is set.  For example, before this change, a C file containing

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

would compile with gcc but not with clang. Now it compiles with clang too.

This also fixes PR12997, where older versions of the Linux headers would define
NULL incorrectly, and glibc would define __need_NULL and expect stddef.h to
redefine NULL with the correct definition.

llvm-svn: 207606
2014-04-30 04:35:09 +00:00
Nico Weber f077c51a70 Revert r207482; I fail at reading IRC.
llvm-svn: 207483
2014-04-29 01:25:49 +00:00
Nico Weber 8af28c1e61 Let stddef.h redefine NULL if __need_NULL is set, as needed by glibc, PR12997.
See the bug and the cfe-commits thread "[patch] Let stddef.h redefine NULL if
__need_NULL is set" for discussion.

Fixes PR12997 and is similar to the __need_wint_t bits already in this file.

llvm-svn: 207482
2014-04-29 01:19:21 +00:00
David Majnemer 1e57976ec0 Headers: Provide an ABI compatible max_align_t when _MSC_VER is defined
Summary:
Our usual definition of max_align_t wouldn't match up with MSVC if it
was used in a template argument.

Reviewers: chandlerc, rsmith, rnk

Reviewed By: chandlerc

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D2924

llvm-svn: 202911
2014-03-04 23:43:48 +00:00
Chandler Carruth e813984b43 Teach Clang to provide ::max_align_t in C11 and C++11 modes.
This definition is not chosen idly. There is an unfortunate reality with
max_align_t -- the specific nature of its definition leaks into the ABI
almost immediately. Because it is part of C11 and C++11 it becomes
essential for it to match with other systems on that ABI. There is an
effort to discourage any further use of this construct as a consequence
-- using max_align_t introduces an immediate ABI problem. We can never
update it to have larger alignment even as the microarchitecture changes
to necessitate higher alignment. =/

The particular definition here exactly matches the ABI of GCC's chosen
::max_align_t definition, for better or worse. This was written with the
help of Richard Smith who was decoding the exact ABI implications of the
selected definition in GCC. Notably, in-register arguments are impacted
by the particular definition chosen. =/

No one is under the illusion that this is a "good" or "useful"
definition of max_align_t, and we are working with the standards
committee to specify a more useful interface to address this need.

llvm-svn: 201729
2014-02-19 22:35:01 +00:00
Hans Wennborg 4c02be3b83 Make sure we define wchar_t related macros correctly in -fms-extensions mode.
This adds a test to make sure we define _WCHAR_T_DEFINED and
_NATIVE_WCHAR_T_DEFINED correctly in the preprocessor, and updates
stddef.h to set it when typedeffing wchar_t.

llvm-svn: 180918
2013-05-02 13:12:32 +00:00
Hans Wennborg b2175b25a7 Fix typo in a stddef.h comment: s/risze_t/rsize_t/
llvm-svn: 180916
2013-05-02 10:36:31 +00:00
Daniel Dunbar 95f1de3de5 Headers: Add support for ISO9899:2011 rsize_t.
llvm-svn: 179427
2013-04-12 23:24:56 +00:00
Argyrios Kyrtzidis 95aa0b77f2 Revert "[lib/Headers] Define NULL as __DARWIN_NULL when on __APPLE__."
Per feedback by Doug, we should avoid platform-specific implementations
in lib/Headers as much as possible.

This reverts commit r178110.

llvm-svn: 178181
2013-03-27 21:22:45 +00:00
Argyrios Kyrtzidis 0909d3c5ed [lib/Headers] Define NULL as __DARWIN_NULL when on __APPLE__.
This makes it identical with the system definition.

llvm-svn: 178110
2013-03-27 01:25:37 +00:00
Douglas Gregor 96efb4a442 <rdar://problem/13479214> Make Clang's <stddef.h> robust against system headers defining size_t/ptrdiff_t/wchar_t.
Clang's <stddef.h> provides definitions for the C standard library
types size_t, ptrdiff_t, and wchar_t. However, the system's C standard
library headers tend to provide the same typedefs, and the two
generally avoid each other using the macros
_SIZE_T/_PTRDIFF_T/_WCHAR_T. With modules, however, we need to see
*all* of the places where these types are defined, so provide the
typedefs (ignoring the macros) when modules are enabled.

llvm-svn: 177686
2013-03-22 00:10:49 +00:00
Daniel Dunbar 230cc79394 [Headers] Use standard builtin defines instead of typeof trickery.
- The trickery can confuse more basic source processors, in particular the
   Unix conformance tool that wants to scan headers.

llvm-svn: 174475
2013-02-06 00:38:13 +00:00
Douglas Gregor 158dec5d20 std::nullptr_t support in MS headers, from João Matos.
llvm-svn: 159448
2012-06-29 18:28:41 +00:00
Nico Weber 1d725ecf93 Let NULL and MSVC headers coexist better.
Fixes the two issues mentioned in PR12146.

llvm-svn: 155490
2012-04-24 21:27:01 +00:00
Chris Lattner 57540c5be0 fix a bunch of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129559
2011-04-15 05:22:18 +00:00
Ted Kremenek f49e1dd86d Add '#ifndef _PTRDIFF_T' guard around definition of ptrdiff_t. Fixes <rdar://problem/9210154>.
llvm-svn: 128578
2011-03-30 21:43:52 +00:00
NAKAMURA Takumi a8792e514a lib/Headers/stddef.h: wint_t should be defined whenever <stddef.h> is included with __need_wint_t.
llvm-svn: 116794
2010-10-19 03:42:41 +00:00
Chris Lattner ee8df8f167 fix PR7192 by defining wchar_t in a more conventional way. The
type of L"x" can change based on command line arguments.

llvm-svn: 113127
2010-09-05 23:29:49 +00:00
Chris Lattner 38321174e0 add a hack for visual studio, fixing PR7796
llvm-svn: 110161
2010-08-03 22:13:56 +00:00
Alexis Hunt 0684e33ba5 MinGW requires that wint_t be defined in stddef.h. In order to accomodate, we
won't define it unless specifically requested via the use of __need_wint_t.

llvm-svn: 105985
2010-06-15 02:36:48 +00:00
Ted Kremenek 0a4a8326c1 Add preprocessor guards to the definitions of size_t and wchar_t, and #undef NULL before defining it.
This addresses potential issues with system headers reported in <rdar://problem/7727159>.

llvm-svn: 98006
2010-03-08 23:23:45 +00:00
Douglas Gregor f7ab50df29 Define NULL to __null in C++, so that it's guaranteed to have the same size as a pointer
llvm-svn: 60355
2008-12-01 17:20:57 +00:00
Anders Carlsson 6b0dc85119 #define NULL as 0 when compiling as C++. This fixes the carbon.cpp and cocoa.mm test failures.
llvm-svn: 58685
2008-11-04 06:53:14 +00:00
Eli Friedman 9e9b046ac9 Add a couple more headers. stddef was discussed on cfe-dev, and
consensus was that it was fine; iso646 is trivial.

We actually don't need that many headers overall... on Ubuntu, at least, 
all we need are stdint.h, stdarg.h, limits.h, and float.h to stop 
depending on having gcc's headers around for normal code.

On a side note, the path searching needs some improvement; I had to 
hardcode the path to my header directory into clang.cpp to get the 
driver to use it consistently.

llvm-svn: 51317
2008-05-20 13:34:26 +00:00