This revision was automatically updated to reflect the committed changes. Closed by commit rG29a4239d31c6: [Sema] Fix a crash when attaching comments to an implicit decl (authored by erik.pilkington). Herald added a project: clang.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75483/new/ https://reviews.llvm.org/D75483 Files: clang/lib/AST/ASTContext.cpp clang/test/Sema/warn-documentation.m Index: clang/test/Sema/warn-documentation.m =================================================================== --- clang/test/Sema/warn-documentation.m +++ clang/test/Sema/warn-documentation.m @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s +// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s @class NSString; @@ -318,3 +319,10 @@ // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} VoidBlockTypeCall ^e; ///< \return none // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +#ifdef __cplusplus +@interface HasAnonNamespace @end +@implementation HasAnonNamespace +namespace {} +@end +#endif Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -474,10 +474,20 @@ if (Comments.empty() || Decls.empty()) return; - // See if there are any new comments that are not attached to a decl. - // The location doesn't have to be precise - we care only about the file. - const FileID File = - SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first; + FileID File; + for (Decl *D : Decls) { + SourceLocation Loc = D->getLocation(); + if (Loc.isValid()) { + // See if there are any new comments that are not attached to a decl. + // The location doesn't have to be precise - we care only about the file. + File = SourceMgr.getDecomposedLoc(Loc).first; + break; + } + } + + if (File.isInvalid()) + return; + auto CommentsInThisFile = Comments.getCommentsInFile(File); if (!CommentsInThisFile || CommentsInThisFile->empty() || CommentsInThisFile->rbegin()->second->isAttached())
Index: clang/test/Sema/warn-documentation.m =================================================================== --- clang/test/Sema/warn-documentation.m +++ clang/test/Sema/warn-documentation.m @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s +// RUN: %clang_cc1 -xobjective-c++ -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s @class NSString; @@ -318,3 +319,10 @@ // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} VoidBlockTypeCall ^e; ///< \return none // expected-warning@-1 {{'\return' command used in a comment that is not attached to a function or method declaration}} + +#ifdef __cplusplus +@interface HasAnonNamespace @end +@implementation HasAnonNamespace +namespace {} +@end +#endif Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -474,10 +474,20 @@ if (Comments.empty() || Decls.empty()) return; - // See if there are any new comments that are not attached to a decl. - // The location doesn't have to be precise - we care only about the file. - const FileID File = - SourceMgr.getDecomposedLoc((*Decls.begin())->getLocation()).first; + FileID File; + for (Decl *D : Decls) { + SourceLocation Loc = D->getLocation(); + if (Loc.isValid()) { + // See if there are any new comments that are not attached to a decl. + // The location doesn't have to be precise - we care only about the file. + File = SourceMgr.getDecomposedLoc(Loc).first; + break; + } + } + + if (File.isInvalid()) + return; + auto CommentsInThisFile = Comments.getCommentsInFile(File); if (!CommentsInThisFile || CommentsInThisFile->empty() || CommentsInThisFile->rbegin()->second->isAttached())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits