r174081 - Lexer: Don't warn about Unicode in preprocessor directives.
Jordan Rose
jordan_rose at apple.com
Thu Jan 31 11:48:48 PST 2013
Author: jrose
Date: Thu Jan 31 13:48:48 2013
New Revision: 174081
URL: http://llvm.org/viewvc/llvm-project?rev=174081&view=rev
Log:
Lexer: Don't warn about Unicode in preprocessor directives.
This allows people to use Unicode in their #pragma mark and in macros
that exist only to be string-ized.
<rdar://problem/13107323&13121362>
Modified:
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/test/Lexer/unicode.c
cfe/trunk/test/Lexer/utf8-invalid.c
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=174081&r1=174080&r2=174081&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Jan 31 13:48:48 2013
@@ -2832,7 +2832,8 @@ void Lexer::LexUnicode(Token &Result, ui
return LexIdentifier(Result, CurPtr);
}
- if (!isLexingRawMode() && !PP->isPreprocessedOutput() &&
+ if (!isLexingRawMode() && !ParsingPreprocessorDirective &&
+ !PP->isPreprocessedOutput() &&
!isASCII(*BufferPtr) && !isAllowedIDChar(C)) {
// Non-ASCII characters tend to creep into source code unintentionally.
// Instead of letting the parser complain about the unknown token,
@@ -3537,7 +3538,8 @@ LexNextToken:
if (Status == conversionOK)
return LexUnicode(Result, CodePoint, CurPtr);
- if (isLexingRawMode() || PP->isPreprocessedOutput()) {
+ if (isLexingRawMode() || ParsingPreprocessorDirective ||
+ PP->isPreprocessedOutput()) {
++CurPtr;
Kind = tok::unknown;
break;
Modified: cfe/trunk/test/Lexer/unicode.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/unicode.c?rev=174081&r1=174080&r2=174081&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/unicode.c (original)
+++ cfe/trunk/test/Lexer/unicode.c Thu Jan 31 13:48:48 2013
@@ -10,6 +10,17 @@ extern intãx; // expected-warning {
// 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
Modified: cfe/trunk/test/Lexer/utf8-invalid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/utf8-invalid.c?rev=174081&r1=174080&r2=174081&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/utf8-invalid.c (original)
+++ cfe/trunk/test/Lexer/utf8-invalid.c Thu Jan 31 13:48:48 2013
@@ -9,3 +9,7 @@ extern int x; // expected-error{{sourc
// 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
More information about the cfe-commits
mailing list