diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-21 22:04:37 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-21 22:04:37 +0000 |
commit | 923074016b351405fd86dffdb66bed2646b4ba1f (patch) | |
tree | f933b6cc9a3cbbe3d37bbb1fd8e2456d436a7534 /clang/lib/AST/RawCommentList.cpp | |
parent | c457f620337db407de143681dd00931ff0b97502 (diff) | |
download | bcm5719-llvm-923074016b351405fd86dffdb66bed2646b4ba1f.tar.gz bcm5719-llvm-923074016b351405fd86dffdb66bed2646b4ba1f.zip |
Handle include directive with comments. It turns out that in this case comments are not coming in source order. Instead of trying to std::sort() comments (which can be costly), just remove comments that are not in order.
llvm-svn: 158940
Diffstat (limited to 'clang/lib/AST/RawCommentList.cpp')
-rw-r--r-- | clang/lib/AST/RawCommentList.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp index f32e628caa0..438fdcd24c7 100644 --- a/clang/lib/AST/RawCommentList.cpp +++ b/clang/lib/AST/RawCommentList.cpp @@ -158,13 +158,15 @@ void RawCommentList::addComment(const RawComment &RC) { if (RC.isInvalid()) return; - assert((Comments.empty() || - Comments.back().getSourceRange().getEnd() == - RC.getSourceRange().getBegin() || - SourceMgr.isBeforeInTranslationUnit( - Comments.back().getSourceRange().getEnd(), - RC.getSourceRange().getBegin())) && - "comments are not coming in source order"); + // Check if the comments are not in source order. + while (!Comments.empty() && + !SourceMgr.isBeforeInTranslationUnit( + Comments.back().getSourceRange().getBegin(), + RC.getSourceRange().getBegin())) { + // If they are, just pop a few last comments that don't fit. + // This happens if an \#include directive contains comments. + Comments.pop_back(); + } if (OnlyWhitespaceSeen) { if (!onlyWhitespaceBetweenComments(SourceMgr, LastComment, RC)) |