From c1e32fca96743194a28519bb90add1137d96f65c Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 11 Oct 2017 00:41:20 +0000 Subject: [PATCH] A '<' with a trigraph '#' is not a valid editor placeholder Credit to OSS-Fuzz for discovery: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3137#c5 rdar://34923985 llvm-svn: 315398 --- clang/lib/Lex/Lexer.cpp | 3 ++- clang/test/Parser/editor-placeholder-recovery.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 9885ab9d3e29..0c179c0fb875 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -3542,7 +3542,8 @@ LexNextToken: } else if (LangOpts.Digraphs && Char == '%') { // '<%' -> '{' CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); Kind = tok::l_brace; - } else if (Char == '#' && lexEditorPlaceholder(Result, CurPtr)) { + } else if (Char == '#' && /*Not a trigraph*/ SizeTmp == 1 && + lexEditorPlaceholder(Result, CurPtr)) { return true; } else { Kind = tok::less; diff --git a/clang/test/Parser/editor-placeholder-recovery.cpp b/clang/test/Parser/editor-placeholder-recovery.cpp index 48c290ee9a14..d68e087d6fba 100644 --- a/clang/test/Parser/editor-placeholder-recovery.cpp +++ b/clang/test/Parser/editor-placeholder-recovery.cpp @@ -69,3 +69,7 @@ void Struct::method(<#Struct &x#>, noSupressionHere) { // expected-error {{unkno // expected-error@-2 {{editor placeholder in source file}} #endif } + +void handleTrigraph() { + // expected-error {{expected expression}} expected-error {{expected expression}} expected-warning {{trigraph converted to '#' character}} +}