[cfe-commits] r154981 - in /cfe/trunk: lib/Frontend/TextDiagnostic.cpp test/Misc/wnull-character.cpp

Matthieu Monrocq matthieu.monrocq at gmail.com
Sat Apr 28 02:30:10 PDT 2012


On Fri, Apr 27, 2012 at 2:17 AM, Seth Cantrell <seth.cantrell at gmail.com>wrote:

> Okay, thanks. Without understanding exactly how the scratch buffer is
> used, it seems to me like the right solution is to make the scratch buffer
> or the source manager understand where the actual used portion of the
> buffer ends. I'll take a look and see if I can make that work or think of
> anything else.
>
> I'm not sure I understand your comment about embedded newlines. A new line
> character constitutes the end of a line, and so can never be embedded
> inside a line. And emitSnippetAndCaret takes a SourceLocation and outputs
> in a diagnostic with just the line containing that source location.
>
>
> Hi Seth,

I believe Nico is referring to something like:    printf("%s", "Hello
Seth\n");

This statement has a newline character embedded, which should be rendered
as '\n' and not cause a newline character to be printed.

-- Matthieu


> On Apr 26, 2012, at 5:37 PM, Nico Weber wrote:
>
> > Hi Seth,
> >
> > On Tue, Apr 17, 2012 at 7:44 PM, Seth Cantrell <seth.cantrell at gmail.com>
> wrote:
> >> Author: socantre
> >> Date: Tue Apr 17 21:44:48 2012
> >> New Revision: 154981
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=154981&view=rev
> >> Log:
> >> fix display of source lines with null characters
> >>
> >> Added:
> >>    cfe/trunk/test/Misc/wnull-character.cpp
> >> Modified:
> >>    cfe/trunk/lib/Frontend/TextDiagnostic.cpp
> >>
> >> Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=154981&r1=154980&r2=154981&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
> >> +++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Tue Apr 17 21:44:48 2012
> >> @@ -839,10 +839,13 @@
> >>
> >>   // Get information about the buffer it points into.
> >>   bool Invalid = false;
> >> -  const char *BufStart = SM.getBufferData(FID, &Invalid).data();
> >> +  StringRef BufData = SM.getBufferData(FID, &Invalid);
> >>   if (Invalid)
> >>     return;
> >>
> >> +  const char *BufStart = BufData.data();
> >> +  const char *BufEnd = BufStart + BufData.size();
> >> +
> >>   unsigned LineNo = SM.getLineNumber(FID, FileOffset);
> >>   unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
> >>   unsigned CaretEndColNo
> >> @@ -856,7 +859,7 @@
> >>   // Compute the line end.  Scan forward from the error position to the
> end of
> >>   // the line.
> >>   const char *LineEnd = TokPtr;
> >> -  while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
> >> +  while (*LineEnd != '\n' && *LineEnd != '\r' && LineEnd!=BufEnd)
> >
> > this caused PR12674. I can't think of a good fix, so I'll revert this,
> > with a test that shows what went wrong. Note that even with this CL,
> > strings with embedded newline characters weren't printed correctly.
> >
> > Nico
> >
> >>     ++LineEnd;
> >>
> >>   // FIXME: This shouldn't be necessary, but the CaretEndColNo can
> extend past
> >>
> >> Added: cfe/trunk/test/Misc/wnull-character.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/wnull-character.cpp?rev=154981&view=auto
> >>
> ==============================================================================
> >> Binary files cfe/trunk/test/Misc/wnull-character.cpp (added) and
> cfe/trunk/test/Misc/wnull-character.cpp Tue Apr 17 21:44:48 2012 differ
> >>
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> cfe-commits at cs.uiuc.edu
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120428/c6670a0a/attachment.html>


More information about the cfe-commits mailing list