[PATCH] D15173: [Preprocessor] Fix assertion in AnnotatePreviousCachedTokens
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 12 17:25:59 PST 2015
bruno updated this revision to Diff 42649.
bruno added a comment.
Thanks Duncan and Argyrios, updated a patch with the suggestions!
http://reviews.llvm.org/D15173
Files:
lib/Lex/PPCaching.cpp
test/Parser/objcxx11-protocol-in-template.mm
Index: test/Parser/objcxx11-protocol-in-template.mm
===================================================================
--- test/Parser/objcxx11-protocol-in-template.mm
+++ test/Parser/objcxx11-protocol-in-template.mm
@@ -8,3 +8,11 @@
vector<id<P>> v;
vector<vector<id<P>>> v2;
+
+ at protocol PA;
+ at protocol PB;
+
+ at class NSArray<ObjectType>;
+typedef int some_t;
+
+id<PA> FA(NSArray<id<PB>> *h, some_t group);
Index: lib/Lex/PPCaching.cpp
===================================================================
--- lib/Lex/PPCaching.cpp
+++ lib/Lex/PPCaching.cpp
@@ -97,8 +97,26 @@
void Preprocessor::AnnotatePreviousCachedTokens(const Token &Tok) {
assert(Tok.isAnnotation() && "Expected annotation token");
assert(CachedLexPos != 0 && "Expected to have some cached tokens");
- assert(CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc()
- && "The annotation should be until the most recent cached token");
+
+#ifndef NDEBUG
+ Token CachedLastTok = CachedTokens[CachedLexPos - 1];
+ SourceLocation CachedLastTokLoc = CachedLastTok.getLastLoc();
+ SourceLocation TokAnnEndLoc = Tok.getAnnotationEndLoc();
+
+ // The annotation should be until the most recent cached token. Since
+ // `Tok` length could be bigger than one (e.g. greatergreater '>>'), account
+ // for that cases before checking the assertion.
+ if (!CachedLastTok.isAnnotation()) {
+ CachedLastTokLoc =
+ CachedLastTokLoc.getLocWithOffset(CachedLastTok.getLength());
+ unsigned TokAnnEndLocSize = Lexer::MeasureTokenLength(
+ SourceMgr.getSpellingLoc(TokAnnEndLoc), SourceMgr, LangOpts);
+ TokAnnEndLoc = TokAnnEndLoc.getLocWithOffset(TokAnnEndLocSize);
+ }
+
+ assert(CachedLastTokLoc == TokAnnEndLoc &&
+ "The annotation should be until the most recent cached token");
+#endif
// Start from the end of the cached tokens list and look for the token
// that is the beginning of the annotation token.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15173.42649.patch
Type: text/x-patch
Size: 1948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151213/bb8367ab/attachment.bin>
More information about the cfe-commits
mailing list