diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2014-01-27 17:55:43 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2014-01-27 17:55:43 +0000 |
commit | 6bf8f803f21c1603731ac7fc3064dc3a1ef7a698 (patch) | |
tree | b2cee54e02497d02a7f3822c5c5e25d20a16e020 /clang/lib/AST/CommentSema.cpp | |
parent | 73afb432135a59570a6b07d34ce20e59805e00ae (diff) | |
download | bcm5719-llvm-6bf8f803f21c1603731ac7fc3064dc3a1ef7a698.tar.gz bcm5719-llvm-6bf8f803f21c1603731ac7fc3064dc3a1ef7a698.zip |
Comment parsing: don't crash while parsing \deprecated in a standalone comment
(comment without a decl).
I think this can not happen during normal compilation with -Wdocumentation,
only while using Clang APIs to parse comments outside of a source file.
Based on a patch by Olivier Goffart.
llvm-svn: 200230
Diffstat (limited to 'clang/lib/AST/CommentSema.cpp')
-rw-r--r-- | clang/lib/AST/CommentSema.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 450325f91dc..0ae00820fde 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -68,8 +68,12 @@ void Sema::actOnBlockCommandFinish(BlockCommandComment *Command, Command->setParagraph(Paragraph); checkBlockCommandEmptyParagraph(Command); checkBlockCommandDuplicate(Command); - checkReturnsCommand(Command); - checkDeprecatedCommand(Command); + if (ThisDeclInfo) { + // These checks only make sense if the comment is attached to a + // declaration. + checkReturnsCommand(Command); + checkDeprecatedCommand(Command); + } } ParamCommandComment *Sema::actOnParamCommandStart( @@ -558,6 +562,9 @@ void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) { void Sema::checkReturnsCommand(const BlockCommandComment *Command) { if (!Traits.getCommandInfo(Command->getCommandID())->IsReturnsCommand) return; + + assert(ThisDeclInfo && "should not call this check on a bare comment"); + if (isFunctionDecl()) { if (ThisDeclInfo->ReturnType->isVoidType()) { unsigned DiagKind; @@ -636,6 +643,8 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) { if (!Traits.getCommandInfo(Command->getCommandID())->IsDeprecatedCommand) return; + assert(ThisDeclInfo && "should not call this check on a bare comment"); + const Decl *D = ThisDeclInfo->CommentDecl; if (!D) return; |