llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

<details>
<summary>Changes</summary>

When the comment ends with a splice at EOF.

Fixes #<!-- -->141221

---
Full diff: https://github.com/llvm/llvm-project/pull/141940.diff


2 Files Affected:

- (modified) clang/lib/Frontend/VerifyDiagnosticConsumer.cpp (+1-1) 
- (added) clang/test/Frontend/verify-gh141221.c (+6) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/141940
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to