diff --git a/clang-tools-extra/pseudo/test/crash/bad-ucn.c b/clang-tools-extra/pseudo/test/crash/bad-ucn.c new file mode 100644 --- /dev/null +++ b/clang-tools-extra/pseudo/test/crash/bad-ucn.c @@ -0,0 +1,4 @@ +// This UCN doesn't encode a valid codepoint. +// We used to assert while trying to expand UCNs in the token. +// RUN: clang-pseudo -source=%s +A\UAAAAAAAA diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -320,10 +320,8 @@ llvm::SmallVectorImpl &Str) { char ResultBuf[4]; char *ResultPtr = ResultBuf; - bool Res = llvm::ConvertCodePointToUTF8(Codepoint, ResultPtr); - (void)Res; - assert(Res && "Unexpected conversion failure"); - Str.append(ResultBuf, ResultPtr); + if (llvm::ConvertCodePointToUTF8(Codepoint, ResultPtr)) + Str.append(ResultBuf, ResultPtr); } void clang::expandUCNs(SmallVectorImpl &Buf, StringRef Input) { diff --git a/clang/test/Lexer/unicode.c b/clang/test/Lexer/unicode.c --- a/clang/test/Lexer/unicode.c +++ b/clang/test/Lexer/unicode.c @@ -28,6 +28,9 @@ int _; +extern int X\UAAAAAAAA; // expected-error {{not allowed in an identifier}} +int Y = '\UAAAAAAAA'; // expected-error {{invalid universal character}} + #ifdef __cplusplus extern int ༀ;