diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 89fda3e839cb9..eb241f34d095e 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -812,7 +812,7 @@ bool VerifyDiagnosticConsumer::HandleComment(Preprocessor &PP, C2 += C.substr(last, loc-last); last = loc + 1; - if (C[last] == '\n' || C[last] == '\r') { + if (last < C.size() && (C[last] == '\n' || C[last] == '\r')) { ++last; // Escape \r\n or \n\r, but not \n\n. diff --git a/clang/test/Frontend/verify-gh141221.c b/clang/test/Frontend/verify-gh141221.c new file mode 100644 index 0000000000000..eb0be46a3da8b --- /dev/null +++ b/clang/test/Frontend/verify-gh141221.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -verify %s + +// Check that we don't crash if the file ends in a splice +// This file should *NOT* end with a new line +a; +// expected-error@-1 {{}} \ \ No newline at end of file