[clang-tools-extra] 00a5755 - [clang-tidy] Add check llvmlibc-implementation-in-namespace.
Author: Paula Toth Date: 2020-04-06T10:49:49-07:00 New Revision: 00a57558978d3e4f11d08bed486497a8674000e3 URL: https://github.com/llvm/llvm-project/commit/00a57558978d3e4f11d08bed486497a8674000e3 DIFF: https://github.com/llvm/llvm-project/commit/00a57558978d3e4f11d08bed486497a8674000e3.diff LOG: [clang-tidy] Add check llvmlibc-implementation-in-namespace. Summary: This check makes sure all llvm-libc implementations falls within the `__llvm_libc` namespace. Reviewers: alexfh, aaron.ballman, hokein, njames93 Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, libc-commits, mgorny, xazax.hun, MaskRay, cfe-commits, sivachandra Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D76818 Added: clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h clang-tools-extra/docs/clang-tidy/checks/llvmlibc-implementation-in-namespace.rst clang-tools-extra/test/clang-tidy/checkers/llvmlibc-implementation-in-namespace.cpp Modified: clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst Removed: diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt index cc213d35a572..15e80a734ad1 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_LINK_COMPONENTS support) add_clang_library(clangTidyLLVMLibcModule + ImplementationInNamespaceCheck.cpp LLVMLibcTidyModule.cpp RestrictSystemLibcHeadersCheck.cpp diff --git a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp new file mode 100644 index ..42b697076b35 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.cpp @@ -0,0 +1,49 @@ +//===--- ImplementationInNamespaceCheck.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 "ImplementationInNamespaceCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace llvm_libc { + +const static StringRef RequiredNamespace = "__llvm_libc"; +void ImplementationInNamespaceCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl())) + .bind("child_of_translation_unit"), + this); +} + +void ImplementationInNamespaceCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *MatchedDecl = + Result.Nodes.getNodeAs("child_of_translation_unit"); + if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation())) +return; + + if (const auto *NS = dyn_cast(MatchedDecl)) { +if (NS->getName() != RequiredNamespace) { + diag(NS->getLocation(), "'%0' needs to be the outermost namespace") + << RequiredNamespace; +} +return; + } + diag(MatchedDecl->getLocation(), + "declaration must be declared within the '%0' namespace") + << RequiredNamespace; + return; +} + +} // namespace llvm_libc +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h new file mode 100644 index ..dcd29b381a41 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvmlibc/ImplementationInNamespaceCheck.h @@ -0,0 +1,38 @@ +//===--- ImplementationInNamespaceCheck.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_LLVMLIBC_IMPLEMENTATIONINNAMESPACECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_IMPLEMENTATIONINNAMESPACECHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang { +namespace tidy { +namespace llvm_libc { + +/// Checks all llvm-libc implementation is within the correct namespace. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/llvmlibc-imple
[clang-tools-extra] 8683f5d - [clang-tidy] Add check callee-namespace.
Author: Paula Toth Date: 2020-04-28T17:22:23-07:00 New Revision: 8683f5de535274398a82ed0a2c9f05648dc43f41 URL: https://github.com/llvm/llvm-project/commit/8683f5de535274398a82ed0a2c9f05648dc43f41 DIFF: https://github.com/llvm/llvm-project/commit/8683f5de535274398a82ed0a2c9f05648dc43f41.diff LOG: [clang-tidy] Add check callee-namespace. Summary: This check will ensure that all calls to functions resolve to one inside the `__llvm_libc` namespace. This is done to ensure that if we include a public header then we don't accidentally call into the a function within the global namespace. Reviewers: aaron.ballman, njames93 Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits, sivachandra Tags: #clang-tools-extra, #libc-project, #clang Differential Revision: https://reviews.llvm.org/D78890 Added: clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h clang-tools-extra/docs/clang-tidy/checks/llvmlibc-callee-namespace.rst clang-tools-extra/test/clang-tidy/checkers/llvmlibc-callee-namespace.cpp Modified: clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst Removed: diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt index d7965e126b72..9d4edb2abf1a 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS ) add_clang_library(clangTidyLLVMLibcModule + CalleeNamespaceCheck.cpp ImplementationInNamespaceCheck.cpp LLVMLibcTidyModule.cpp RestrictSystemLibcHeadersCheck.cpp diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp new file mode 100644 index ..fbc6762a44e7 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.cpp @@ -0,0 +1,56 @@ +//===-- CalleeNamespaceCheck.cpp --===// +// +// 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 "CalleeNamespaceCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang { +namespace tidy { +namespace llvm_libc { + +// Gets the outermost namespace of a DeclContext, right under the Translation +// Unit. +const DeclContext *getOutermostNamespace(const DeclContext *Decl) { + const DeclContext *Parent = Decl->getParent(); + if (Parent && Parent->isTranslationUnit()) +return Decl; + return getOutermostNamespace(Parent); +} + +void CalleeNamespaceCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher( + declRefExpr(to(functionDecl().bind("func"))).bind("use-site"), this); +} + +void CalleeNamespaceCheck::check(const MatchFinder::MatchResult &Result) { + const auto *UsageSiteExpr = Result.Nodes.getNodeAs("use-site"); + const auto *FuncDecl = Result.Nodes.getNodeAs("func"); + + // Ignore compiler builtin functions. + if (FuncDecl->getBuiltinID() != 0) +return; + + // If the outermost namespace of the function is __llvm_libc, we're good. + const auto *NS = dyn_cast(getOutermostNamespace(FuncDecl)); + if (NS && NS->getName() == "__llvm_libc") +return; + + diag(UsageSiteExpr->getBeginLoc(), "%0 must resolve to a function declared " + "within the '__llvm_libc' namespace") + << FuncDecl; + + diag(FuncDecl->getLocation(), "resolves to this declaration", + clang::DiagnosticIDs::Note); +} + +} // namespace llvm_libc +} // namespace tidy +} // namespace clang diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h new file mode 100644 index ..b35c6011f088 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvmlibc/CalleeNamespaceCheck.h @@ -0,0 +1,38 @@ +//===-- CalleeNamespaceCheck.h --*- 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_LLVMLIBC_CALLEENAMESPACECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LL
[clang-tools-extra] 556b917 - [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes
Author: Paula Toth Date: 2020-03-20T15:53:05-07:00 New Revision: 556b917fffcfaa15ea11a277e1b0d87b8d13e0f1 URL: https://github.com/llvm/llvm-project/commit/556b917fffcfaa15ea11a277e1b0d87b8d13e0f1 DIFF: https://github.com/llvm/llvm-project/commit/556b917fffcfaa15ea11a277e1b0d87b8d13e0f1.diff LOG: [clang-tidy] Merge common code between llvmlibc-restrict-system-libc-headers and portability-restrict-system-includes Summary: Made llvmlibc::RestrictSystemLibcHeadersCheck a subclass of protability::RestrictSystemIncludesCheck to re-use common code between the two. This also adds the ability to white list linux development headers. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: mgorny, xazax.hun, MaskRay, cfe-commits, sivachandra Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D76395 Added: Modified: clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h clang-tools-extra/docs/clang-tidy/checks/list.rst clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp Removed: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt index c03d8b677f26..cc213d35a572 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt @@ -10,6 +10,7 @@ add_clang_library(clangTidyLLVMLibcModule clangBasic clangLex clangTidy + clangTidyPortabilityModule clangTidyUtils clangTooling ) diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp index 8a597c0b2a24..4a19b5359d4f 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp @@ -18,12 +18,14 @@ namespace llvm_libc { namespace { -class RestrictedIncludesPPCallbacks : public PPCallbacks { +class RestrictedIncludesPPCallbacks +: public portability::RestrictedIncludesPPCallbacks { public: explicit RestrictedIncludesPPCallbacks( RestrictSystemLibcHeadersCheck &Check, const SourceManager &SM, const SmallString<128> CompilerIncudeDir) - : Check(Check), SM(SM), CompilerIncudeDir(CompilerIncudeDir) {} + : portability::RestrictedIncludesPPCallbacks(Check, SM), +CompilerIncudeDir(CompilerIncudeDir) {} void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, @@ -33,8 +35,6 @@ class RestrictedIncludesPPCallbacks : public PPCallbacks { SrcMgr::CharacteristicKind FileType) override; private: - RestrictSystemLibcHeadersCheck &Check; - const SourceManager &SM; const SmallString<128> CompilerIncudeDir; }; @@ -45,18 +45,12 @@ void RestrictedIncludesPPCallbacks::InclusionDirective( bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { - if (SrcMgr::isSystem(FileType)) { -// Compiler provided headers are allowed (e.g stddef.h). -if (SearchPath == CompilerIncudeDir) return; -if (!SM.isInMainFile(HashLoc)) { - Check.diag( - HashLoc, - "system libc header %0 not allowed, transitively included from %1") - << FileName << SM.getFilename(HashLoc); -} else { - Check.diag(HashLoc, "system libc header %0 not allowed") << FileName; -} - } + // Compiler provided headers are allowed (e.g stddef.h). + if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir) +return; + portability::RestrictedIncludesPPCallbacks::InclusionDirective( + HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, + RelativePath, Imported, FileType); } void RestrictSystemLibcHeadersCheck::registerPPCallbacks( diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h index 3910a29a28e4..9eead7a22882 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/Rest
[clang-tools-extra] ebdb98f - [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use.
Author: Paula Toth Date: 2020-03-10T13:33:06-07:00 New Revision: ebdb98f254f632b506109b9d20c6e8e19697765f URL: https://github.com/llvm/llvm-project/commit/ebdb98f254f632b506109b9d20c6e8e19697765f DIFF: https://github.com/llvm/llvm-project/commit/ebdb98f254f632b506109b9d20c6e8e19697765f.diff LOG: [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use. Summary: Created a general check for restrict-system-includes under portability as recommend in the comments under D75332. I also fleshed out the user facing documentation to show examples for common use-cases such as allow-list, block-list, and wild carding. Removed fuchsia's check as per phosek sugguestion. Reviewers: aaron.ballman, phosek, alexfh, hokein, njames93 Reviewed By: phosek Subscribers: Eugene.Zelenko, mgorny, xazax.hun, phosek, cfe-commits, MaskRay Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D75786 Added: clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst 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/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 Modified: clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp clang-tools-extra/clang-tidy/portability/CMakeLists.txt clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst Removed: clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h clang-tools-extra/docs/clang-tidy/checks/fuchsia-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/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 diff --git a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt index 30b319e7e5aa..26e6719a6475 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt @@ -6,7 +6,6 @@ add_clang_library(clangTidyFuchsiaModule FuchsiaTidyModule.cpp MultipleInheritanceCheck.cpp OverloadedOperatorCheck.cpp - RestrictSystemIncludesCheck.cpp StaticallyConstructedObjectsCheck.cpp TrailingReturnC
[clang-tools-extra] ddfcda0 - [clang-tidy] Fix warning from my previous patch in ReleaseNotes.txt
Author: Paula Toth Date: 2020-03-10T14:01:23-07:00 New Revision: ddfcda0256ca231499614742cce1b66db056dc2a URL: https://github.com/llvm/llvm-project/commit/ddfcda0256ca231499614742cce1b66db056dc2a DIFF: https://github.com/llvm/llvm-project/commit/ddfcda0256ca231499614742cce1b66db056dc2a.diff LOG: [clang-tidy] Fix warning from my previous patch in ReleaseNotes.txt Added: Modified: clang-tools-extra/docs/ReleaseNotes.rst Removed: diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 68ca5f61a4fa..aa777ce50cf5 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -134,7 +134,7 @@ Renamed checks ^^ - The 'fuchsia-restrict-system-headers' check was renamed to :doc:`portability-restrict-system-includes - + ` Improvements to include-fixer - ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 54928ba - [clang-tidy] Use more widely available headers for protability-restrict-system-includes-check's test
Author: Paula Toth Date: 2020-03-10T16:54:11-07:00 New Revision: 54928ba0ec8355edbbdb31c7b01bb45eb2d384b6 URL: https://github.com/llvm/llvm-project/commit/54928ba0ec8355edbbdb31c7b01bb45eb2d384b6 DIFF: https://github.com/llvm/llvm-project/commit/54928ba0ec8355edbbdb31c7b01bb45eb2d384b6.diff LOG: [clang-tidy] Use more widely available headers for protability-restrict-system-includes-check's test Added: Modified: 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 Removed: diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp index faab977ad340..e3a9376a8638 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp @@ -1,9 +1,9 @@ // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stdio.h'}]}" +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}" -// Test block-list functionality: allow all but stdio.h. +// Test block-list functionality: allow all but stddef.h. -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed -#include -#include +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stddef.h not allowed +#include +#include diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp index 58c1d4396ee5..f73cbbfc816d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp @@ -1,10 +1,10 @@ // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,stdio.h'}]}" +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,stddef.h'}]}" -// Test allow-list functionality: disallow all but stdio.h. +// Test allow-list functionality: disallow all but stddef.h. -#include -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed +#include +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdint.h not allowed +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include float.h not allowed diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp index ccde9438d93c..bee7ec73438c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp @@ -4,7 +4,7 @@ // Test glob functionality: disallow all headers except those that match // pattern "std*.h". -#include -#include -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed +#include +#include +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include float.h not allowed ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] f1736f7 - [clang-tidy] Mock system headers for portability-restrict-system-includes tests.
Author: Paula Toth Date: 2020-03-11T12:13:27-07:00 New Revision: f1736f7a2a660944c24aac45e24cdf1ea6c6effa URL: https://github.com/llvm/llvm-project/commit/f1736f7a2a660944c24aac45e24cdf1ea6c6effa DIFF: https://github.com/llvm/llvm-project/commit/f1736f7a2a660944c24aac45e24cdf1ea6c6effa.diff LOG: [clang-tidy] Mock system headers for portability-restrict-system-includes tests. Summary: Didn't realize that headers such as stddef.h may not exist on all systems. This patch mocks the headers so that the check's tests work on all systems. (: Reviewers: RKSimon, aaron.ballman Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D76015 Added: clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/float.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stddef.h clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stdint.h Modified: 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 Removed: 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 diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/float.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/float.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h deleted file mode 100644 index e69de29bb2d1.. diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stddef.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stddef.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stdint.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/stdint.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp index e3a9376a8638..a74b94b604ac 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp @@ -1,5 +1,6 @@ // RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}" +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stddef.h'}]}" \ +// RUN: -- -isystem %S/Inputs/portability-restrict-system-includes/system // Test block-list functionality: allow all but stddef.h. diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp index f73cbbfc816d..1d1e8a4e6706 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp @@ -1,5 +1,6 @@ // RUN: %check_clang_tidy %s portability-restrict-system-inclu
[clang-tools-extra] eb41cc6 - [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.
Author: Paula Toth Date: 2020-03-12T11:46:05-07:00 New Revision: eb41cc619866ea3b12a30f734600ac86699ce05e URL: https://github.com/llvm/llvm-project/commit/eb41cc619866ea3b12a30f734600ac86699ce05e DIFF: https://github.com/llvm/llvm-project/commit/eb41cc619866ea3b12a30f734600ac86699ce05e.diff LOG: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check. Summary: This adds a new module to enforce standards specific to the llvm-libc project. This change also adds the first check which restricts user from including system libc headers accidentally which can lead to subtle bugs that would be a challenge to detect. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: aaron.ballman Subscribers: juliehockett, arphaman, jfb, abrachet, sivachandra, Eugene.Zelenko, njames93, mgorny, xazax.hun, MaskRay, cfe-commits Tags: #clang-tools-extra, #libc-project, #clang Differential Revision: https://reviews.llvm.org/D75332 Added: clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/resource/include/stdatomic.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/resource/include/stddef.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/math.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/stdio.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/stdlib.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/system/string.h clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp Modified: clang-tools-extra/clang-tidy/CMakeLists.txt clang-tools-extra/clang-tidy/ClangTidyForceLinker.h clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst clang-tools-extra/docs/clang-tidy/index.rst Removed: diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt index 20800cf93750..9b13516de211 100644 --- a/clang-tools-extra/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/CMakeLists.txt @@ -51,6 +51,7 @@ add_subdirectory(google) add_subdirectory(hicpp) add_subdirectory(linuxkernel) add_subdirectory(llvm) +add_subdirectory(llvmlibc) add_subdirectory(misc) add_subdirectory(modernize) if(CLANG_ENABLE_STATIC_ANALYZER) @@ -75,6 +76,7 @@ set(ALL_CLANG_TIDY_CHECKS clangTidyHICPPModule clangTidyLinuxKernelModule clangTidyLLVMModule + clangTidyLLVMLibcModule clangTidyMiscModule clangTidyModernizeModule clangTidyObjCModule diff --git a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h index 3ab700118587..8d29e62c4408 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h +++ b/clang-tools-extra/clang-tidy/ClangTidyForceLinker.h @@ -45,6 +45,11 @@ extern volatile int LLVMModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination = LLVMModuleAnchorSource; +// This anchor is used to force the linker to link the LLVMLibcModule. +extern volatile int LLVMLibcModuleAnchorSource; +static int LLVM_ATTRIBUTE_UNUSED LLVMLibcModuleAnchorDestination = +LLVMLibcModuleAnchorSource; + // This anchor is used to force the linker to link the CppCoreGuidelinesModule. extern volatile int CppCoreGuidelinesModuleAnchorSource; static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination = diff --git a/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt new file mode 100644 index ..c03d8b677f26 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt @@ -0,0 +1,15 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_library(clangTidyLLVMLibcModule + LLVMLibcTidyModule.cpp + RestrictSystemLibcHeadersCheck.cpp + + LINK_LIBS + clangAST + clangASTMatchers + clangBasic + clangLex + clangTidy + clangTidyUtils + clangTooling + ) diff --git a/clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp b/clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp new file mode 100644 index ..9874cae17d34 --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp @@ -0,0 +1,37 @@ +//===--- LLVMLibcTidyModule.cpp - clang-tidy --===// +// +// Part of the LLVM Project, under the Apache Licens
[clang] 71e8038 - Update shebang for clang-format-diff script to python3.
Author: Paula Toth Date: 2021-04-22T06:47:51-07:00 New Revision: 71e80386d0fe7f7a2f997271ce5d492d5e8686c2 URL: https://github.com/llvm/llvm-project/commit/71e80386d0fe7f7a2f997271ce5d492d5e8686c2 DIFF: https://github.com/llvm/llvm-project/commit/71e80386d0fe7f7a2f997271ce5d492d5e8686c2.diff LOG: Update shebang for clang-format-diff script to python3. Different distributions have different strategies migrating the `python` symlink. Debian and its derivatives provide `python-is-python2` and `python-is-python3`. If neither is installed, the user gets no `/usr/bin/python`. The clang-format-diff script and consequently `arc diff` can thus fail with a python not found error. Since we require python greater than 3.6 as part of llvm prerequisites (https://llvm.org/docs/GettingStarted.html#software), let's go ahead and update this shebang. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D100968 Added: Modified: clang/tools/clang-format/clang-format-diff.py Removed: diff --git a/clang/tools/clang-format/clang-format- diff .py b/clang/tools/clang-format/clang-format- diff .py index efed8168cc505..4edc0b2e19c29 100755 --- a/clang/tools/clang-format/clang-format- diff .py +++ b/clang/tools/clang-format/clang-format- diff .py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # #===- clang-format- diff .py - ClangFormat Diff Reformatter *- python -*--===# # ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits