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 | e601b237e495bb15a5e5df2e20c61fa01a6c4df0 (patch) | |
tree | 30c0657fd9a368d7758c06b6bf9caef1516d3a2e /lib/AST/RawCommentList.cpp | |
parent | 091005954a2e42e6f699dfef25369b3654397536 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158940 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/RawCommentList.cpp')
-rw-r--r-- | lib/AST/RawCommentList.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/AST/RawCommentList.cpp b/lib/AST/RawCommentList.cpp index f32e628caa..438fdcd24c 100644 --- a/lib/AST/RawCommentList.cpp +++ b/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)) |