PaulkaToast updated this revision to Diff 248882. PaulkaToast marked 5 inline comments as done. PaulkaToast added a comment.
Thanks for the heads up phosek, I removed the check from fuchsia's directory. Also addressed Eurgene.Zelenko's comments. (: Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75786/new/ https://reviews.llvm.org/D75786 Files: clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h clang-tools-extra/clang-tidy/portability/CMakeLists.txt clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/a.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/j.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/s.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/t.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/r.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/s.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/t.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/transitive.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/transitive2.h clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp +++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp @@ -1,11 +1,11 @@ // RUN: rm -rf %T/Headers // RUN: mkdir %T/Headers -// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Headers/fuchsia-restrict-system-includes -// RUN: %check_clang_tidy -std=c++11 %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \ +// RUN: cp -r %S/Inputs/portability-restrict-system-includes %T/Headers/portability-restrict-system-includes +// RUN: %check_clang_tidy -std=c++11 %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \ // RUN: -system-headers -header-filter=.* \ -// RUN: -- -I %T/Headers/fuchsia-restrict-system-includes -isystem %T/Headers/fuchsia-restrict-system-includes/system -// RUN: FileCheck -input-file=%T/Headers/fuchsia-restrict-system-includes/transitive2.h %s -check-prefix=CHECK-FIXES +// RUN: -- -I %T/Headers/portability-restrict-system-includes -isystem %T/Headers/portability-restrict-system-includes/system +// RUN: FileCheck -input-file=%T/Headers/portability-restrict-system-includes/transitive2.h %s -check-prefix=CHECK-FIXES // RUN: rm -rf %T/Headers // FIXME: Make the test work in all language modes. Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" + +// Test glob functionality: disallow all headers except those that match +// pattern "std*.h". + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,stdio.h'}]}" + +// Test allow-list functionality: disallow all but stdio.h. + +#include <stdio.h> +#include <stdlib.h> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed +#include <string.h> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed Index: clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp @@ -0,0 +1,9 @@ +// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stdio.h'}]}" + +// Test block-list functionality: allow all but stdio.h. + +#include <stdio.h> +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed +#include <stdlib.h> +#include <string.h> Index: clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \ -// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system - -#include "a.h" - -#include <s.h> -#include <t.h> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed -// CHECK-FIXES-NOT: #include <t.h> - -#include "s.h" -#include "t.h" -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed -// CHECK-FIXES-NOT: #include "t.h" - -#define foo <j.h> - -#include foo -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed -// CHECK-FIXES-NOT: #include foo - -#/* comment */ include /* comment */ foo -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed -// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo Index: clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'cstd*'}]}" \ -// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system - -#include <cstdlib.h> -#include <cstdarg.h> -#include <t.h> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed -// CHECK-FIXES-NOT: #include <t.h> Index: clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: ''}]}" \ -// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system - -#include <cstdlib.h> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include cstdlib.h not allowed -#include <cstdarg.h> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include cstdarg.h not allowed -#include <t.h> -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h @@ -1,2 +0,0 @@ -#include <s.h> -#include <t.h> Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h @@ -1,3 +0,0 @@ -#include <r.h> -#include <t.h> -#include <s.h> Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h @@ -1 +0,0 @@ -void f() {} Index: clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst =================================================================== --- /dev/null +++ clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst @@ -0,0 +1,51 @@ +.. title:: clang-tidy - portability-restrict-system-includes + +portability-restrict-system-includes +==================================== + +Checks to selectively allow or disallow a configurable list of system headers. + +For example: + +In order to **only** allow `zlib.h` from the system you would set the options +to `-*,zlib.h`. + +.. code-block:: c++ + + #include <curses.h> // Bad: disallowed system header. + #include <openssl/ssl.h> // Bad: disallowed system header. + #include <zlib.h> // Good: allowed system header. + #include "src/myfile.h" // Good: non-system header always allowed. + +In order to allow everything **except** `zlib.h` from the system you would set +the options to `*,-zlib.h`. + +.. code-block:: c++ + + #include <curses.h> // Good: allowed system header. + #include <openssl/ssl.h> // Good: allowed system header. + #include <zlib.h> // Bad: disallowed system header. + #include "src/myfile.h" // Good: non-system header always allowed. + +Since the opions support globbing you can use wildcarding to allow groups of +headers. + +`-*,openssl/*.h` will allow all openssl headers but disallow any others. + +.. code-block:: c++ + + #include <curses.h> // Bad: disallowed system header. + #include <openssl/ssl.h> // Good: allowed system header. + #include <openssl/rsa.h> // Good: allowed system header. + #include <zlib.h> // Bad: disallowed system header. + #include "src/myfile.h" // Good: non-system header always allowed. + +Options +------- + +.. option:: Includes + + A string containing a comma separated glob list of allowed include + filenames. Similar to the -checks glob list for running clang-tidy itself, + the two wildcard characters are `*` and `-`, to include and exclude globs, + respectively. The default is `*`, which allows all includes. Index: clang-tools-extra/docs/clang-tidy/checks/list.rst =================================================================== --- clang-tools-extra/docs/clang-tidy/checks/list.rst +++ clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -154,7 +154,6 @@ `fuchsia-default-arguments-declarations <fuchsia-default-arguments-declarations.html>`_, "Yes" `fuchsia-multiple-inheritance <fuchsia-multiple-inheritance.html>`_, `fuchsia-overloaded-operator <fuchsia-overloaded-operator.html>`_, - `fuchsia-restrict-system-includes <fuchsia-restrict-system-includes.html>`_, "Yes" `fuchsia-statically-constructed-objects <fuchsia-statically-constructed-objects.html>`_, `fuchsia-trailing-return <fuchsia-trailing-return.html>`_, `fuchsia-virtual-inheritance <fuchsia-virtual-inheritance.html>`_, @@ -255,6 +254,7 @@ `performance-type-promotion-in-math-fn <performance-type-promotion-in-math-fn.html>`_, "Yes" `performance-unnecessary-copy-initialization <performance-unnecessary-copy-initialization.html>`_, `performance-unnecessary-value-param <performance-unnecessary-value-param.html>`_, "Yes" + `portability-restrict-system-includes <portability-restrict-system-includes.html>`_, "Yes" `portability-simd-intrinsics <portability-simd-intrinsics.html>`_, `readability-avoid-const-params-in-decls <readability-avoid-const-params-in-decls.html>`_, `readability-braces-around-statements <readability-braces-around-statements.html>`_, "Yes" Index: clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst =================================================================== --- clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. title:: clang-tidy - fuchsia-restrict-system-includes - -fuchsia-restrict-system-includes -================================ - -Checks for allowed system includes and suggests removal of any others. - -It is important to note that running this check with fixes may break code, as -the fix removes headers. Fixes are applied to source and header files, but not -to system headers. - -For example, given the allowed system includes 'a.h,b*': - -.. code-block:: c++ - - #include <a.h> - #include <b.h> - #include <bar.h> - #include <c.h> // Warning, as c.h is not explicitly allowed - -All system includes can be allowed with '*', and all can be disallowed with an -empty string (''). - -Options -------- - -.. option:: Includes - - A string containing a comma separated glob list of allowed include filenames. - Similar to the -checks glob list for running clang-tidy itself, the two - wildcard characters are '*' and '-', to include and exclude globs, - respectively.The default is '*', which allows all includes. Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -127,6 +127,8 @@ Renamed checks ^^^^^^^^^^^^^^ +- The 'fuchsia-restrict-system-headers' check was renamed to :doc:`portability-restrict-system-includes + <clang-tidy/checks/portability-restrict-system-includes> Improvements to include-fixer ----------------------------- Index: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h =================================================================== --- clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h +++ clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -1,4 +1,4 @@ -//===--- RestrictSystemIncludesCheck.h - clang-tidy---------- ----*- C++-*-===// +//===--- RestrictSystemIncludesCheck.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. @@ -6,21 +6,21 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H #include "../ClangTidyCheck.h" #include "../GlobList.h" namespace clang { namespace tidy { -namespace fuchsia { +namespace portability { /// Checks for allowed includes and suggests removal of any others. If no /// includes are specified, the check will exit without issuing any warnings. /// /// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html +/// http://clang.llvm.org/extra/clang-tidy/checks/portability-restrict-system-includes.html class RestrictSystemIncludesCheck : public ClangTidyCheck { public: RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context) @@ -40,8 +40,8 @@ GlobList AllowedIncludesGlobList; }; -} // namespace fuchsia +} // namespace portability } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H \ No newline at end of file Index: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp +++ clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -1,4 +1,4 @@ -//===--- RestrictSystemIncludesCheck.cpp - clang-tidy----------------------===// +//===--- RestrictSystemIncludesCheck.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. @@ -18,7 +18,7 @@ namespace clang { namespace tidy { -namespace fuchsia { +namespace portability { class RestrictedIncludesPPCallbacks : public PPCallbacks { public: @@ -111,6 +111,6 @@ Options.store(Opts, "Includes", AllowedIncludes); } -} // namespace fuchsia +} // namespace portability } // namespace tidy } // namespace clang Index: clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp =================================================================== --- clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp +++ clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -9,6 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" +#include "RestrictSystemIncludesCheck.h" #include "SIMDIntrinsicsCheck.h" namespace clang { @@ -18,6 +19,8 @@ class PortabilityModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<RestrictSystemIncludesCheck>( + "portability-restrict-system-includes"); CheckFactories.registerCheck<SIMDIntrinsicsCheck>( "portability-simd-intrinsics"); } Index: clang-tools-extra/clang-tidy/portability/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/portability/CMakeLists.txt +++ clang-tools-extra/clang-tidy/portability/CMakeLists.txt @@ -2,6 +2,7 @@ add_clang_library(clangTidyPortabilityModule PortabilityTidyModule.cpp + RestrictSystemIncludesCheck.cpp SIMDIntrinsicsCheck.cpp LINK_LIBS Index: clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp =================================================================== --- clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -14,7 +14,6 @@ #include "DefaultArgumentsDeclarationsCheck.h" #include "MultipleInheritanceCheck.h" #include "OverloadedOperatorCheck.h" -#include "RestrictSystemIncludesCheck.h" #include "StaticallyConstructedObjectsCheck.h" #include "TrailingReturnCheck.h" #include "VirtualInheritanceCheck.h" @@ -39,8 +38,6 @@ "fuchsia-multiple-inheritance"); CheckFactories.registerCheck<OverloadedOperatorCheck>( "fuchsia-overloaded-operator"); - CheckFactories.registerCheck<RestrictSystemIncludesCheck>( - "fuchsia-restrict-system-includes"); CheckFactories.registerCheck<StaticallyConstructedObjectsCheck>( "fuchsia-statically-constructed-objects"); CheckFactories.registerCheck<TrailingReturnCheck>( Index: clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt +++ clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt @@ -6,7 +6,6 @@ FuchsiaTidyModule.cpp MultipleInheritanceCheck.cpp OverloadedOperatorCheck.cpp - RestrictSystemIncludesCheck.cpp StaticallyConstructedObjectsCheck.cpp TrailingReturnCheck.cpp VirtualInheritanceCheck.cpp
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits