Skip to content

Commit 094c01d

Browse files
authored
Merge branch 'sycl' into iwgo5
2 parents 900aca8 + cb069fe commit 094c01d

File tree

3,640 files changed

+136854
-48143
lines changed

Some content is hidden

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

3,640 files changed

+136854
-48143
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const ClangTidyOptions &ClangTidyContext::getOptions() const {
205205
ClangTidyOptions ClangTidyContext::getOptionsForFile(StringRef File) const {
206206
// Merge options on top of getDefaults() as a safeguard against options with
207207
// unset values.
208-
return ClangTidyOptions::getDefaults().mergeWith(
208+
return ClangTidyOptions::getDefaults().merge(
209209
OptionsProvider->getOptions(File), 0);
210210
}
211211

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
116116
Options.User = llvm::None;
117117
for (const ClangTidyModuleRegistry::entry &Module :
118118
ClangTidyModuleRegistry::entries())
119-
Options = Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
119+
Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
120120
return Options;
121121
}
122122

@@ -142,27 +142,31 @@ static void overrideValue(Optional<T> &Dest, const Optional<T> &Src) {
142142
Dest = Src;
143143
}
144144

145-
ClangTidyOptions ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
146-
unsigned Priority) const {
147-
ClangTidyOptions Result = *this;
148-
149-
mergeCommaSeparatedLists(Result.Checks, Other.Checks);
150-
mergeCommaSeparatedLists(Result.WarningsAsErrors, Other.WarningsAsErrors);
151-
overrideValue(Result.HeaderFilterRegex, Other.HeaderFilterRegex);
152-
overrideValue(Result.SystemHeaders, Other.SystemHeaders);
153-
overrideValue(Result.FormatStyle, Other.FormatStyle);
154-
overrideValue(Result.User, Other.User);
155-
overrideValue(Result.UseColor, Other.UseColor);
156-
mergeVectors(Result.ExtraArgs, Other.ExtraArgs);
157-
mergeVectors(Result.ExtraArgsBefore, Other.ExtraArgsBefore);
145+
ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
146+
unsigned Order) {
147+
mergeCommaSeparatedLists(Checks, Other.Checks);
148+
mergeCommaSeparatedLists(WarningsAsErrors, Other.WarningsAsErrors);
149+
overrideValue(HeaderFilterRegex, Other.HeaderFilterRegex);
150+
overrideValue(SystemHeaders, Other.SystemHeaders);
151+
overrideValue(FormatStyle, Other.FormatStyle);
152+
overrideValue(User, Other.User);
153+
overrideValue(UseColor, Other.UseColor);
154+
mergeVectors(ExtraArgs, Other.ExtraArgs);
155+
mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore);
158156

159157
for (const auto &KeyValue : Other.CheckOptions) {
160-
Result.CheckOptions.insert_or_assign(
158+
CheckOptions.insert_or_assign(
161159
KeyValue.getKey(),
162160
ClangTidyValue(KeyValue.getValue().Value,
163-
KeyValue.getValue().Priority + Priority));
161+
KeyValue.getValue().Priority + Order));
164162
}
163+
return *this;
164+
}
165165

166+
ClangTidyOptions ClangTidyOptions::merge(const ClangTidyOptions &Other,
167+
unsigned Order) const {
168+
ClangTidyOptions Result = *this;
169+
Result.mergeWith(Other, Order);
166170
return Result;
167171
}
168172

@@ -178,8 +182,8 @@ ClangTidyOptions
178182
ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
179183
ClangTidyOptions Result;
180184
unsigned Priority = 0;
181-
for (const auto &Source : getRawOptions(FileName))
182-
Result = Result.mergeWith(Source.first, ++Priority);
185+
for (auto &Source : getRawOptions(FileName))
186+
Result.mergeWith(Source.first, ++Priority);
183187
return Result;
184188
}
185189

