[PATCH] D108296: Do not emit diagnostics for invalid unicode characters in preprocessing mode

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 18 05:58:33 PDT 2021


cor3ntin created this revision.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108296

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


Index: clang/test/Lexer/unicode.c
===================================================================
--- clang/test/Lexer/unicode.c
+++ clang/test/Lexer/unicode.c
@@ -1,5 +1,6 @@
 // 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 -triple x86_64-scei-ps4 -E -DPP_ONLY=1 %s -o %t
 // RUN: %clang_cc1 -E -DPP_ONLY=1 %s -o %t
 // RUN: FileCheck --strict-whitespace --input-file=%t %s
 
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1652,7 +1652,8 @@
   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 @@
     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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108296.367187.patch
Type: text/x-patch
Size: 1487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210818/2947f3e2/attachment.bin>


More information about the cfe-commits mailing list