[PATCH] Parse: Don't crash on trailing whitespace before EOF

David Majnemer david.majnemer at gmail.com
Wed Jul 23 15:27:47 PDT 2014


  - Address Richard's review comments.

http://reviews.llvm.org/D4646

Files:
  lib/Parse/ParseDecl.cpp
  test/Parser/eof2.cpp

Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2449,8 +2449,11 @@
                                         DeclSpecContext DSContext,
                                         LateParsedAttrList *LateAttrs) {
   if (DS.getSourceRange().isInvalid()) {
+    // Start the range at the current token but make the end of the range
+    // invalid.  This will make the entire range invalid unless we successfully
+    // consume a token.
     DS.SetRangeStart(Tok.getLocation());
-    DS.SetRangeEnd(Tok.getLocation());
+    DS.SetRangeEnd(SourceLocation());
   }
 
   bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level);
Index: test/Parser/eof2.cpp
===================================================================
--- /dev/null
+++ test/Parser/eof2.cpp
@@ -0,0 +1,15 @@
+// RUN: not %clang_cc1 %s -fsyntax-only 2>&1 | FileCheck %s
+
+// CHECK: error: expected expression
+// CHECK: error: expected member name or ';' after declaration specifiers
+// CHECK: error: expected '}'
+// CHECK: note: to match this '{'
+// CHECK: error: expected ';' after class
+// CHECK: 4 errors generated.
+
+// Do not add anything to the end of this file.  This requires the whitespace
+// plus EOF after the '<' token.
+
+template <typename T>
+class a {
+  a<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4646.11824.patch
Type: text/x-patch
Size: 1379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140723/a9ab5a7c/attachment.bin>


More information about the cfe-commits mailing list