[cfe-commits] r158940 - in /cfe/trunk: lib/AST/RawCommentList.cpp test/Index/Inputs/annotate-comments-preprocessor.h test/Index/annotate-comments-preprocessor.c
Dmitri Gribenko
gribozavr at gmail.com
Thu Jun 21 15:04:37 PDT 2012
Author: gribozavr
Date: Thu Jun 21 17:04:37 2012
New Revision: 158940
URL: http://llvm.org/viewvc/llvm-project?rev=158940&view=rev
Log:
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.
Added:
cfe/trunk/test/Index/Inputs/annotate-comments-preprocessor.h
cfe/trunk/test/Index/annotate-comments-preprocessor.c
Modified:
cfe/trunk/lib/AST/RawCommentList.cpp
Modified: cfe/trunk/lib/AST/RawCommentList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RawCommentList.cpp?rev=158940&r1=158939&r2=158940&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RawCommentList.cpp (original)
+++ cfe/trunk/lib/AST/RawCommentList.cpp Thu Jun 21 17:04:37 2012
@@ -158,13 +158,15 @@
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))
Added: cfe/trunk/test/Index/Inputs/annotate-comments-preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/annotate-comments-preprocessor.h?rev=158940&view=auto
==============================================================================
--- cfe/trunk/test/Index/Inputs/annotate-comments-preprocessor.h (added)
+++ cfe/trunk/test/Index/Inputs/annotate-comments-preprocessor.h Thu Jun 21 17:04:37 2012
@@ -0,0 +1,2 @@
+/* Meow */
+
Added: cfe/trunk/test/Index/annotate-comments-preprocessor.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-comments-preprocessor.c?rev=158940&view=auto
==============================================================================
--- cfe/trunk/test/Index/annotate-comments-preprocessor.c (added)
+++ cfe/trunk/test/Index/annotate-comments-preprocessor.c Thu Jun 21 17:04:37 2012
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs %s
+
+// As long as none of this crashes, we don't care about comments in
+// preprocessor directives.
+
+#include "annotate-comments-preprocessor.h" /* Aaa. */ /* Bbb. */
+#include "annotate-comments-preprocessor.h" /* Aaa. */
+#include "annotate-comments-preprocessor.h" /** Aaa. */
+#include "annotate-comments-preprocessor.h" /**< Aaa. */
+#include "annotate-comments-preprocessor.h" // Aaa.
+#include "annotate-comments-preprocessor.h" /// Aaa.
+#include "annotate-comments-preprocessor.h" ///< Aaa.
+
+#define A0 0
+#define A1 1 /* Aaa. */
+#define A2 1 /** Aaa. */
+#define A3 1 /**< Aaa. */
+#define A4 1 // Aaa.
+#define A5 1 /// Aaa.
+#define A6 1 ///< Aaa.
+
+int A[] = { A0, A1, A2, A3, A4, A5, A6 };
+
+#if A0 /** Aaa. */
+int f(int a1[A1], int a2[A2], int a3[A3], int a4[A4], int a5[A5], int a6[A6]);
+#endif /** Aaa. */
+
+#if A1 /** Aaa. */
+int g(int a1[A1], int a2[A2], int a3[A3], int a4[A4], int a5[A5], int a6[A6]);
+#endif /* Aaa. */
+
+#pragma once /** Aaa. */
+
+#define FOO \
+ do { \
+ /* Aaa. */ \
+ /** Aaa. */ \
+ /**< Aaa. */ \
+ ; \
+ } while(0)
+
+void h(void) {
+ FOO;
+}
+
More information about the cfe-commits
mailing list