stephanemoore updated this revision to Diff 475222. stephanemoore added a subscriber: Eugene.Zelenko. stephanemoore added a comment.
Included namespace comment linter fixes from D137740 <https://reviews.llvm.org/D137740> as advised by @Eugene.Zelenko, Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D137738/new/ https://reviews.llvm.org/D137738 Files: clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m
Index: clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m +++ clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m @@ -1,4 +1,5 @@ -// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t +// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t -- -- -I %S/Inputs/ + @class NSString; @interface NSException @@ -21,12 +22,29 @@ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception] } +#include "system-header-throw.h" + +#define THROW(e) @throw e + +#define RAISE [NSException raise:@"example" format:@"fmt"] + - (void)f2 { [NSException raise:@"TestException" format:@"Test"]; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception] [NSException raise:@"TestException" format:@"Test %@" arguments:@"bar"]; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception] [NotException raise:@"NotException" format:@"Test"]; + + NSException *e; + SYS_THROW(e); + + SYS_RAISE; + + THROW(e); + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception] + + RAISE; + // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception] } @end Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h @@ -0,0 +1,6 @@ +#pragma clang system_header + +#define SYS_THROW(e) @throw e + +#define SYS_RAISE [NSException raise:@"example" format:@"fmt"] + Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -141,6 +141,10 @@ would be emitted for uninitialized members of an anonymous union despite there being an initializer for one of the other members. +- Fixed false positives in :doc:`google-objc-avoid-throwing-exception + <clang-tidy/checks/google/objc-avoid-throwing-exception>` check for exceptions + thrown by code emitted from macros in system headers. + - Improved :doc:`modernize-use-emplace <clang-tidy/checks/modernize/use-emplace>` check. Index: clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp +++ clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp @@ -36,12 +36,28 @@ Result.Nodes.getNodeAs<ObjCMessageExpr>("raiseException"); auto SourceLoc = MatchedStmt == nullptr ? MatchedExpr->getSelectorStartLoc() : MatchedStmt->getThrowLoc(); + + // Early return on invalid locations. + if (SourceLoc.isInvalid()) + return; + + // If the match location was in a macro, check if the macro was in a system + // header. + if (SourceLoc.isMacroID()) { + SourceManager &SM = *Result.SourceManager; + auto MacroLoc = SM.getImmediateMacroCallerLoc(SourceLoc); + + // Matches in system header macros should be ignored. + if (SM.isInSystemHeader(MacroLoc)) + return; + } + diag(SourceLoc, "pass in NSError ** instead of throwing exception to indicate " "Objective-C errors"); } -} // namespace objc -} // namespace google -} // namespace tidy -} // namespace clang +} // namespace objc +} // namespace google +} // namespace tidy +} // namespace clang
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits