diff options
Diffstat (limited to 'test/Lexer')
-rw-r--r-- | test/Lexer/badstring_in_if0.c | 3 | ||||
-rw-r--r-- | test/Lexer/builtin_redef.c | 19 | ||||
-rw-r--r-- | test/Lexer/c90.c | 9 | ||||
-rw-r--r-- | test/Lexer/char-literal.cpp | 18 | ||||
-rw-r--r-- | test/Lexer/counter.c | 13 | ||||
-rw-r--r-- | test/Lexer/cxx0x_raw_string_directives.cpp | 9 | ||||
-rw-r--r-- | test/Lexer/has_feature_memory_sanitizer.cpp | 11 | ||||
-rw-r--r-- | test/Lexer/has_feature_thread_sanitizer.cpp | 11 | ||||
-rw-r--r-- | test/Lexer/pragma-message.c | 2 | ||||
-rw-r--r-- | test/Lexer/pragma-operators.cpp | 20 | ||||
-rw-r--r-- | test/Lexer/pragma-region.c | 33 | ||||
-rw-r--r-- | test/Lexer/string_concat.cpp | 15 | ||||
-rw-r--r-- | test/Lexer/token-concat-2.c | 4 | ||||
-rw-r--r-- | test/Lexer/token-concat.c | 11 | ||||
-rw-r--r-- | test/Lexer/unicode-strings.c | 21 | ||||
-rw-r--r-- | test/Lexer/unicode.c | 26 | ||||
-rw-r--r-- | test/Lexer/unknown-char.c | 4 | ||||
-rw-r--r-- | test/Lexer/utf8-char-literal.cpp | 1 | ||||
-rw-r--r-- | test/Lexer/utf8-invalid.c | 15 |
19 files changed, 227 insertions, 18 deletions
diff --git a/test/Lexer/badstring_in_if0.c b/test/Lexer/badstring_in_if0.c index 486dcf2..f7cd9d7 100644 --- a/test/Lexer/badstring_in_if0.c +++ b/test/Lexer/badstring_in_if0.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -E %s 2>&1 | not grep error +// RUN: %clang_cc1 -E -verify %s +// expected-no-diagnostics #if 0 " diff --git a/test/Lexer/builtin_redef.c b/test/Lexer/builtin_redef.c new file mode 100644 index 0000000..c9351dc --- /dev/null +++ b/test/Lexer/builtin_redef.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-OUT +// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 | FileCheck %s --check-prefix=CHECK-WARN +// RUN: %clang_cc1 %s -D__TIME__=1234 -U__DATE__ -E 2>&1 -pedantic-errors | FileCheck %s --check-prefix=CHECK-ERR + +// CHECK-WARN: <command line>:{{.*}} warning: redefining builtin macro +// CHECK-WARN: <command line>:{{.*}} warning: undefining builtin macro + +// CHECK-ERR: <command line>:{{.*}} error: redefining builtin macro +// CHECK-ERR: <command line>:{{.*}} error: undefining builtin macro + +int n = __TIME__; +__DATE__ + +#define __FILE__ "my file" +// CHECK-WARN: :[[@LINE-1]]:9: warning: redefining builtin macro +// CHECK-ERR: :[[@LINE-2]]:9: error: redefining builtin macro + +// CHECK-OUT: int n = 1234; +// CHECK-OUT: __DATE__ diff --git a/test/Lexer/c90.c b/test/Lexer/c90.c index 7142c09..649173d 100644 --- a/test/Lexer/c90.c +++ b/test/Lexer/c90.c @@ -29,8 +29,8 @@ void test2() { } void test3() { - (void)L"\u1234"; // expected-error {{unicode escape sequences are only valid in C99 or C++}} - (void)L'\u1234'; // expected-error {{unicode escape sequences are only valid in C99 or C++}} + (void)L"\u1234"; // expected-error {{universal character names are only valid in C99 or C++}} + (void)L'\u1234'; // expected-error {{universal character names are only valid in C99 or C++}} } #define PREFIX(x) foo ## x @@ -39,3 +39,8 @@ int test4() { int *p = &PREFIX(0p+1); return p[-1]; } + +#define MY_UCN \u00FC // expected-warning {{universal character names are only valid in C99 or C++; treating as '\' followed by identifier}} +#define NOT_A_UCN \h // no-warning + +extern int idWithUCN\u00FC; // expected-warning {{universal character names are only valid in C99 or C++; treating as '\' followed by identifier}} expected-error {{expected ';'}} diff --git a/test/Lexer/char-literal.cpp b/test/Lexer/char-literal.cpp index 8556d46..b2fab34 100644 --- a/test/Lexer/char-literal.cpp +++ b/test/Lexer/char-literal.cpp @@ -1,4 +1,11 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -Wfour-char-constants -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -Wfour-char-constants -fsyntax-only -verify %s + +#ifndef __cplusplus +typedef __WCHAR_TYPE__ wchar_t; +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; +#endif int a = 'ab'; // expected-warning {{multi-character character constant}} int b = '\xFF\xFF'; // expected-warning {{multi-character character constant}} @@ -7,7 +14,9 @@ int c = 'APPS'; // expected-warning {{multi-character character constant}} char d = '⌘'; // expected-error {{character too large for enclosing character literal type}} char e = '\u2318'; // expected-error {{character too large for enclosing character literal type}} +#ifdef __cplusplus auto f = '\xE2\x8C\x98'; // expected-warning {{multi-character character constant}} +#endif char16_t g = u'ab'; // expected-error {{Unicode character literals may not contain multiple characters}} char16_t h = u'\U0010FFFD'; // expected-error {{character too large for enclosing character literal type}} @@ -24,4 +33,11 @@ char32_t n = U'ab'; // expected-error {{Unicode character literals may not conta char16_t o = '👽'; // expected-error {{character too large for enclosing character literal type}} char16_t p[2] = u"\U0000FFFF"; -char16_t q[2] = u"\U00010000"; // expected-error {{too long}} +char16_t q[2] = u"\U00010000"; +#ifdef __cplusplus +// expected-error@-2 {{too long}} +#else +// FIXME: The above should be accepted in C11 mode. +// expected-error@-6 {{must be an initializer list}} +// expected-error@-6 {{must be an initializer list}} +#endif diff --git a/test/Lexer/counter.c b/test/Lexer/counter.c index 2173730..70ac98e 100644 --- a/test/Lexer/counter.c +++ b/test/Lexer/counter.c @@ -1,16 +1,17 @@ // __COUNTER__ support: rdar://4329310 -// RUN: %clang -E %s > %t +// RUN: %clang -E %s | FileCheck %s #define PASTE2(x,y) x##y #define PASTE1(x,y) PASTE2(x,y) #define UNIQUE(x) PASTE1(x,__COUNTER__) -// RUN: grep "A: 0" %t A: __COUNTER__ - -// RUN: grep "B: foo1" %t B: UNIQUE(foo); -// RUN: grep "C: foo2" %t C: UNIQUE(foo); -// RUN: grep "D: 3" %t D: __COUNTER__ + +// CHECK: A: 0 +// CHECK: B: foo1; +// CHECK: C: foo2; +// CHECK: D: 3 + diff --git a/test/Lexer/cxx0x_raw_string_directives.cpp b/test/Lexer/cxx0x_raw_string_directives.cpp new file mode 100644 index 0000000..a01fba0 --- /dev/null +++ b/test/Lexer/cxx0x_raw_string_directives.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s +// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s + +// expected-error@8 {{in c++98 only}} +#if 0 +R"( +#else +#error in c++98 only)" +#endif diff --git a/test/Lexer/has_feature_memory_sanitizer.cpp b/test/Lexer/has_feature_memory_sanitizer.cpp new file mode 100644 index 0000000..3ebb9e1 --- /dev/null +++ b/test/Lexer/has_feature_memory_sanitizer.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -E -fsanitize=memory %s -o - | FileCheck --check-prefix=CHECK-MSAN %s +// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-MSAN %s + +#if __has_feature(memory_sanitizer) +int MemorySanitizerEnabled(); +#else +int MemorySanitizerDisabled(); +#endif + +// CHECK-MSAN: MemorySanitizerEnabled +// CHECK-NO-MSAN: MemorySanitizerDisabled diff --git a/test/Lexer/has_feature_thread_sanitizer.cpp b/test/Lexer/has_feature_thread_sanitizer.cpp new file mode 100644 index 0000000..0a24810 --- /dev/null +++ b/test/Lexer/has_feature_thread_sanitizer.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -E -fsanitize=thread %s -o - | FileCheck --check-prefix=CHECK-TSAN %s +// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-TSAN %s + +#if __has_feature(thread_sanitizer) +int ThreadSanitizerEnabled(); +#else +int ThreadSanitizerDisabled(); +#endif + +// CHECK-TSAN: ThreadSanitizerEnabled +// CHECK-NO-TSAN: ThreadSanitizerDisabled diff --git a/test/Lexer/pragma-message.c b/test/Lexer/pragma-message.c index 807edda..b67886f 100644 --- a/test/Lexer/pragma-message.c +++ b/test/Lexer/pragma-message.c @@ -12,3 +12,5 @@ #define STRING(x) STRING2(x) #pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}} #pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 14}} + +#pragma message(invalid) // expected-error {{expected string literal in pragma message}} diff --git a/test/Lexer/pragma-operators.cpp b/test/Lexer/pragma-operators.cpp index a76e0b2..6a5a498 100644 --- a/test/Lexer/pragma-operators.cpp +++ b/test/Lexer/pragma-operators.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fms-extensions -E %s | FileCheck %s +// RUN: %clang_cc1 -fms-extensions -std=c++11 -E %s | FileCheck %s // Test that we properly expand the C99 _Pragma and Microsoft __pragma // into #pragma directives, with newlines where needed. <rdar://problem/8412013> @@ -17,3 +17,21 @@ #pragma warning(push) B(foo) #pragma warning(pop) + +#define pragma_L _Pragma(L"GCC diagnostic push") +#define pragma_u8 _Pragma(u8"system_header") +#define pragma_u _Pragma(u"GCC diagnostic pop") +#define pragma_U _Pragma(U"comment(lib, \"libfoo\")") +#define pragma_R _Pragma(R"(clang diagnostic ignored "-Wunused")") +#define pragma_UR _Pragma(UR"(clang diagnostic error "-Wunused")") +#define pragma_hello _Pragma(u8R"x(message R"y("Hello", world!)y")x") +// CHECK: int n = +// CHECK: #pragma GCC diagnostic push +// CHECK: #pragma system_header +// CHECK: #pragma GCC diagnostic pop +// CHECK: #pragma comment(lib, "libfoo") +// CHECK: #pragma clang diagnostic ignored "-Wunused" +// CHECK: #pragma clang diagnostic error "-Wunused" +// CHECK: #pragma message("\042Hello\042, world!") +// CHECK: 0; +int n = pragma_L pragma_u8 pragma_u pragma_U pragma_R pragma_UR pragma_hello 0; diff --git a/test/Lexer/pragma-region.c b/test/Lexer/pragma-region.c new file mode 100644 index 0000000..502db22 --- /dev/null +++ b/test/Lexer/pragma-region.c @@ -0,0 +1,33 @@ +/* Test pragma region directive from + http://msdn.microsoft.com/en-us/library/b6xkz944(v=vs.80).aspx */ + +// Editor-only pragma, just skipped by compiler. +// Syntax: +// #pragma region optional name +// #pragma endregion optional comment +// +// RUN: %clang_cc1 -fsyntax-only -verify -Wall -fms-extensions %s + +#pragma region +/* inner space */ +#pragma endregion + +#pragma region long name +/* inner space */ +void foo(void){} +#pragma endregion long comment + +void inner(); + +__pragma(region) // no sense, but ignored +_Pragma("region")// ditto + +#pragma region2 // expected-warning {{unknown pragma ignored}} + +#pragma region one +#pragma region inner +//#pragma endregion inner + +#pragma endregion end + +// {{unclosed pragma region}} - region mismatches is not detected yet diff --git a/test/Lexer/string_concat.cpp b/test/Lexer/string_concat.cpp index 7e78a63..a7eb396f 100644 --- a/test/Lexer/string_concat.cpp +++ b/test/Lexer/string_concat.cpp @@ -1,33 +1,48 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c11 -x c -fsyntax-only -verify %s + +#ifndef __cplusplus +typedef __WCHAR_TYPE__ wchar_t; +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; +#endif void f() { const char* a = u8"abc" u"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const char* b = u8"abc" U"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const char* c = u8"abc" L"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} +#ifdef __cplusplus const char* d = u8"abc" uR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const char* e = u8"abc" UR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const char* f = u8"abc" LR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} +#endif const char16_t* g = u"abc" u8"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const char16_t* h = u"abc" U"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const char16_t* i = u"abc" L"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} +#ifdef __cplusplus const char16_t* j = u"abc" u8R"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const char16_t* k = u"abc" UR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const char16_t* l = u"abc" LR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} +#endif const char32_t* m = U"abc" u8"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const char32_t* n = U"abc" u"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const char32_t* o = U"abc" L"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} +#ifdef __cplusplus const char32_t* p = U"abc" u8R"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const char32_t* q = U"abc" uR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const char32_t* r = U"abc" LR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} +#endif const wchar_t* s = L"abc" u8"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const wchar_t* t = L"abc" u"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} const wchar_t* u = L"abc" U"abc"; // expected-error {{unsupported non-standard concatenation of string literals}} +#ifdef __cplusplus const wchar_t* v = L"abc" u8R"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const wchar_t* w = L"abc" uR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} const wchar_t* x = L"abc" UR"(abc)"; // expected-error {{unsupported non-standard concatenation of string literals}} +#endif } diff --git a/test/Lexer/token-concat-2.c b/test/Lexer/token-concat-2.c deleted file mode 100644 index 7d3cd64..0000000 --- a/test/Lexer/token-concat-2.c +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -E -x c -o - %s | grep '[.][*]' -// PR4395 -#define X .* -X diff --git a/test/Lexer/token-concat.c b/test/Lexer/token-concat.c index 551af95..0a2cbee 100644 --- a/test/Lexer/token-concat.c +++ b/test/Lexer/token-concat.c @@ -1,4 +1,11 @@ -// RUN: %clang_cc1 -E -x c -o %t %s -// RUN: grep 'IDENT.2' %t +// RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s IDENT.2 +// CHECK: {{^}}IDENT.2{{$}} + + +// PR4395 +#define X .* +X +// CHECK: {{^}}.*{{$}} + diff --git a/test/Lexer/unicode-strings.c b/test/Lexer/unicode-strings.c new file mode 100644 index 0000000..3ed1f76 --- /dev/null +++ b/test/Lexer/unicode-strings.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -x c -std=c11 -Werror %s +// RUN: %clang_cc1 -x c++ -std=c++11 -Werror %s +// RUN: %clang_cc1 -x c -std=c11 -Wc99-compat -verify %s +// RUN: %clang_cc1 -x c++ -std=c++11 -Wc++98-compat -verify %s + +#ifndef __cplusplus +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; +#else +// expected-warning@17 {{'char16_t' type specifier is incompatible with C++98}} +// expected-warning@18 {{'char32_t' type specifier is incompatible with C++98}} +// expected-warning@20 {{'char16_t' type specifier is incompatible with C++98}} +// expected-warning@21 {{'char32_t' type specifier is incompatible with C++98}} +#endif + +const char *a = u8"abcd"; // expected-warning {{unicode literals are incompatible with}} +const char16_t *b = u"abcd"; // expected-warning {{unicode literals are incompatible with}} +const char32_t *c = U"abcd"; // expected-warning {{unicode literals are incompatible with}} + +char16_t d = u'a'; // expected-warning {{unicode literals are incompatible with}} +char32_t e = U'a'; // expected-warning {{unicode literals are incompatible with}} diff --git a/test/Lexer/unicode.c b/test/Lexer/unicode.c new file mode 100644 index 0000000..de758f1 --- /dev/null +++ b/test/Lexer/unicode.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -E -DPP_ONLY=1 %s -o %t +// RUN: FileCheck --strict-whitespace --input-file=%t %s + +// This file contains Unicode characters; please do not "fix" them! + +extern int x; // expected-warning {{treating Unicode character as whitespace}} +extern int x; // expected-warning {{treating Unicode character as whitespace}} + +// CHECK: extern int {{x}} +// CHECK: extern int {{x}} + +#pragma mark ¡Unicode! + +#define COPYRIGHT Copyright © 2012 +#define XSTR(X) #X +#define STR(X) XSTR(X) + +static const char *copyright = STR(COPYRIGHT); // no-warning +// CHECK: static const char *copyright = "Copyright © {{2012}}"; + +#if PP_ONLY +COPYRIGHT +// CHECK: Copyright © {{2012}} +CHECK: The preprocessor should not complain about Unicode characters like ©. +#endif diff --git a/test/Lexer/unknown-char.c b/test/Lexer/unknown-char.c index 334df37..8d316b3 100644 --- a/test/Lexer/unknown-char.c +++ b/test/Lexer/unknown-char.c @@ -1,2 +1,4 @@ -// RUN: %clang_cc1 -E %s 2>&1 | not grep error +// RUN: %clang_cc1 -E -verify %s +// expected-no-diagnostics + ` ` ` ` diff --git a/test/Lexer/utf8-char-literal.cpp b/test/Lexer/utf8-char-literal.cpp index 12b001e..7a4d126 100644 --- a/test/Lexer/utf8-char-literal.cpp +++ b/test/Lexer/utf8-char-literal.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only -verify %s int array0[u'ñ' == u'\xf1'? 1 : -1]; int array1['\xF1' != u'\xf1'? 1 : -1]; diff --git a/test/Lexer/utf8-invalid.c b/test/Lexer/utf8-invalid.c new file mode 100644 index 0000000..2657b54 --- /dev/null +++ b/test/Lexer/utf8-invalid.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -E %s -o /dev/null + +// Note: This file deliberately contains invalid UTF-8. Please do not fix! + +extern int �x; // expected-error{{source file is not valid UTF-8}} + +#if 0 +// Don't warn about bad UTF-8 in raw lexing mode. +extern int �x; +#endif + +// Don't warn about bad UTF-8 in preprocessor directives. +#define x82 � +#pragma mark � |