Skip to content

Commit cb8e359

Browse files
committed
Merge from 'master' to 'sycl-web' (#6)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGLoopInfo.cpp
2 parents 938c2fd + 26d254f commit cb8e359

File tree

360 files changed

+9247
-3465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+9247
-3465
lines changed

clang-tools-extra/clang-tidy/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ add_subdirectory(google)
5151
add_subdirectory(hicpp)
5252
add_subdirectory(linuxkernel)
5353
add_subdirectory(llvm)
54+
add_subdirectory(llvmlibc)
5455
add_subdirectory(misc)
5556
add_subdirectory(modernize)
5657
if(CLANG_ENABLE_STATIC_ANALYZER)
@@ -75,6 +76,7 @@ set(ALL_CLANG_TIDY_CHECKS
7576
clangTidyHICPPModule
7677
clangTidyLinuxKernelModule
7778
clangTidyLLVMModule
79+
clangTidyLLVMLibcModule
7880
clangTidyMiscModule
7981
clangTidyModernizeModule
8082
clangTidyObjCModule

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "clang/Tooling/Core/Diagnostic.h"
2727
#include "llvm/ADT/STLExtras.h"
2828
#include "llvm/ADT/SmallString.h"
29+
#include "llvm/Support/Regex.h"
2930
#include <tuple>
3031
#include <vector>
3132
using namespace clang;

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "llvm/ADT/StringMap.h"
2020
#include "llvm/Support/Timer.h"
2121

22+
namespace llvm {
23+
class Regex;
24+
}
25+
2226
namespace clang {
2327

2428
class ASTContext;

clang-tools-extra/clang-tidy/ClangTidyForceLinker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ extern volatile int LLVMModuleAnchorSource;
4545
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
4646
LLVMModuleAnchorSource;
4747

48+
// This anchor is used to force the linker to link the LLVMLibcModule.
49+
extern volatile int LLVMLibcModuleAnchorSource;
50+
static int LLVM_ATTRIBUTE_UNUSED LLVMLibcModuleAnchorDestination =
51+
LLVMLibcModuleAnchorSource;
52+
4853
// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
4954
extern volatile int CppCoreGuidelinesModuleAnchorSource;
5055
static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "ExpandModularHeadersPPCallbacks.h"
1010
#include "clang/Basic/FileManager.h"
11+
#include "clang/Basic/TargetInfo.h"
1112
#include "clang/Frontend/CompilerInstance.h"
1213
#include "clang/Lex/PreprocessorOptions.h"
1314
#include "clang/Serialization/ASTReader.h"

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "StringIntegerAssignmentCheck.h"
4646
#include "StringLiteralWithEmbeddedNulCheck.h"
4747
#include "SuspiciousEnumUsageCheck.h"
48+
#include "SuspiciousIncludeCheck.h"
4849
#include "SuspiciousMemsetUsageCheck.h"
4950
#include "SuspiciousMissingCommaCheck.h"
5051
#include "SuspiciousSemicolonCheck.h"
@@ -140,6 +141,8 @@ class BugproneModule : public ClangTidyModule {
140141
"bugprone-string-literal-with-embedded-nul");
141142
CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
142143
"bugprone-suspicious-enum-usage");
144+
CheckFactories.registerCheck<SuspiciousIncludeCheck>(
145+
"bugprone-suspicious-include");
143146
CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
144147
"bugprone-suspicious-memset-usage");
145148
CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_clang_library(clangTidyBugproneModule
3737
StringIntegerAssignmentCheck.cpp
3838
StringLiteralWithEmbeddedNulCheck.cpp
3939
SuspiciousEnumUsageCheck.cpp
40+
SuspiciousIncludeCheck.cpp
4041
SuspiciousMemsetUsageCheck.cpp
4142
SuspiciousMissingCommaCheck.cpp
4243
SuspiciousSemicolonCheck.cpp
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//===--- SuspiciousIncludeCheck.cpp - clang-tidy --------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "SuspiciousIncludeCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
12+
namespace clang {
13+
namespace tidy {
14+
namespace bugprone {
15+
16+
namespace {
17+
class SuspiciousIncludePPCallbacks : public PPCallbacks {
18+
public:
19+
explicit SuspiciousIncludePPCallbacks(SuspiciousIncludeCheck &Check,
20+
const SourceManager &SM,
21+
Preprocessor *PP)
22+
: Check(Check), PP(PP) {}
23+
24+
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
25+
StringRef FileName, bool IsAngled,
26+
CharSourceRange FilenameRange, const FileEntry *File,
27+
StringRef SearchPath, StringRef RelativePath,
28+
const Module *Imported,
29+
SrcMgr::CharacteristicKind FileType) override;
30+
31+
private:
32+
SuspiciousIncludeCheck &Check;
33+
Preprocessor *PP;
34+
};
35+
} // namespace
36+
37+
SuspiciousIncludeCheck::SuspiciousIncludeCheck(StringRef Name,
38+
ClangTidyContext *Context)
39+
: ClangTidyCheck(Name, Context),
40+
RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
41+
"HeaderFileExtensions", utils::defaultHeaderFileExtensions())),
42+
RawStringImplementationFileExtensions(Options.getLocalOrGlobal(
43+
"ImplementationFileExtensions",
44+
utils::defaultImplementationFileExtensions())) {
45+
if (!utils::parseFileExtensions(RawStringImplementationFileExtensions,
46+
ImplementationFileExtensions,
47+
utils::defaultFileExtensionDelimiters())) {
48+
llvm::errs() << "Invalid implementation file extension: "
49+
<< RawStringImplementationFileExtensions << "\n";
50+
}
51+
52+
if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
53+
HeaderFileExtensions,
54+
utils::defaultFileExtensionDelimiters())) {
55+
llvm::errs() << "Invalid header file extension: "
56+
<< RawStringHeaderFileExtensions << "\n";
57+
}
58+
}
59+
60+
void SuspiciousIncludeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
61+
Options.store(Opts, "ImplementationFileExtensions",
62+
RawStringImplementationFileExtensions);
63+
Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
64+
}
65+
66+
void SuspiciousIncludeCheck::registerPPCallbacks(
67+
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
68+
PP->addPPCallbacks(
69+
::std::make_unique<SuspiciousIncludePPCallbacks>(*this, SM, PP));
70+
}
71+
72+
void SuspiciousIncludePPCallbacks::InclusionDirective(
73+
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
74+
bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
75+
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
76+
SrcMgr::CharacteristicKind FileType) {
77+
if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import)
78+
return;
79+
80+
SourceLocation DiagLoc = FilenameRange.getBegin().getLocWithOffset(1);
81+
82+
const Optional<StringRef> IFE =
83+
utils::getFileExtension(FileName, Check.ImplementationFileExtensions);
84+
if (!IFE)
85+
return;
86+
87+
Check.diag(DiagLoc, "suspicious #%0 of file with '%1' extension")
88+
<< IncludeTok.getIdentifierInfo()->getName() << *IFE;
89+
90+
for (const auto &HFE : Check.HeaderFileExtensions) {
91+
SmallString<128> GuessedFileName(FileName);
92+
llvm::sys::path::replace_extension(GuessedFileName,
93+
(HFE.size() ? "." : "") + HFE);
94+
95+
const DirectoryLookup *CurDir;
96+
Optional<FileEntryRef> File =
97+
PP->LookupFile(DiagLoc, GuessedFileName, IsAngled, nullptr, nullptr,
98+
CurDir, nullptr, nullptr, nullptr, nullptr, nullptr);
99+
if (File) {
100+
Check.diag(DiagLoc, "did you mean to include '%0'?", DiagnosticIDs::Note)
101+
<< GuessedFileName;
102+
}
103+
}
104+
}
105+
106+
} // namespace bugprone
107+
} // namespace tidy
108+
} // namespace clang
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//===--- SuspiciousIncludeCheck.h - clang-tidy ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
#include "../utils/FileExtensionsUtils.h"
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace bugprone {
18+
19+
/// Warns on inclusion of files whose names suggest that they're implementation
20+
/// files, instead of headers. E.g:
21+
///
22+
/// #include "foo.cpp" // warning
23+
/// #include "bar.c" // warning
24+
/// #include "baz.h" // no diagnostic
25+
///
26+
/// The check supports these options:
27+
/// - `HeaderFileExtensions`: a semicolon-separated list of filename
28+
/// extensions of header files (The filename extensions should not contain
29+
/// "." prefix) ";h;hh;hpp;hxx" by default. For extension-less header
30+
/// files, using an empty string or leaving an empty string between ";" if
31+
/// there are other filename extensions.
32+
///
33+
/// - `ImplementationFileExtensions`: likewise, a semicolon-separated list of
34+
/// filename extensions of implementation files. "c;cc;cpp;cxx" by default.
35+
///
36+
/// For the user-facing documentation see:
37+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-suspicious-include.html
38+
class SuspiciousIncludeCheck : public ClangTidyCheck {
39+
public:
40+
SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context);
41+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
42+
Preprocessor *ModuleExpanderPP) override;
43+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
44+
45+
utils::FileExtensionsSet HeaderFileExtensions;
46+
utils::FileExtensionsSet ImplementationFileExtensions;
47+
48+
private:
49+
const std::string RawStringHeaderFileExtensions;
50+
const std::string RawStringImplementationFileExtensions;
51+
};
52+
53+
} // namespace bugprone
54+
} // namespace tidy
55+
} // namespace clang
56+
57+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H

clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "DefaultOperatorNewAlignmentCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/Basic/TargetInfo.h"
1213

1314
using namespace clang::ast_matchers;
1415

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(LLVM_LINK_COMPONENTS support)
2+
3+
add_clang_library(clangTidyLLVMLibcModule
4+
LLVMLibcTidyModule.cpp
5+
RestrictSystemLibcHeadersCheck.cpp
6+
7+
LINK_LIBS
8+
clangAST
9+
clangASTMatchers
10+
clangBasic
11+
clangLex
12+
clangTidy
13+
clangTidyUtils
14+
clangTooling
15+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- LLVMLibcTidyModule.cpp - clang-tidy ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "../ClangTidy.h"
10+
#include "../ClangTidyModule.h"
11+
#include "../ClangTidyModuleRegistry.h"
12+
#include "RestrictSystemLibcHeadersCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace llvm_libc {
17+
18+
class LLVMLibcModule : public ClangTidyModule {
19+
public:
20+
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
21+
CheckFactories.registerCheck<RestrictSystemLibcHeadersCheck>(
22+
"llvmlibc-restrict-system-libc-headers");
23+
}
24+
};
25+
26+
// Register the LLVMLibcTidyModule using this statically initialized variable.
27+
static ClangTidyModuleRegistry::Add<LLVMLibcModule>
28+
X("llvmlibc-module", "Adds LLVM libc standards checks.");
29+
30+
} // namespace llvm_libc
31+
32+
// This anchor is used to force the linker to link in the generated object file
33+
// and thus register the LLVMLibcModule.
34+
volatile int LLVMLibcModuleAnchorSource = 0;
35+
36+
} // namespace tidy
37+
} // namespace clang
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//===--- RestrictSystemLibcHeadersCheck.cpp - clang-tidy ------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "RestrictSystemLibcHeadersCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/Lex/HeaderSearch.h"
13+
#include "clang/Lex/HeaderSearchOptions.h"
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace llvm_libc {
18+
19+
namespace {
20+
21+
class RestrictedIncludesPPCallbacks : public PPCallbacks {
22+
public:
23+
explicit RestrictedIncludesPPCallbacks(
24+
RestrictSystemLibcHeadersCheck &Check, const SourceManager &SM,
25+
const SmallString<128> CompilerIncudeDir)
26+
: Check(Check), SM(SM), CompilerIncudeDir(CompilerIncudeDir) {}
27+
28+
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
29+
StringRef FileName, bool IsAngled,
30+
CharSourceRange FilenameRange, const FileEntry *File,
31+
StringRef SearchPath, StringRef RelativePath,
32+
const Module *Imported,
33+
SrcMgr::CharacteristicKind FileType) override;
34+
35+
private:
36+
RestrictSystemLibcHeadersCheck &Check;
37+
const SourceManager &SM;
38+
const SmallString<128> CompilerIncudeDir;
39+
};
40+
41+
} // namespace
42+
43+
void RestrictedIncludesPPCallbacks::InclusionDirective(
44+
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
45+
bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
46+
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
47+
SrcMgr::CharacteristicKind FileType) {
48+
if (SrcMgr::isSystem(FileType)) {
49+
// Compiler provided headers are allowed (e.g stddef.h).
50+
if (SearchPath == CompilerIncudeDir) return;
51+
if (!SM.isInMainFile(HashLoc)) {
52+
Check.diag(
53+
HashLoc,
54+
"system libc header %0 not allowed, transitively included from %1")
55+
<< FileName << SM.getFilename(HashLoc);
56+
} else {
57+
Check.diag(HashLoc, "system libc header %0 not allowed") << FileName;
58+
}
59+
}
60+
}
61+
62+
void RestrictSystemLibcHeadersCheck::registerPPCallbacks(
63+
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
64+
SmallString<128> CompilerIncudeDir =
65+
StringRef(PP->getHeaderSearchInfo().getHeaderSearchOpts().ResourceDir);
66+
llvm::sys::path::append(CompilerIncudeDir, "include");
67+
PP->addPPCallbacks(std::make_unique<RestrictedIncludesPPCallbacks>(
68+
*this, SM, CompilerIncudeDir));
69+
}
70+
71+
} // namespace llvm_libc
72+
} // namespace tidy
73+
} // namespace clang

0 commit comments

Comments
 (0)