diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-03-22 00:10:49 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-03-22 00:10:49 +0000 |
commit | 96efb4a4425ebe24c783da1af6c6ae05d80ae887 (patch) | |
tree | 1206fa5b3720f89d7a9522360badc67d1194e6a2 | |
parent | 9e65aa35a03a94882a0f1d5dd161cb2163f4796d (diff) | |
download | bcm5719-llvm-96efb4a4425ebe24c783da1af6c6ae05d80ae887.tar.gz bcm5719-llvm-96efb4a4425ebe24c783da1af6c6ae05d80ae887.zip |
<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
-rw-r--r-- | clang/lib/Headers/stddef.h | 24 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/StdDef/module.map | 11 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/StdDef/other.h | 2 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/StdDef/size_t.h | 4 | ||||
-rw-r--r-- | clang/test/Modules/stddef.m | 7 |
5 files changed, 43 insertions, 5 deletions
diff --git a/clang/lib/Headers/stddef.h b/clang/lib/Headers/stddef.h index ad5dc21fb04..52962248f67 100644 --- a/clang/lib/Headers/stddef.h +++ b/clang/lib/Headers/stddef.h @@ -26,17 +26,28 @@ #ifndef __STDDEF_H #define __STDDEF_H -#ifndef _PTRDIFF_T +#if !defined(_PTRDIFF_T) || __has_feature(modules) +/* Always define ptrdiff_t when modules are available. */ +#if !__has_feature(modules) #define _PTRDIFF_T +#endif typedef __PTRDIFF_TYPE__ ptrdiff_t; #endif -#ifndef _SIZE_T + +#if !defined(_SIZE_T) || __has_feature(modules) +/* Always define size_t when modules are available. */ +#if !__has_feature(modules) #define _SIZE_T +#endif typedef __SIZE_TYPE__ size_t; #endif + #ifndef __cplusplus -#ifndef _WCHAR_T +/* Always define wchar_t when modules are available. */ +#if !defined(_WCHAR_T) || __has_feature(modules) +#if !__has_feature(modules) #define _WCHAR_T +#endif typedef __WCHAR_TYPE__ wchar_t; #endif #endif @@ -66,9 +77,12 @@ using ::std::nullptr_t; /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */ #if defined(__need_wint_t) -#if !defined(_WINT_T) +/* Always define wint_t when modules are available. */ +#if !defined(_WINT_T) || __has_feature(modules) +#if !__has_feature(modules) #define _WINT_T +#endif typedef __WINT_TYPE__ wint_t; -#endif /* _WINT_T */ +#endif #undef __need_wint_t #endif /* __need_wint_t */ diff --git a/clang/test/Modules/Inputs/StdDef/module.map b/clang/test/Modules/Inputs/StdDef/module.map new file mode 100644 index 00000000000..69c69eac35b --- /dev/null +++ b/clang/test/Modules/Inputs/StdDef/module.map @@ -0,0 +1,11 @@ +module StdDef { + module SizeT { + header "size_t.h" + export * + } + + module Other { + header "other.h" + export * + } +} diff --git a/clang/test/Modules/Inputs/StdDef/other.h b/clang/test/Modules/Inputs/StdDef/other.h new file mode 100644 index 00000000000..f29f6366cc6 --- /dev/null +++ b/clang/test/Modules/Inputs/StdDef/other.h @@ -0,0 +1,2 @@ +#include <stddef.h> + diff --git a/clang/test/Modules/Inputs/StdDef/size_t.h b/clang/test/Modules/Inputs/StdDef/size_t.h new file mode 100644 index 00000000000..9ac61c5e0d7 --- /dev/null +++ b/clang/test/Modules/Inputs/StdDef/size_t.h @@ -0,0 +1,4 @@ +#ifndef _SIZE_T +#define _SIZE_T +typedef __SIZE_TYPE__ size_t; +#endif diff --git a/clang/test/Modules/stddef.m b/clang/test/Modules/stddef.m new file mode 100644 index 00000000000..83f73f9d33a --- /dev/null +++ b/clang/test/Modules/stddef.m @@ -0,0 +1,7 @@ +@import StdDef.Other; + +size_t getSize(); + +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I %S/Inputs/StdDef %s -verify +// expected-no-diagnostics |