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

David Majnemer david.majnemer at gmail.com
Wed Jul 23 12:48:17 PDT 2014


Hi rsmith,

Parser::ParseDeclarationSpecifiers eagerly updates the source range of
the DeclSpec with the current token position.  However, it might not
consume any more tokens.

Fix this by only setting the start of the range, not the end.  This way
the SourceRange will be invalid if we don't consume any more tokens.

This fixes PR20413.

http://reviews.llvm.org/D4646

Files:
  lib/Parse/ParseDecl.cpp

Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2450,7 +2450,7 @@
                                         LateParsedAttrList *LateAttrs) {
   if (DS.getSourceRange().isInvalid()) {
     DS.SetRangeStart(Tok.getLocation());
-    DS.SetRangeEnd(Tok.getLocation());
+    DS.SetRangeEnd(SourceLocation());
   }
 
   bool EnteringContext = (DSContext == DSC_class || DSContext == DSC_top_level);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4646.11818.patch
Type: text/x-patch
Size: 503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140723/f0e6eed0/attachment.bin>


More information about the cfe-commits mailing list