Эх сурвалжийг харах

[Syntax] Add assertion to catch invalid tokens early. NFC

To help with identifiying root cause of a crash we are seeing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365599 91177308-0d34-0410-b5e6-96231b3b80d8
Ilya Biryukov 6 жил өмнө
parent
commit
155b44067b

+ 1 - 2
include/clang/Tooling/Syntax/Tokens.h

@@ -99,8 +99,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const FileRange &R);
 /// Can represent both expanded and spelled tokens.
 class Token {
 public:
-  Token(SourceLocation Location, unsigned Length, tok::TokenKind Kind)
-      : Location(Location), Length(Length), Kind(Kind) {}
+  Token(SourceLocation Location, unsigned Length, tok::TokenKind Kind);
   /// EXPECTS: clang::Token is not an annotation token.
   explicit Token(const clang::Token &T);
 

+ 6 - 0
lib/Tooling/Syntax/Tokens.cpp

@@ -35,6 +35,12 @@
 using namespace clang;
 using namespace clang::syntax;
 
+syntax::Token::Token(SourceLocation Location, unsigned Length,
+                     tok::TokenKind Kind)
+    : Location(Location), Length(Length), Kind(Kind) {
+  assert(Location.isValid());
+}
+
 syntax::Token::Token(const clang::Token &T)
     : Token(T.getLocation(), T.getLength(), T.getKind()) {
   assert(!T.isAnnotation());