[clang-tools-extra] r351922 - Revert rCTE351921 to fix documentation geneeration.
Author: stephanemoore Date: Tue Jan 22 18:58:59 2019 New Revision: 351922 URL: http://llvm.org/viewvc/llvm-project?rev=351922&view=rev Log: Revert rCTE351921 to fix documentation geneeration. Original review: https://reviews.llvm.org/D56945 Modified: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.h clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst Modified: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp?rev=351922&r1=351921&r2=351922&view=diff == --- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp Tue Jan 22 18:58:59 2019 @@ -97,6 +97,14 @@ bool prefixedPropertyNameValid(llvm::Str } } // namespace +PropertyDeclarationCheck::PropertyDeclarationCheck(StringRef Name, + ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + SpecialAcronyms( + utils::options::parseStringList(Options.get("Acronyms", ""))), + IncludeDefaultAcronyms(Options.get("IncludeDefaultAcronyms", true)), + EscapedAcronyms() {} + void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) { // this check should only be applied to ObjC sources. if (!getLangOpts().ObjC) return; @@ -137,6 +145,12 @@ void PropertyDeclarationCheck::check(con << generateFixItHint(MatchedDecl, StandardProperty); } +void PropertyDeclarationCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "Acronyms", +utils::options::serializeStringList(SpecialAcronyms)); + Options.store(Opts, "IncludeDefaultAcronyms", IncludeDefaultAcronyms); +} + } // namespace objc } // namespace tidy } // namespace clang Modified: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.h?rev=351922&r1=351921&r2=351922&view=diff == --- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.h Tue Jan 22 18:58:59 2019 @@ -10,6 +10,8 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_PROPERTY_DECLARATION_H #include "../ClangTidy.h" +#include +#include namespace clang { namespace tidy { @@ -25,10 +27,15 @@ namespace objc { /// http://clang.llvm.org/extra/clang-tidy/checks/objc-property-declaration.html class PropertyDeclarationCheck : public ClangTidyCheck { public: - PropertyDeclarationCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} + PropertyDeclarationCheck(StringRef Name, ClangTidyContext *Context); void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + void storeOptions(ClangTidyOptions::OptionMap &Options) override; + +private: + const std::vector SpecialAcronyms; + const bool IncludeDefaultAcronyms; + std::vector EscapedAcronyms; }; } // namespace objc Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=351922&r1=351921&r2=351922&view=diff == --- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original) +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Jan 22 18:58:59 2019 @@ -73,10 +73,6 @@ Improvements to clang-tidy Checks for casts of ``absl::Duration`` conversion functions, and recommends the right conversion function instead. -- The :option:`Acronyms` and :option:`IncludeDefaultAcronyms` options for the - :doc:`objc-property-declaration ` - check have been removed. - Improvements to include-fixer - Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst?rev=351922&r1=351921&r2=351922&view=diff == --- clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst Tue Jan 22 18:58:59 2019 @@ -40,3 +40,15 @@ lowercase letters followed by a '_' to a @property(nonatomic, assign) int abc_lowerCamelCase; The corresponding style rule: https://deve
[clang-tools-extra] r347000 - [clang-tidy] Fix reference to -[NSError init] in AvoidNSErrorInitCheck.h
Author: stephanemoore Date: Thu Nov 15 14:38:39 2018 New Revision: 347000 URL: http://llvm.org/viewvc/llvm-project?rev=347000&view=rev Log: [clang-tidy] Fix reference to -[NSError init] in AvoidNSErrorInitCheck.h Modified: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h Modified: clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h?rev=347000&r1=346999&r2=347000&view=diff == --- clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/objc/AvoidNSErrorInitCheck.h Thu Nov 15 14:38:39 2018 @@ -16,7 +16,7 @@ namespace clang { namespace tidy { namespace objc { -/// Finds usages of [NSSError init]. It is not the proper way of creating +/// Finds usages of -[NSError init]. It is not the proper way of creating /// NSError. errorWithDomain:code:userInfo: should be used instead. /// /// For the user-facing documentation see: ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D59336: [clang-tidy] Disable google-runtime-int in Objective-C++ 🔓
I was uncertain whether or not this change required new tests. A previous change which disabled this check in languages other than C++ did not include additional tests: https://github.com/llvm/llvm-project/commit/ec3e5d6fd87862eb77a2b0320d79b9a4427d39df#diff-a491be84e1b831aeaea56c39b5eb898c If there is a preference to add tests for this change, I can do so. On Wed, Mar 13, 2019 at 3:21 PM Roman Lebedev wrote: > test? > > On Thu, Mar 14, 2019 at 1:17 AM Stephane Moore via Phabricator via > cfe-commits wrote: > > > > stephanemoore created this revision. > > Herald added subscribers: cfe-commits, jdoerfert, xazax.hun. > > Herald added a project: clang. > > > > In contrast to Google C++, Objective-C often uses built-in integer types > > other than `int`. In fact, the Objective-C runtime itself defines the > > types NSInteger¹ and NSUInteger² which are variant types depending on > > the target architecture. The Objective-C style guide indicates that > > usage of system types with variant sizes is appropriate when handling > > values provided by system interfaces³. Objective-C++ is commonly the > > result of conversion from Objective-C to Objective-C++ for the purpose > > of integrating C++ functionality. The opposite of Objective-C++ being > > used to expose Objective-C functionality to C++ is less common, > > potentially because Objective-C has a signficantly more uneven presence > > on different platforms compared to C++. This generally predisposes > > Objective-C++ to commonly being more Objective-C than C++. Forcing > > Objective-C++ developers to perform conversions between variant system > types > > and fixed size integer types depending on target architecture when > > Objective-C++ commonly uses variant system types from Objective-C is > > likely to lead to more bugs and overhead than benefit. For that reason, > > this change proposes to disable google-runtime-int in Objective-C++. > > > > [1] > https://developer.apple.com/documentation/objectivec/nsinteger?language=objc > > [2] > https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc > > [3] "Types long, NSInteger, NSUInteger, and CGFloat vary in size between > > 32- and 64-bit builds. Use of these types is appropriate when handling > > values exposed by system interfaces, but they should be avoided for most > > other computations." > > > https://github.com/google/styleguide/blob/gh-pages/objcguide.md#types-with-inconsistent-sizes > > > > > > Repository: > > rG LLVM Github Monorepo > > > > https://reviews.llvm.org/D59336 > > > > Files: > > clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp > > > > > > Index: clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp > > === > > --- clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp > > +++ clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp > > @@ -54,7 +54,9 @@ > > > > void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) { > >// Find all TypeLocs. The relevant Style Guide rule only applies to > C++. > > - if (!getLangOpts().CPlusPlus) > > + // This check is also not applied in Objective-C++ sources as > Objective-C > > + // often uses built-in integer types other than `int`. > > + if (!getLangOpts().CPlusPlus || getLangOpts().ObjC) > > return; > >// Match any integer types, unless they are passed to a printf-based > API: > >// > > > > > > ___ > > cfe-commits mailing list > > cfe-commits@lists.llvm.org > > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r362279 - Revise the google-objc-global-variable-declaration check to match the style guide.
Author: stephanemoore Date: Fri May 31 16:41:15 2019 New Revision: 362279 URL: http://llvm.org/viewvc/llvm-project?rev=362279&view=rev Log: Revise the google-objc-global-variable-declaration check to match the style guide. Summary: Revise the google-objc-global-variable-declaration check to match the style guide. This commit updates the check as follows: (1) Do not emit fixes for extern global constants. (2) Allow the second character of prefixes for constants to be numeric (the new guideline is that global constants should generally be named with a prefix that begins with a capital letter followed by one or more capital letters or numbers). https://google.github.io/styleguide/objcguide.html#prefixes This is an amended re-submission of https://reviews.llvm.org/rG12e3726fadb0b2a4d8aeed0a2817b5159f9d029d. Contributed By: yaqiji Reviewers: Wizard, benhamilton, stephanemoore Reviewed By: benhamilton, stephanemoore Subscribers: mgorny, cfe-commits, yaqiji Tags: #clang Differential Revision: https://reviews.llvm.org/D62045 Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp?rev=362279&r1=362278&r2=362279&view=diff == --- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp Fri May 31 16:41:15 2019 @@ -23,29 +23,35 @@ namespace objc { namespace { -AST_MATCHER(VarDecl, isLocalVariable) { - return Node.isLocalVarDecl(); -} +AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); } FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) { + if (IsConst && (Decl->getStorageClass() != SC_Static)) { +// No fix available if it is not a static constant, since it is difficult +// to determine the proper fix in this case. +return FixItHint(); + } + char FC = Decl->getName()[0]; if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) { // No fix available if first character is not alphabetical character, or it -// is a single-character variable, since it is difficult to determine the +// is a single-character variable, since it is difficult to determine the // proper fix in this case. Users should create a proper variable name by // their own. return FixItHint(); } char SC = Decl->getName()[1]; if ((FC == 'k' || FC == 'g') && !llvm::isAlpha(SC)) { -// No fix available if the prefix is correct but the second character is not -// alphabetical, since it is difficult to determine the proper fix in this -// case. +// No fix available if the prefix is correct but the second character is +// not alphabetical, since it is difficult to determine the proper fix in +// this case. return FixItHint(); } + auto NewName = (IsConst ? "k" : "g") + llvm::StringRef(std::string(1, FC)).upper() + Decl->getName().substr(1).str(); + return FixItHint::CreateReplacement( CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())), llvm::StringRef(NewName)); @@ -71,7 +77,7 @@ void GlobalVariableDeclarationCheck::reg this); Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()), unless(isLocalVariable()), - unless(matchesName("::(k[A-Z]|[A-Z]{2,})"))) + unless(matchesName("::(k[A-Z])|([A-Z][A-Z0-9])"))) .bind("global_const"), this); } Modified: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m?rev=362279&r1=362278&r2=362279&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m (original) +++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m Fri May 31 16:41:15 2019 @@ -1,10 +1,14 @@ // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t @class NSString; + static NSString* const myConstString = @"hello"; // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration] // CHECK-FIXES: static NSString* const kMyConstString = @"hello"; +extern NSString* const GlobalConstant = @"hey"; +// CHECK-MESSAGES: :[[@LINE-1]]:24: warnin
[clang-tools-extra] r361907 - Revise the google-objc-global-variable-declaration check to match the style guide.
Author: stephanemoore Date: Tue May 28 18:36:23 2019 New Revision: 361907 URL: http://llvm.org/viewvc/llvm-project?rev=361907&view=rev Log: Revise the google-objc-global-variable-declaration check to match the style guide. Summary: Revise the google-objc-global-variable-declaration check to match the style guide. This commit updates the check as follows: (1) Do not emit fixes for extern global constants. (2) Allow the second character of prefixes for constants to be numeric (the new guideline is that global constants should generally be named with a prefix that begins with a capital letter followed by one or more capital letters or numbers). https://google.github.io/styleguide/objcguide.html#prefixes Contributed by yaqiji. Reviewers: Wizard, benhamilton, stephanemoore Reviewed By: benhamilton, stephanemoore Subscribers: mgorny, cfe-commits, yaqiji Tags: #clang Differential Revision: https://reviews.llvm.org/D62045 Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp?rev=361907&r1=361906&r2=361907&view=diff == --- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp Tue May 28 18:36:23 2019 @@ -23,29 +23,35 @@ namespace objc { namespace { -AST_MATCHER(VarDecl, isLocalVariable) { - return Node.isLocalVarDecl(); -} +AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); } FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) { + if (IsConst && (Decl->getStorageClass() != SC_Static)) { +// No fix available if it is not a static constant, since it is difficult +// to determine the proper fix in this case. +return FixItHint(); + } + char FC = Decl->getName()[0]; if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) { // No fix available if first character is not alphabetical character, or it -// is a single-character variable, since it is difficult to determine the +// is a single-character variable, since it is difficult to determine the // proper fix in this case. Users should create a proper variable name by // their own. return FixItHint(); } char SC = Decl->getName()[1]; if ((FC == 'k' || FC == 'g') && !llvm::isAlpha(SC)) { -// No fix available if the prefix is correct but the second character is not -// alphabetical, since it is difficult to determine the proper fix in this -// case. +// No fix available if the prefix is correct but the second character is +// not alphabetical, since it is difficult to determine the proper fix in +// this case. return FixItHint(); } + auto NewName = (IsConst ? "k" : "g") + llvm::StringRef(std::string(1, FC)).upper() + Decl->getName().substr(1).str(); + return FixItHint::CreateReplacement( CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())), llvm::StringRef(NewName)); @@ -71,7 +77,7 @@ void GlobalVariableDeclarationCheck::reg this); Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()), unless(isLocalVariable()), - unless(matchesName("::(k[A-Z]|[A-Z]{2,})"))) + unless(matchesName("::(k[A-Z])|([A-Z][A-Z0-9])"))) .bind("global_const"), this); } Modified: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m?rev=361907&r1=361906&r2=361907&view=diff == --- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m (original) +++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.m Tue May 28 18:36:23 2019 @@ -1,10 +1,14 @@ // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t @class NSString; + static NSString* const myConstString = @"hello"; // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration] // CHECK-FIXES: static NSString* const kMyConstString = @"hello"; +extern NSString* const GlobalConstant = @"hey"; +// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'GlobalConstant' must have a name which starts with an appropriate prefix [googl
[clang-tools-extra] r373028 - [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage
Author: stephanemoore Date: Thu Sep 26 16:04:59 2019 New Revision: 373028 URL: http://llvm.org/viewvc/llvm-project?rev=373028&view=rev Log: [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage Summary: Creates a new darwin ClangTidy module and adds the darwin-dispatch-once-nonstatic check that warns about dispatch_once_t variables not in static or global storage. This catches a missing static for local variables in e.g. singleton initialization behavior, and also warns on storing dispatch_once_t values in Objective-C instance variables. C/C++ struct/class instances may potentially live in static/global storage, and are ignored for this check. The osx.API static analysis checker can find the non-static storage use of dispatch_once_t; I thought it useful to also catch this issue in clang-tidy when possible. Contributed By: mwyman Reviewers: benhamilton, hokein, stephanemoore, aaron.ballman, gribozavr Reviewed By: stephanemoore, gribozavr Subscribers: jkorous, arphaman, kadircet, usaxena95, NoQ, xazax.hun, lebedev.ri, mgorny, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D67567 Added: clang-tools-extra/trunk/clang-tidy/darwin/ clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp clang-tools-extra/trunk/clang-tidy/darwin/DispatchOnceNonstaticCheck.cpp clang-tools-extra/trunk/clang-tidy/darwin/DispatchOnceNonstaticCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-dispatch-once-nonstatic.rst clang-tools-extra/trunk/test/clang-tidy/darwin-dispatch-once-nonstatic.mm Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt clang-tools-extra/trunk/clangd/CMakeLists.txt clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=373028&r1=373027&r2=373028&view=diff == --- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Thu Sep 26 16:04:59 2019 @@ -43,6 +43,7 @@ add_subdirectory(boost) add_subdirectory(bugprone) add_subdirectory(cert) add_subdirectory(cppcoreguidelines) +add_subdirectory(darwin) add_subdirectory(fuchsia) add_subdirectory(google) add_subdirectory(hicpp) Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h?rev=373028&r1=373027&r2=373028&view=diff == --- clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h (original) +++ clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h Thu Sep 26 16:04:59 2019 @@ -50,6 +50,11 @@ extern volatile int CppCoreGuidelinesMod static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination = CppCoreGuidelinesModuleAnchorSource; +// This anchor is used to force the linker to link the DarwinModule. +extern volatile int DarwinModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination = +DarwinModuleAnchorSource; + // This anchor is used to force the linker to link the FuchsiaModule. extern volatile int FuchsiaModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination = Added: clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt?rev=373028&view=auto == --- clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt (added) +++ clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt Thu Sep 26 16:04:59 2019 @@ -0,0 +1,15 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyDarwinModule + DarwinTidyModule.cpp + DispatchOnceNonstaticCheck.cpp + + LINK_LIBS + clangAnalysis + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + clangTidyUtils + ) Added: clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp?rev=373028&view=auto == --- clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp (added) +++ clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp Thu Sep 26 16:04:59 2019 @@ -0,0 +1,37 @@ +//===--- MiscTidyModule.cpp - clang-tidy --
[clang-tools-extra] r373392 - [clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlock
Author: stephanemoore Date: Tue Oct 1 14:18:40 2019 New Revision: 373392 URL: http://llvm.org/viewvc/llvm-project?rev=373392&view=rev Log: [clang-tidy] Rename objc-avoid-spinlock check to darwin-avoid-spinlock Summary: OSSpinLock* are Apple/Darwin functions, but were previously located with ObjC checks as those were most closely tied to Apple platforms before. Now that there's a specific Darwin module, relocating the check there. This change was prepared by running rename_check.py. Contributed By: mwyman Reviewers: stephanemoore, dmaclach Reviewed By: stephanemoore Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang, #llvm Differential Revision: https://reviews.llvm.org/D68148 Added: clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/darwin-avoid-spinlock.rst clang-tools-extra/trunk/test/clang-tidy/darwin-avoid-spinlock.m Removed: clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.cpp clang-tools-extra/trunk/clang-tidy/objc/AvoidSpinlockCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/objc-avoid-spinlock.rst clang-tools-extra/trunk/test/clang-tidy/objc-avoid-spinlock.m Modified: clang-tools-extra/trunk/clang-tidy/darwin/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/darwin/DarwinTidyModule.cpp clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Added: clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp?rev=373392&view=auto == --- clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp (added) +++ clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.cpp Tue Oct 1 14:18:40 2019 @@ -0,0 +1,36 @@ +//===--- AvoidSpinlockCheck.cpp - clang-tidy---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "AvoidSpinlockCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace darwin { + +void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + callExpr(callee((functionDecl(hasAnyName( + "OSSpinlockLock", "OSSpinlockUnlock", "OSSpinlockTry") + .bind("spinlock"), + this); +} + +void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) { + const auto *MatchedExpr = Result.Nodes.getNodeAs("spinlock"); + diag(MatchedExpr->getBeginLoc(), + "use os_unfair_lock_lock() or dispatch queue APIs instead of the " + "deprecated OSSpinLock"); +} + +} // namespace darwin +} // namespace tidy +} // namespace clang Added: clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h?rev=373392&view=auto == --- clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h (added) +++ clang-tools-extra/trunk/clang-tidy/darwin/AvoidSpinlockCheck.h Tue Oct 1 14:18:40 2019 @@ -0,0 +1,35 @@ +//===--- AvoidSpinlockCheck.h - clang-tidy---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang { +namespace tidy { +namespace darwin { + +/// Finds usages of OSSpinlock, which is deprecated due to potential livelock +/// problems. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/darwin-avoid-spinlock.html +class AvoidSpinlockCheck : public ClangTidyCheck { + public: + AvoidSpinlockCheck(StringRef Name, ClangTidyContext *Context) + : ClangTidyCheck(Name, Context) {} + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // n
[clang-tools-extra] 6c21409 - [clang-tidy] Suppress google-objc-avoid-throwing-exception in system macros 🫢
Author: Stephane Moore Date: 2022-11-30T16:44:45-08:00 New Revision: 6c2140943cbe257c85f7121349c5bca950a26e0d URL: https://github.com/llvm/llvm-project/commit/6c2140943cbe257c85f7121349c5bca950a26e0d DIFF: https://github.com/llvm/llvm-project/commit/6c2140943cbe257c85f7121349c5bca950a26e0d.diff LOG: [clang-tidy] Suppress google-objc-avoid-throwing-exception in system macros 🫢 The google-objc-avoid-throwing-exception check enforces the Google Objective-C Style Guide's prohibition on throwing exceptions in user code but the check incorrectly triggers findings for code emitted from system headers. This commit suppresses any findings that do not have valid locations or are emitted from macros in system headers. Avoid Throwing Exceptions, Google Objective-C Style Guide: https://github.com/google/styleguide/blob/gh-pages/objcguide.md#avoid-throwing-exceptions Test Notes: Ran clang-tidy lit tests. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D137738 Added: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h Modified: clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m Removed: diff --git a/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp index 2263806fb6a7f..9205125e5ac1f 100644 --- a/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/AvoidThrowingObjCExceptionCheck.cpp @@ -36,6 +36,22 @@ void AvoidThrowingObjCExceptionCheck::check( Result.Nodes.getNodeAs("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"); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 44c3743549ef0..52346e5b75589 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -141,6 +141,10 @@ Changes in existing checks 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 + ` check for exceptions + thrown by code emitted from macros in system headers. + - Improved :doc:`modernize-use-emplace ` check. diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h b/clang-tools-extra/test/clang-tidy/checkers/google/Inputs/system-header-throw.h new file mode 100644 index 0..22d1bd45387b5 --- /dev/null +++ b/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"] + diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m b/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m index 7fa32e7a5aa59..c28bf6414bce6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m +++ b/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 @@ - (void)f { // 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"]; /
Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls
stephanemoore added a subscriber: stephanemoore. stephanemoore added a comment. I hope that it's not presumptuous of me to inquire but I was wondering if the intent of this patch is to optimize calls to RR methods (and alloc) in non-ARC code? Would I be correct in assuming that clang will already emit direct calls to relevant RR runtime functions when ARC is enabled? http://reviews.llvm.org/D14737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits