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

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 01:24:42 PDT 2019


Author: ibiryukov
Date: Wed Jul 10 01:24:42 2019
New Revision: 365599

URL: http://llvm.org/viewvc/llvm-project?rev=365599&view=rev
Log:
[Syntax] Add assertion to catch invalid tokens early. NFC

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

Modified:
    cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
    cfe/trunk/lib/Tooling/Syntax/Tokens.cpp

Modified: cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Syntax/Tokens.h?rev=365599&r1=365598&r2=365599&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Syntax/Tokens.h (original)
+++ cfe/trunk/include/clang/Tooling/Syntax/Tokens.h Wed Jul 10 01:24:42 2019
@@ -99,8 +99,7 @@ llvm::raw_ostream &operator<<(llvm::raw_
 /// 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);
 

Modified: cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Syntax/Tokens.cpp?rev=365599&r1=365598&r2=365599&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Syntax/Tokens.cpp (original)
+++ cfe/trunk/lib/Tooling/Syntax/Tokens.cpp Wed Jul 10 01:24:42 2019
@@ -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());




More information about the cfe-commits mailing list