[clang] 2715c4d - Do not emit diagnostics for invalid unicode characters in preprocessing mode

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 18 06:12:43 PDT 2021


Author: Corentin Jabot
Date: 2021-08-18T09:12:36-04:00
New Revision: 2715c4da50387ed6dae49a2a17fdcfad8a769a3c

URL: https://github.com/llvm/llvm-project/commit/2715c4da50387ed6dae49a2a17fdcfad8a769a3c
DIFF: https://github.com/llvm/llvm-project/commit/2715c4da50387ed6dae49a2a17fdcfad8a769a3c.diff

LOG: Do not emit diagnostics for invalid unicode characters in preprocessing mode

This amends 4e80636db71a1b6123d15ed1f9eda3979b4292de with a fix for
https://lab.llvm.org/buildbot/#/builders/139/builds/8943

Added: 
    

Modified: 
    clang/lib/Lex/Lexer.cpp
    clang/test/Lexer/unicode.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index d1555b47dbd0d..05b84e0c14b3e 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1652,7 +1652,8 @@ bool Lexer::tryConsumeIdentifierUCN(const char *&CurPtr, unsigned Size,
   if (!isAllowedIDChar(CodePoint, LangOpts)) {
     if (isASCII(CodePoint) || isUnicodeWhitespace(CodePoint))
       return false;
-    if (!isLexingRawMode())
+    if (!isLexingRawMode() && !ParsingPreprocessorDirective &&
+        !PP->isPreprocessedOutput())
       diagnoseInvalidUnicodeCodepointInIdentifier(
           PP->getDiagnostics(), LangOpts, CodePoint,
           makeCharRange(*this, CurPtr, UCNPtr),
@@ -1691,7 +1692,8 @@ bool Lexer::tryConsumeIdentifierUTF8Char(const char *&CurPtr) {
     if (isASCII(CodePoint) || isUnicodeWhitespace(CodePoint))
       return false;
 
-    if (!isLexingRawMode())
+    if (!isLexingRawMode() && !ParsingPreprocessorDirective &&
+        !PP->isPreprocessedOutput())
       diagnoseInvalidUnicodeCodepointInIdentifier(
           PP->getDiagnostics(), LangOpts, CodePoint,
           makeCharRange(*this, CurPtr, UnicodePtr), /*IsFirst=*/false);

diff  --git a/clang/test/Lexer/unicode.c b/clang/test/Lexer/unicode.c
index fb974a42a1c0c..3d644887fab86 100644
--- a/clang/test/Lexer/unicode.c
+++ b/clang/test/Lexer/unicode.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -x c -std=c11 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -x c++ -std=c++11 %s
-// RUN: %clang_cc1 -E -DPP_ONLY=1 %s -o %t
-// RUN: FileCheck --strict-whitespace --input-file=%t %s
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -E -DPP_ONLY=1 %s | FileCheck %s --strict-whitespace
+// RUN: %clang_cc1 -E -DPP_ONLY=1 %s | FileCheck %s --strict-whitespace
 
 // This file contains Unicode characters; please do not "fix" them!
 


        


More information about the cfe-commits mailing list