[clang] Fix clang crash when printing highlighted code in diagnostic (after #66514) (PR #80442)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 2 08:03:55 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,
----------------
bgra8 wrote:
> we have an existing test that embeds a null character into the source and that doesn't seem to reproduce the issue
Can you construct a test case with an embedded null character into the source and make the call to `PP->getCheckPoint(FID, FirstLineStart))` (at `clang/lib/Frontend/TextDiagnostic.cpp:1155` also shown below) return an address _after_ the null? That would reproduce the issue.
```
const char *FirstLineStart =
FileData.data() +
SM.getDecomposedLoc(SM.translateLineCol(FID, StartLineNumber, 1)).second;
if (const char *CheckPoint = PP->getCheckPoint(FID, FirstLineStart)) {
assert(CheckPoint >= Buff->getBufferStart() &&
CheckPoint <= Buff->getBufferEnd());
assert(CheckPoint <= FirstLineStart);
size_t Offset = CheckPoint - Buff->getBufferStart();
L.seek(Offset, /*IsAtStartOfLine=*/false);
}
```
https://github.com/llvm/llvm-project/pull/80442
More information about the cfe-commits
mailing list