@@ -325,7 +329,9 @@ llvm::Optional<OptionsSource>
325329
FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
326330
assert(!Directory.empty());
327331

328-
if (!llvm::sys::fs::is_directory(Directory)) {
332+
llvm::ErrorOr<llvm::vfs::Status> DirectoryStatus = FS->status(Directory);
333+
334+
if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
329335
llvm::errs() << "Error reading configuration from " << Directory
330336
<< ": directory doesn't exist.\n";
331337
return llvm::None;
@@ -336,15 +342,13 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
336342
llvm::sys::path::append(ConfigFile, ConfigHandler.first);
337343
LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
338344

339-
bool IsFile = false;
340-
// Ignore errors from is_regular_file: we only need to know if we can read
341-
// the file or not.
342-
llvm::sys::fs::is_regular_file(Twine(ConfigFile), IsFile);
343-
if (!IsFile)
345+
llvm::ErrorOr<llvm::vfs::Status> FileStatus = FS->status(ConfigFile);
346+
347+
if (!FileStatus || !FileStatus->isRegularFile())
344348
continue;
345349

346350
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
347-
llvm::MemoryBuffer::getFile(ConfigFile.c_str());
351+
FS->getBufferForFile(ConfigFile);
348352
if (std::error_code EC = Text.getError()) {
349353
llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
350354
<< "\n";
@@ -363,7 +367,7 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
363367
<< ParsedOptions.getError().message() << "\n";
364368
continue;
365369
}
366-
return OptionsSource(*ParsedOptions, ConfigFile.c_str());
370+
return OptionsSource(*ParsedOptions, std::string(ConfigFile));
367371
}
368372
return llvm::None;
369373
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ struct ClangTidyOptions {
5555
/// of each registered \c ClangTidyModule.
5656
static ClangTidyOptions getDefaults();
5757

58+
/// Overwrites all fields in here by the fields of \p Other that have a value.
59+
/// \p Order specifies precedence of \p Other option.
60+
ClangTidyOptions &mergeWith(const ClangTidyOptions &Other, unsigned Order);
61+
5862
/// Creates a new \c ClangTidyOptions instance combined from all fields
5963
/// of this instance overridden by the fields of \p Other that have a value.
6064
/// \p Order specifies precedence of \p Other option.
61-
ClangTidyOptions mergeWith(const ClangTidyOptions &Other,
62-
unsigned Order) const;
65+
LLVM_NODISCARD ClangTidyOptions merge(const ClangTidyOptions &Other,
66+
unsigned Order) const;
6367

6468
/// Checks filter.
6569
llvm::Optional<std::string> Checks;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static llvm::Regex ConsumeGlob(StringRef &GlobList) {
3434
for (char C : Glob) {
3535
if (C == '*')
3636
RegexText.push_back('.');
37-
else if (MetaChars.find(C) != StringRef::npos)
37+
else if (MetaChars.contains(C))
3838
RegexText.push_back('\\');
3939
RegexText.push_back(C);
4040
}
@@ -43,6 +43,7 @@ static llvm::Regex ConsumeGlob(StringRef &GlobList) {
4343
}
4444

4545
GlobList::GlobList(StringRef Globs) {
46+
Items.reserve(Globs.count(',') + 1);
4647
do {
4748
GlobListItem Item;
4849
Item.IsPositive = !ConsumeNegativeIndicator(Globs);
@@ -52,10 +53,11 @@ GlobList::GlobList(StringRef Globs) {
5253
}
5354

5455
bool GlobList::contains(StringRef S) {
55-
bool Contains = false;
56-
for (const GlobListItem &Item : Items) {
56+
// Iterating the container backwards as the last match determins if S is in
57+
// the list.
58+
for (const GlobListItem &Item : llvm::reverse(Items)) {
5759
if (Item.Regex.match(S))
58-
Contains = Item.IsPositive;
60+
return Item.IsPositive;
5961
}
60-
return Contains;
62+
return false;
6163
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
1111

1212
#include "clang/Basic/LLVM.h"
13+
#include "llvm/ADT/SmallVector.h"
1314
#include "llvm/ADT/StringRef.h"
1415
#include "llvm/Support/Regex.h"
15-
#include <vector>
1616

1717
namespace clang {
1818
namespace tidy {
@@ -39,9 +39,9 @@ class GlobList {
3939

4040
struct GlobListItem {
4141
bool IsPositive;
42-
mutable llvm::Regex Regex;
42+
llvm::Regex Regex;
4343
};
44-
std::vector<GlobListItem> Items;
44+
SmallVector<GlobListItem, 0> Items;
4545
};
4646

4747
} // end namespace tidy

clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../ClangTidy.h"
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
12+
#include "KernelNameRestrictionCheck.h"
1213
#include "StructPackAlignCheck.h"
1314

1415
using namespace clang::ast_matchers;
@@ -20,6 +21,8 @@ namespace altera {
2021
class AlteraModule : public ClangTidyModule {
2122
public:
2223
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
24+
CheckFactories.registerCheck<KernelNameRestrictionCheck>(
25+
"altera-kernel-name-restriction");
2326
CheckFactories.registerCheck<StructPackAlignCheck>(
2427
"altera-struct-pack-align");
2528
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
55

66
add_clang_library(clangTidyAlteraModule
77
AlteraTidyModule.cpp
8+
KernelNameRestrictionCheck.cpp
89
StructPackAlignCheck.cpp
910

1011
LINK_LIBS
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//===--- KernelNameRestrictionCheck.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 "KernelNameRestrictionCheck.h"
10+
#include "clang/Frontend/CompilerInstance.h"
11+
#include "clang/Lex/PPCallbacks.h"
12+
#include "clang/Lex/Preprocessor.h"
13+
#include <string>
14+
#include <vector>
15+
16+
using namespace clang::ast_matchers;
17+
18+
namespace clang {
19+
namespace tidy {
20+
namespace altera {
21+
22+
namespace {
23+
24+
class KernelNameRestrictionPPCallbacks : public PPCallbacks {
25+
public:
26+
explicit KernelNameRestrictionPPCallbacks(ClangTidyCheck &Check,
27+
const SourceManager &SM)
28+
: Check(Check), SM(SM) {}
29+
30+
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
31+
StringRef FileName, bool IsAngled,
32+
CharSourceRange FileNameRange, const FileEntry *File,
33+
StringRef SearchPath, StringRef RelativePath,
34+
const Module *Imported,
35+
SrcMgr::CharacteristicKind FileType) override;
36+
37+
void EndOfMainFile() override;
38+
39+
private:
40+
/// Returns true if the name of the file with path FilePath is 'kernel.cl',
41+
/// 'verilog.cl', or 'vhdl.cl'. The file name check is case insensitive.
42+
bool FileNameIsRestricted(StringRef FilePath);
43+
44+
struct IncludeDirective {
45+
SourceLocation Loc; // Location in the include directive.
46+
StringRef FileName; // Filename as a string.
47+
};
48+
49+
std::vector<IncludeDirective> IncludeDirectives;
50+
ClangTidyCheck &Check;
51+
const SourceManager &SM;
52+
};
53+
54+
} // namespace
55+
56+
void KernelNameRestrictionCheck::registerPPCallbacks(const SourceManager &SM,
57+
Preprocessor *PP,
58+
Preprocessor *) {
59+
PP->addPPCallbacks(
60+
std::make_unique<KernelNameRestrictionPPCallbacks>(*this, SM));
61+
}
62+
63+
void KernelNameRestrictionPPCallbacks::InclusionDirective(
64+
SourceLocation HashLoc, const Token &, StringRef FileName, bool,
65+
CharSourceRange, const FileEntry *, StringRef, StringRef, const Module *,
66+
SrcMgr::CharacteristicKind) {
67+
IncludeDirective ID = {HashLoc, FileName};
68+
IncludeDirectives.push_back(std::move(ID));
69+
}
70+
71+
bool KernelNameRestrictionPPCallbacks::FileNameIsRestricted(
72+
StringRef FileName) {
73+
return FileName.equals_lower("kernel.cl") ||
74+
FileName.equals_lower("verilog.cl") ||
75+
FileName.equals_lower("vhdl.cl");
76+
}
77+
78+
void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
79+
80+
// Check main file for restricted names.
81+
const FileEntry *Entry = SM.getFileEntryForID(SM.getMainFileID());
82+
StringRef FileName = llvm::sys::path::filename(Entry->getName());
83+
if (FileNameIsRestricted(FileName))
84+
Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()),
85+
"compiling '%0' may cause additional compilation errors due "
86+
"to the name of the kernel source file; consider renaming the "
87+
"included kernel source file")
88+
<< FileName;
89+
90+
if (IncludeDirectives.empty())
91+
return;
92+
93+
// Check included files for restricted names.
94+
for (const IncludeDirective &ID : IncludeDirectives) {
95+
StringRef FileName = llvm::sys::path::filename(ID.FileName);
96+
if (FileNameIsRestricted(FileName))
97+
Check.diag(ID.Loc,
98+
"including '%0' may cause additional compilation errors due "
99+
"to the name of the kernel source file; consider renaming the "
100+
"included kernel source file")
101+
<< FileName;
102+
}
103+
}
104+
105+
} // namespace altera
106+
} // namespace tidy
107+
} // namespace clang
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- KernelNameRestrictionCheck.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_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace altera {
17+
18+
/// Finds kernel files and include directives whose filename is `kernel.cl`,
19+
/// `Verilog.cl`, or `VHDL.cl`.
20+
///
21+
/// For the user-facing documentation see:
22+
/// http://clang.llvm.org/extra/clang-tidy/checks/altera-kernel-name-restriction.html
23+
class KernelNameRestrictionCheck : public ClangTidyCheck {
24+
public:
25+
KernelNameRestrictionCheck(StringRef Name, ClangTidyContext *Context)
26+
: ClangTidyCheck(Name, Context) {}
27+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
28+
Preprocessor *) override;
29+
};
30+
31+
} // namespace altera
32+
} // namespace tidy
33+
} // namespace clang
34+
35+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ void RedundantBranchConditionCheck::check(const MatchFinder::MatchResult &Result
8282

8383
// For standalone condition variables and for "or" binary operations we simply
8484
// remove the inner `if`.
85-
const auto *BinOpCond = dyn_cast<BinaryOperator>(InnerIf->getCond());
85+
const auto *BinOpCond =
86+
dyn_cast<BinaryOperator>(InnerIf->getCond()->IgnoreParenImpCasts());
87+
8688
if (isa<DeclRefExpr>(InnerIf->getCond()->IgnoreParenImpCasts()) ||
8789
(BinOpCond && BinOpCond->getOpcode() == BO_LOr)) {
8890
SourceLocation IfBegin = InnerIf->getBeginLoc();
@@ -129,7 +131,8 @@ void RedundantBranchConditionCheck::check(const MatchFinder::MatchResult &Result
129131
// For "and" binary operations we remove the "and" operation with the
130132
// condition variable from the inner if.
131133
} else {
132-
const auto *CondOp = cast<BinaryOperator>(InnerIf->getCond());
134+
const auto *CondOp =
135+
cast<BinaryOperator>(InnerIf->getCond()->IgnoreParenImpCasts());
133136
const auto *LeftDRE =
134137
dyn_cast<DeclRefExpr>(CondOp->getLHS()->IgnoreParenImpCasts());
135138
if (LeftDRE && LeftDRE->getDecl() == CondVar) {

0 commit comments

Comments
 (0)