From c814c64c6f7e7a26f4af0d040ad04b69917a36c8 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 2 May 2013 13:12:32 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180918 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Headers/stddef.h | 3 +++ test/Headers/ms-wchar.c | 15 +++++++++++++++ test/Preprocessor/init.c | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/Headers/ms-wchar.c diff --git a/lib/Headers/stddef.h b/lib/Headers/stddef.h index 0c5c961d5e..6a64d6d32a 100644 --- a/lib/Headers/stddef.h +++ b/lib/Headers/stddef.h @@ -58,6 +58,9 @@ typedef __SIZE_TYPE__ rsize_t; #if !defined(_WCHAR_T) || __has_feature(modules) #if !__has_feature(modules) #define _WCHAR_T +#if defined(_MSC_EXTENSIONS) +#define _WCHAR_T_DEFINED +#endif #endif typedef __WCHAR_TYPE__ wchar_t; #endif diff --git a/test/Headers/ms-wchar.c b/test/Headers/ms-wchar.c new file mode 100644 index 0000000000..f015fc77ee --- /dev/null +++ b/test/Headers/ms-wchar.c @@ -0,0 +1,15 @@ +// RUN: %clang -fsyntax-only -target i386-pc-win32 %s + +#if defined(_WCHAR_T_DEFINED) +#error "_WCHAR_T_DEFINED should not be defined in C99" +#endif + +#include + +#if !defined(_WCHAR_T_DEFINED) +#error "_WCHAR_T_DEFINED should have been set by stddef.h" +#endif + +#if defined(_NATIVE_WCHAR_T_DEFINED) +#error "_NATIVE_WCHAR_T_DEFINED should not be defined" +#endif diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index c1519a8a7f..b69c76ce1b 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -88,10 +88,24 @@ // C94:#define __STDC_VERSION__ 199409L // // -// RUN: %clang_cc1 -fms-extensions -triple i686-pc-win32 -fobjc-runtime=gcc -E -dM < /dev/null | FileCheck -check-prefix MSEXT %s +// RUN: %clang_cc1 -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -check-prefix MSEXT %s // // MSEXT-NOT:#define __STDC__ // MSEXT:#define _INTEGRAL_MAX_BITS 64 +// MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1 +// MSEXT-NOT:#define _WCHAR_T_DEFINED 1 +// +// +// RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -check-prefix MSEXT-CXX %s +// +// MSEXT-CXX:#define _NATIVE_WCHAR_T_DEFINED 1 +// MSEXT-CXX:#define _WCHAR_T_DEFINED 1 +// +// +// RUN: %clang_cc1 -x c++ -fno-wchar -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -check-prefix MSEXT-CXX-NOWCHAR %s +// +// MSEXT-CXX-NOWCHAR-NOT:#define _NATIVE_WCHAR_T_DEFINED 1 +// MSEXT-CXX-NOWCHAR-NOT:#define _WCHAR_T_DEFINED 1 // // // RUN: %clang_cc1 -x objective-c -E -dM < /dev/null | FileCheck -check-prefix OBJC %s -- 2.40.0