diff options
| author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-30 17:38:19 +0000 |
|---|---|---|
| committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-30 17:38:19 +0000 |
| commit | a260c030b85b72a3efa5179239e11933b02ef37a (patch) | |
| tree | 814351bbd76c51dd50803030fd7bfd8397d7d2ab | |
| parent | eb488fe16532518160ef55bbbfcdc0d1f14ea64c (diff) | |
| download | bcm5719-llvm-a260c030b85b72a3efa5179239e11933b02ef37a.tar.gz bcm5719-llvm-a260c030b85b72a3efa5179239e11933b02ef37a.zip | |
Add an assert to ParamCommandComment::getParamIndex() -- it should not be
called unless index is valid.
llvm-svn: 160970
| -rw-r--r-- | clang/include/clang/AST/Comment.h | 1 | ||||
| -rw-r--r-- | clang/tools/libclang/CXComment.cpp | 15 |
2 files changed, 12 insertions, 4 deletions
diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 55cb08141a9..4c20618ca17 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -713,6 +713,7 @@ public: } unsigned getParamIndex() const LLVM_READONLY { + assert(isParamIndexValid()); return ParamIndex; } diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp index dfa782005b3..4189b31446a 100644 --- a/clang/tools/libclang/CXComment.cpp +++ b/clang/tools/libclang/CXComment.cpp @@ -256,7 +256,7 @@ unsigned clang_ParamCommandComment_isParamIndexValid(CXComment CXC) { 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 @@ namespace { 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; } }; |

