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

2024-02-05 Thread Aaron Ballman via cfe-commits


@@ -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[]> 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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

That's about as much as we can help with further debugging. As I said, I don't 
see how to create a reliable test case here.

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


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

2024-02-02 Thread via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

Some debugging.

Backtrace:
```
frame #7: 0x754b2ee6 clang`__assert_fail(assertion="CheckPoint >= 
Buff->getBufferStart() && CheckPoint <= Buff->getBufferEnd()", 
file="llvm-project/clang/lib/Frontend/TextDiagnostic.cpp", line=1157, 
function="std::unique_ptr[]> 
highlightLines(StringRef, unsigned int, unsigned int, const Preprocessor *, 
const LangOptions &, bool, FileID, const SourceManager &)") at logging.cc:57:3
frame #8: 0x67bfc020 clang`highlightLines(FileData=(Data = "\n 
clang diagnostic ignored \"-Wdeprecated-declarations\"\n", Length = 55), 
StartLineNumber=40, EndLineNumber=40, PP=0x25c8bf806018, 
LangOpts=0x25c8bf848918, ShowColors=true, FID=(ID = 23810), 
SM=0x25c8bf892000) at TextDiagnostic.cpp:1156:5
frame #9: 0x67bfabcc 
clang`clang::TextDiagnostic::emitSnippetAndCaret(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff3b68, Level=Note, Ranges=0x7fff3c80, 
Hints=ArrayRef @ 0x7fff3b90) at TextDiagnostic.cpp:1352:7
frame #10: 0x67c021a7 
clang`clang::TextDiagnostic::emitCodeContext(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff3c00, Level=Note, Ranges=0x7fff3c80, 
Hints=ArrayRef @ 0x7fff3c20) at TextDiagnostic.h:97:5
frame #11: 0x67bc1a9d 
clang`clang::DiagnosticRenderer::emitCaret(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff3ce0, Level=Note, Ranges=ArrayRef @ 
0x7fff3cd0, Hints=ArrayRef @ 0x7fff3d00) at 
DiagnosticRenderer.cpp:429:3
frame #12: 0x67bc1112 
clang`clang::DiagnosticRenderer::emitDiagnostic(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff4270, Level=Note, Message=(Data = "expanded 
from hereo '_GLIB_GNUC_DO_PRAGMA'_FOR'_48_FOR'", Length = 18), Ranges=ArrayRef 
@ 0x7fff42a0, FixItHints=ArrayRef @ 0x7fff42b0, 
D=clang::DiagOrStoredDiag @ 0x7fff4258) at DiagnosticRenderer.cpp:127:5
frame #13: 0x67bc3549 
clang`clang::DiagnosticRenderer::emitSingleMacroExpansion(this=0x25c8bfc62f00,
 Loc=FullSourceLoc @ 0x7fff44c8, Level=Warning, Ranges=ArrayRef @ 
0x7fff44b8) at DiagnosticRenderer.cpp:454:3
frame #14: 0x67bc1f4b 
clang`clang::DiagnosticRenderer::emitMacroExpansions(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff4840, Level=Warning, Ranges=ArrayRef @ 
0x7fff4830, Hints=ArrayRef @ 0x7fff4860) at 
DiagnosticRenderer.cpp:569:7
frame #15: 0x67bc11dc 
clang`clang::DiagnosticRenderer::emitDiagnostic(this=0x25c8bfc62f00, 
Loc=FullSourceLoc @ 0x7fff4dd0, Level=Warning, Message=(Data = 
"Deprecated pre-processor symbol: replace with \"static inline\" 
[-W#pragma-messages]\xff\xff\xff\U007f", Length = 82), Ranges=ArrayRef @ 
0x7fff4e00, FixItHints=ArrayRef @ 0x7fff4e10, 
D=clang::DiagOrStoredDiag @ 0x7fff4db8) at DiagnosticRenderer.cpp:132:7
frame #16: 0x67bf73b6 
clang`clang::TextDiagnosticPrinter::HandleDiagnostic(this=0x25c8bfc16630, 
Level=Warning, Info=0x7fff50c8) at TextDiagnosticPrinter.cpp:151:13
frame #17: 0x6c6a0148 
clang`clang::DiagnosticIDs::EmitDiag(this=0x25c8bfc04840, 
Diag=0x25c8bf85c900, DiagLevel=Warning) const at DiagnosticIDs.cpp:823:16
frame #18: 0x6c69fef0 
clang`clang::DiagnosticIDs::ProcessDiag(this=0x25c8bfc04840, 
Diag=0x25c8bf85c900) const at DiagnosticIDs.cpp:815:3
frame #19: 0x6c69437a 
clang`clang::DiagnosticsEngine::ProcessDiag(this=0x25c8bf85c900) at 
Diagnostic.h:1042:19
frame #20: 0x6c68ef05 
clang`clang::DiagnosticsEngine::EmitCurrentDiagnostic(this=0x25c8bf85c900, 
Force=false) at Diagnostic.cpp:545:15
frame #21: 0x62f61b4d 
clang`clang::DiagnosticBuilder::Emit(this=0x7fff5420) at 
Diagnostic.h:1325:28
frame #22: 0x62f5fb6c 
clang`clang::DiagnosticBuilder::~DiagnosticBuilder(this=0x7fff5420) at 
Diagnostic.h:1366:26
frame #23: 0x6c5db9c0 clang`(anonymous 
namespace)::PragmaMessageHandler::HandlePragma(this=0x25c8bfc62c40, 
PP=0x25c8bf806018, Introducer=PragmaIntroducer @ 0x7fff54f8, 
Tok=0x7fff5720) at Pragma.cpp:1675:5
frame #24: 0x6c5d33fb 
clang`clang::PragmaNamespace::HandlePragma(this=0x25c8bfc636c0, 
PP=0x25c8bf806018, Introducer=PragmaIntroducer @ 0x7fff55c8, 
Tok=0x7fff5720) at Pragma.cpp:124:12
frame #25: 0x6c5d33fb 
clang`clang::PragmaNamespace::HandlePragma(this=0x25c8bfc63600, 

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

2024-02-02 Thread via cfe-commits


@@ -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[]> 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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits

https://github.com/alexfh edited https://github.com/llvm/llvm-project/pull/80442
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits

https://github.com/alexfh edited https://github.com/llvm/llvm-project/pull/80442
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

I'll try to provide what I have so far, but I doubt it's feasible to create a 
good test case for this.

So here's what I have so far (requires GLib 2.78.3 in third_party/glib/):
```
$ cat q.c
#include 
#include 
#include 
#include "q.h"
$ cat q.h
#ifndef __Q_H__
#define __Q_H__

#include 
#include "third_party/glib/glib/glib.h"

G_INLINE_FUNC void q();

#endif
$ cat stl/math.h
#ifndef _STL_MATH_H_
#define _STL_MATH_H_

#include_next 

#endif
$ cat stl/string.h
#ifndef _STL_STRING_H_
#define _STL_STRING_H_

#include_next 

#endif
$ clang -iquote . -isystem stl  -fdiagnostics-show-option -fcolor-diagnostics  
-Wall -Werror --target=aarch64-unknown-linux-gnu -mcpu=neoverse-n1  
--sysroot=our/custom/libc -D_Q1 -D_Q2 -D_Q3 -D_Q4 -D_Q5 -D_Q6 -D_Q7 -D_Q8 -D_Q9 
-D_Q10 -D_Q11 -D_Q12 -D_Q13  -D_Q14  -D_Q15 -D_Q16 -D_Q17 -D_Q18 -D_Q19 -c q.c 
-fsyntax-only

In file included from q.c:4:
./q.h:7:1: warning: Deprecated pre-processor symbol: replace with "static 
inline" [-W#pragma-messages]
7 | G_INLINE_FUNC void q();
  | ^
./third_party/glib/glib/gmacros.h:157:39: note: expanded from macro 
'G_INLINE_FUNC'
  157 | #  define G_INLINE_FUNC static inline 
GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
  |   ^
./third_party/glib/glib/glib-visibility.h:414:46: note: expanded from macro 
'GLIB_DEPRECATED_MACRO_IN_2_48_FOR'
  414 | #define GLIB_DEPRECATED_MACRO_IN_2_48_FOR(f) GLIB_DEPRECATED_MACRO_FOR 
(f)
  |  ^
./third_party/glib/glib/gmacros.h:1299:3: note: expanded from macro 
'GLIB_DEPRECATED_MACRO_FOR'
 1299 |   _GLIB_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Deprecated 
pre-processor symbol: replace with #f))
  |   ^
./third_party/glib/glib/gmacros.h:1296:33: note: expanded from macro 
'_GLIB_GNUC_DO_PRAGMA'
 1296 | #define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))


   | ^  


  :40:6: note: expanded from here
assert.h assertion failed at 
llvm-project/clang/lib/Frontend/TextDiagnostic.cpp:1157 in 
std::unique_ptr[]> 
highlightLines(StringR
ef, unsigned int, unsigned int, const Preprocessor *, const LangOptions &, 
bool, FileID, const SourceManager &): CheckPoint >= Buff->getBufferStart() && 
CheckPoint <= Buff->getBufferEnd()
*** Check failure stack trace: ***
@ 0x562b1f8b03a3  __assert_fail
@ 0x562b170c558e  clang::TextDiagnostic::emitSnippetAndCaret()
@ 0x562b170c7b02  clang::TextDiagnostic::emitCodeContext()
@ 0x562b1709bcbc  clang::DiagnosticRenderer::emitDiagnostic()
@ 0x562b1709ef73  clang::DiagnosticRenderer::emitSingleMacroExpansion()
@ 0x562b1709cf56  clang::DiagnosticRenderer::emitMacroExpansions()
@ 0x562b1709bd47  clang::DiagnosticRenderer::emitDiagnostic()
@ 0x562b170bc4bb  clang::TextDiagnosticPrinter::HandleDiagnostic()
@ 0x562b1996038a  clang::DiagnosticIDs::EmitDiag()
@ 0x562b19960183  clang::DiagnosticIDs::ProcessDiag()
@ 0x562b199564ac  clang::DiagnosticsEngine::EmitCurrentDiagnostic()
@ 0x562b198aa621  (anonymous 
namespace)::PragmaMessageHandler::HandlePragma()
@ 0x562b198a12d6  clang::PragmaNamespace::HandlePragma()
@ 0x562b198a12d6  clang::PragmaNamespace::HandlePragma()
@ 0x562b198a1587  clang::Preprocessor::HandlePragmaDirective()
@ 0x562b198a21ad  clang::Preprocessor::Handle_Pragma()
@ 0x562b1988aec3  clang::Preprocessor::ExpandBuiltinMacro()
@ 0x562b19889599  clang::Preprocessor::HandleMacroExpandedIdentifier()
@ 0x562b198c32f8  clang::Preprocessor::HandleIdentifier()
@ 0x562b198d5023  clang::TokenLexer::Lex()
@ 0x562b1987c316  clang::Preprocessor::CLK_TokenLexer()
@ 0x562b198c3bfd  clang::Preprocessor::Lex()
@ 0x562b173942fa  clang::Parser::ConsumeToken()
@ 0x562b17393915  clang::Parser::ConsumeAnyToken()
@ 0x562b174784f5  clang::Parser::ParseDeclarationSpecifiers()
@ 0x562b1739ed03  clang::Parser::ParseDeclOrFunctionDefInternal()
@ 0x562b1739e4af  clang::Parser::ParseDeclarationOrFunctionDefinition()
@ 0x562b1739c864  

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

2024-02-02 Thread via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

eaeltsin wrote:

The original crash actually happened on the contents of ``, 
forgot to mention that.

Can it be that scratch space terminates with those `\0`?

I also see involved macros of the form
```
#define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
```


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


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

2024-02-02 Thread via cfe-commits

https://github.com/alexfh closed https://github.com/llvm/llvm-project/pull/80442
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

This may explain the presence of \0's

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


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

2024-02-02 Thread via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

alexfh wrote:

I've got a (still quite hairy and not shareable) reproducer that requires the 
use of a number of defines on the command line to actually cause an assertion 
failure (`-D_Q1 -D_Q2 -D_Q3 -D_Q4 -D_Q5 -D_Q6 -D_Q7 -D_Q8 -D_Q9 -D_Q10 -D_Q11 
-D_Q12 -D_Q13  -D_Q14  -D_Q15 -D_Q16 -D_Q17 -D_Q18 -D_Q19`). Removing any of 
the defines makes the crash disappear.

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


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

2024-02-02 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM to get this unblocked, but I would love it if we could add a test case 
post-commit.

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


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

2024-02-02 Thread Aaron Ballman via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

AaronBallman wrote:

Hmmm, we have an existing test that embeds a null character into the source and 
that doesn't seem to reproduce the issue, but it sure stands to reason it would 
be something along those lines. Good catch!

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


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

2024-02-02 Thread Erich Keane via cfe-commits


@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,

erichkeane wrote:

So this should only matter if there is a null-terminator in the `BufData`, 
right?  I'm really curious what could have caused that.  It would be 
appreciated if we could still get a reduced version of the test for a lit-test, 
but as this is blocking your downstream, I can accept without a repro.

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


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

2024-02-02 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


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


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

2024-02-02 Thread Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/80442
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (alexfh)


Changes

Implements the fix proposed by Evgeny Eltsin on
https://github.com/llvm/llvm-project/pull/66514#issuecomment-1924039038.

No test case provided, since the bug is extremely sensitive to the preprocessor
state (headers, macros, including the ones defined on command line), and it
turned out to be non-trivial to create an isolated test.


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


1 Files Affected:

- (modified) clang/lib/Frontend/TextDiagnostic.cpp (+1-1) 


``diff
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 627a7641308a1..10240d7ee6f2e 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,
  DiagOpts->ShowColors, FID, SM);
 
   SmallVector LineRanges =

``




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


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

2024-02-02 Thread via cfe-commits

https://github.com/alexfh ready_for_review 
https://github.com/llvm/llvm-project/pull/80442
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-02-02 Thread via cfe-commits

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

Implements the fix proposed by Evgeny Eltsin on
https://github.com/llvm/llvm-project/pull/66514#issuecomment-1924039038.

No test case provided, since the bug is extremely sensitive to the preprocessor
state (headers, macros, including the ones defined on command line), and it
turned out to be non-trivial to create an isolated test.


>From 2a1a539d94a9214e09e877710a3f866a260d0371 Mon Sep 17 00:00:00 2001
From: Alexander Kornienko 
Date: Fri, 2 Feb 2024 16:03:56 +0100
Subject: [PATCH] Fix clang crash when printing highlighted code in diagnostic
 (after #66514)

Implements the fix proposed by Evgeny Eltsin on
https://github.com/llvm/llvm-project/pull/66514#issuecomment-1924039038.

No test case provided, since the bug is extremely sensitive to the preprocessor
state (headers, macros, including the ones defined on command line), and it
turned out to be non-trivial to create an isolated test.
---
 clang/lib/Frontend/TextDiagnostic.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 627a7641308a1..10240d7ee6f2e 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -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[]> SourceStyles =
-  highlightLines(BufStart, Lines.first, Lines.second, PP, LangOpts,
+  highlightLines(BufData, Lines.first, Lines.second, PP, LangOpts,
  DiagOpts->ShowColors, FID, SM);
 
   SmallVector LineRanges =

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits