summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-01-27 20:12:04 +0000
committerJordan Rose <jordan_rose@apple.com>2013-01-27 20:12:04 +0000
commitc0cba2723060bec878b34e6521f03cf3cc16ade1 (patch)
tree448a8ec1fd776fcb5d94c852cecac8f5453433a3
parent293a41d14faf65528f3073e538b6795542e97a09 (diff)
downloadbcm5719-llvm-c0cba2723060bec878b34e6521f03cf3cc16ade1.tar.gz
bcm5719-llvm-c0cba2723060bec878b34e6521f03cf3cc16ade1.zip
PR15067: Don't assert when a UCN appears in a C90 file.
Unfortunately, we can't accept the UCN as an extension because we're required to treat it as two tokens for preprocessing purposes. llvm-svn: 173622
-rw-r--r--clang/include/clang/Basic/DiagnosticLexKinds.td7
-rw-r--r--clang/lib/Lex/Lexer.cpp9
-rw-r--r--clang/lib/Lex/LiteralSupport.cpp2
-rw-r--r--clang/test/Lexer/c90.c6
4 files changed, 16 insertions, 8 deletions
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td
index e3bff51b8e1..81e8e9cf848 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -127,6 +127,11 @@ def warn_cxx98_compat_literal_ucn_escape_basic_scs : Warning<
def warn_cxx98_compat_literal_ucn_control_character : Warning<
"universal character name referring to a control character "
"is incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
+def warn_ucn_not_valid_in_c89 : Warning<
+ "universal character names are only valid in C99 or C++; "
+ "treating as '\\' followed by identifier">, InGroup<Unicode>;
+def warn_ucn_not_valid_in_c89_literal : ExtWarn<
+ "universal character names are only valid in C99 or C++">, InGroup<Unicode>;
// Literal
@@ -165,8 +170,6 @@ def ext_string_too_long : Extension<"string literal of length %0 exceeds "
"support">, InGroup<OverlengthStrings>;
def err_character_too_large : Error<
"character too large for enclosing character literal type">;
-def warn_ucn_not_valid_in_c89 : ExtWarn<
- "unicode escape sequences are only valid in C99 or C++">, InGroup<Unicode>;
def warn_cxx98_compat_unicode_literal : Warning<
"unicode literals are incompatible with C++98">,
InGroup<CXX98Compat>, DefaultIgnore;
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 429780eaea3..91c4f664038 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2698,8 +2698,6 @@ bool Lexer::isCodeCompletionPoint(const char *CurPtr) const {
uint32_t Lexer::tryReadUCN(const char *&StartPtr, const char *SlashLoc,
Token *Result) {
- assert(LangOpts.CPlusPlus || LangOpts.C99);
-
unsigned CharSize;
char Kind = getCharAndSize(StartPtr, CharSize);
@@ -2711,6 +2709,11 @@ uint32_t Lexer::tryReadUCN(const char *&StartPtr, const char *SlashLoc,
else
return 0;
+ if (!LangOpts.CPlusPlus && !LangOpts.C99) {
+ Diag(SlashLoc, diag::warn_ucn_not_valid_in_c89);
+ return 0;
+ }
+
const char *CurPtr = StartPtr + CharSize;
const char *KindLoc = &CurPtr[-1];
@@ -2737,7 +2740,7 @@ uint32_t Lexer::tryReadUCN(const char *&StartPtr, const char *SlashLoc,
}
}
}
-
+
return 0;
}
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 1647aa53819..09a94a11436 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -277,7 +277,7 @@ static bool ProcessUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf,
if (!Features.CPlusPlus && !Features.C99 && Diags)
Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
- diag::warn_ucn_not_valid_in_c89);
+ diag::warn_ucn_not_valid_in_c89_literal);
return true;
}
diff --git a/clang/test/Lexer/c90.c b/clang/test/Lexer/c90.c
index 7142c09ac48..826d910b29e 100644
--- a/clang/test/Lexer/c90.c
+++ b/clang/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,5 @@ 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}}
OpenPOWER on IntegriCloud