]> granicus.if.org Git - clang/commitdiff
[Syntax] Add assertion to catch invalid tokens early. NFC
authorIlya Biryukov <ibiryukov@google.com>
Wed, 10 Jul 2019 08:24:42 +0000 (08:24 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Wed, 10 Jul 2019 08:24:42 +0000 (08:24 +0000)
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

include/clang/Tooling/Syntax/Tokens.h
lib/Tooling/Syntax/Tokens.cpp

index a89ff3680d2fbf780695a63e44d8c3bf9b7241b3..4640ccb2d30aaff0b6aa7a8f2aabe1a7afb0e24b 100644 (file)
@@ -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);
 
index b42d5a2ca64e3028251ef3a668f39e5742814a5a..d82dc1f35c9445dc4a226152e2615ed245fe4736 100644 (file)
 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());