[clang] Fix clang crash when printing highlighted code in diagnostic (after #66514) (PR #80442)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 08:11:20 PST 2024


================
@@ -1349,7 +1349,7 @@ void TextDiagnostic::emitSnippetAndCaret(
   // Prepare source highlighting information for the lines we're about to
   // emit, starting from the first line.
   std::unique_ptr<SmallVector<StyleRange>[]> SourceStyles =
-      highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+      highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,
----------------
AaronBallman wrote:

Thank you for the debugging help! You're right, the scratch buffer does embed null characters: https://github.com/llvm/llvm-project/blob/ae354c5a45d319b3117c2822b8f6988461f3cb33/clang/lib/Lex/ScratchBuffer.cpp#L62

That gets used for the stringify operator (`#`) as well as for the `__DATE__` and `__TIME__` predefined macros, and the `_Pragma` operator; hopefully that helps @tbaederr to find a way to add test coverage for this so we don't accidentally regress it in the future.

https://github.com/llvm/llvm-project/pull/80442


More information about the cfe-commits mailing list