From b740316a122b5ceaaa7cf50557b1b39af5fbbf5f Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Mon, 30 Jul 2012 17:38:19 +0000 Subject: [PATCH] Add an assert to ParamCommandComment::getParamIndex() -- it should not be called unless index is valid. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160970 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Comment.h | 1 + tools/libclang/CXComment.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/clang/AST/Comment.h b/include/clang/AST/Comment.h index 55cb08141a..4c20618ca1 100644 --- a/include/clang/AST/Comment.h +++ b/include/clang/AST/Comment.h @@ -713,6 +713,7 @@ public: } unsigned getParamIndex() const LLVM_READONLY { + assert(isParamIndexValid()); return ParamIndex; } diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index dfa782005b..4189b31446 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -256,7 +256,7 @@ unsigned clang_ParamCommandComment_isParamIndexValid(CXComment CXC) { unsigned clang_ParamCommandComment_getParamIndex(CXComment CXC) { const ParamCommandComment *PCC = getASTNodeAs(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; } }; -- 2.40.0