[cfe-commits] r160970 - in /cfe/trunk: include/clang/AST/Comment.h tools/libclang/CXComment.cpp
Dmitri Gribenko
gribozavr at gmail.com
Mon Jul 30 10:38:19 PDT 2012
Author: gribozavr
Date: Mon Jul 30 12:38:19 2012
New Revision: 160970
URL: http://llvm.org/viewvc/llvm-project?rev=160970&view=rev
Log:
Add an assert to ParamCommandComment::getParamIndex() -- it should not be
called unless index is valid.
Modified:
cfe/trunk/include/clang/AST/Comment.h
cfe/trunk/tools/libclang/CXComment.cpp
Modified: cfe/trunk/include/clang/AST/Comment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=160970&r1=160969&r2=160970&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Comment.h (original)
+++ cfe/trunk/include/clang/AST/Comment.h Mon Jul 30 12:38:19 2012
@@ -713,6 +713,7 @@
}
unsigned getParamIndex() const LLVM_READONLY {
+ assert(isParamIndexValid());
return ParamIndex;
}
Modified: cfe/trunk/tools/libclang/CXComment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXComment.cpp?rev=160970&r1=160969&r2=160970&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXComment.cpp (original)
+++ cfe/trunk/tools/libclang/CXComment.cpp Mon Jul 30 12:38:19 2012
@@ -256,7 +256,7 @@
unsigned clang_ParamCommandComment_getParamIndex(CXComment CXC) {
const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
- if (!PCC)
+ if (!PCC || !PCC->isParamIndexValid())
return ParamCommandComment::InvalidParamIndex;
return PCC->getParamIndex();
@@ -316,11 +316,18 @@
class ParamCommandCommentCompareIndex {
public:
+ /// This comparison will sort parameters with valid index by index and
+ /// invalid (unresolved) parameters last.
bool operator()(const ParamCommandComment *LHS,
const ParamCommandComment *RHS) const {
- // To sort invalid (unresolved) parameters last, this comparison relies on
- // invalid indices to be UINT_MAX.
- return LHS->getParamIndex() < RHS->getParamIndex();
+ unsigned LHSIndex = UINT_MAX;
+ unsigned RHSIndex = UINT_MAX;
+ if (LHS->isParamIndexValid())
+ LHSIndex = LHS->getParamIndex();
+ if (RHS->isParamIndexValid())
+ RHSIndex = RHS->getParamIndex();
+
+ return LHSIndex < RHSIndex;
}
};
More information about the cfe-commits
mailing list