[llvm-branch-commits] [cfe-branch] r309580 - Merging r309503:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jul 31 10:00:56 PDT 2017


Author: hans
Date: Mon Jul 31 10:00:55 2017
New Revision: 309580

URL: http://llvm.org/viewvc/llvm-project?rev=309580&view=rev
Log:
Merging r309503:
------------------------------------------------------------------------
r309503 | rsmith | 2017-07-29 23:31:29 -0700 (Sat, 29 Jul 2017) | 6 lines

PR33902: Invalidate line number cache when adding more text to existing buffer.

This led to crashes as the line number cache would report a bogus line number
for a line of code, and we'd try to find a nonexistent column within the line
when printing diagnostics.

------------------------------------------------------------------------

Modified:
    cfe/branches/release_50/   (props changed)
    cfe/branches/release_50/lib/Lex/ScratchBuffer.cpp
    cfe/branches/release_50/test/Misc/caret-diags-multiline.cpp

Propchange: cfe/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jul 31 10:00:55 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:308455,308824,308897,309058,309112-309113,309226,309327
+/cfe/trunk:308455,308824,308897,309058,309112-309113,309226,309327,309503
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_50/lib/Lex/ScratchBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/Lex/ScratchBuffer.cpp?rev=309580&r1=309579&r2=309580&view=diff
==============================================================================
--- cfe/branches/release_50/lib/Lex/ScratchBuffer.cpp (original)
+++ cfe/branches/release_50/lib/Lex/ScratchBuffer.cpp Mon Jul 31 10:00:55 2017
@@ -35,6 +35,14 @@ SourceLocation ScratchBuffer::getToken(c
                                        const char *&DestPtr) {
   if (BytesUsed+Len+2 > ScratchBufSize)
     AllocScratchBuffer(Len+2);
+  else {
+    // Clear out the source line cache if it's already been computed.
+    // FIXME: Allow this to be incrementally extended.
+    auto *ContentCache = const_cast<SrcMgr::ContentCache *>(
+        SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc))
+                 .getFile().getContentCache());
+    ContentCache->SourceLineCache = nullptr;
+  }
 
   // Prefix the token with a \n, so that it looks like it is the first thing on
   // its own virtual line in caret diagnostics.

Modified: cfe/branches/release_50/test/Misc/caret-diags-multiline.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/test/Misc/caret-diags-multiline.cpp?rev=309580&r1=309579&r2=309580&view=diff
==============================================================================
--- cfe/branches/release_50/test/Misc/caret-diags-multiline.cpp (original)
+++ cfe/branches/release_50/test/Misc/caret-diags-multiline.cpp Mon Jul 31 10:00:55 2017
@@ -232,3 +232,8 @@ void multiple_ranges(int a, int b) {
   b
   );
 }
+
+#define pr33902_a(b) #b
+#define pr33902_c(d) _Pragma(pr33902_a(d))
+#define pr33902_e(f) pr33902_c(GCC warning #f)
+pr33902_e() pr33902_e()




More information about the llvm-branch-commits mailing list