Skip to content

Commit bed8916

Browse files
Merge from 'master' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
2 parents 54f31ad + a8d7451 commit bed8916

File tree

363 files changed

+8081
-2896
lines changed

Some content is hidden

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

363 files changed

+8081
-2896
lines changed

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,32 @@ static StringRef const StyleNames[] = {
122122
#undef NAMING_KEYS
123123
// clang-format on
124124

125+
IdentifierNamingCheck::NamingStyle::NamingStyle(
126+
llvm::Optional<IdentifierNamingCheck::CaseType> Case,
127+
const std::string &Prefix, const std::string &Suffix,
128+
const std::string &IgnoredRegexpStr)
129+
: Case(Case), Prefix(Prefix), Suffix(Suffix),
130+
IgnoredRegexpStr(IgnoredRegexpStr) {
131+
if (!IgnoredRegexpStr.empty()) {
132+
IgnoredRegexp =
133+
llvm::Regex(llvm::SmallString<128>({"^", IgnoredRegexpStr, "$"}));
134+
if (!IgnoredRegexp.isValid())
135+
llvm::errs() << "Invalid IgnoredRegexp regular expression: "
136+
<< IgnoredRegexpStr;
137+
}
138+
}
139+
125140
static IdentifierNamingCheck::FileStyle
126141
getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
127-
SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles(
128-
SK_Count);
142+
SmallVector<llvm::Optional<IdentifierNamingCheck::NamingStyle>, 0> Styles;
143+
Styles.resize(SK_Count);
129144
SmallString<64> StyleString;
130145
for (unsigned I = 0; I < SK_Count; ++I) {
131146
StyleString = StyleNames[I];
132147
size_t StyleSize = StyleString.size();
148+
StyleString.append("IgnoredRegexp");
149+
std::string IgnoredRegexpStr = Options.get(StyleString, "");
150+
StyleString.resize(StyleSize);
133151
StyleString.append("Prefix");
134152
std::string Prefix(Options.get(StyleString, ""));
135153
// Fast replacement of [Pre]fix -> [Suf]fix.
@@ -141,9 +159,10 @@ getFileStyleFromOptions(const ClangTidyCheck::OptionsView &Options) {
141159
auto CaseOptional =
142160
Options.getOptional<IdentifierNamingCheck::CaseType>(StyleString);
143161

144-
if (CaseOptional || !Prefix.empty() || !Postfix.empty())
162+
if (CaseOptional || !Prefix.empty() || !Postfix.empty() ||
163+
!IgnoredRegexpStr.empty())
145164
Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
146-
std::move(Postfix));
165+
std::move(Postfix), std::move(IgnoredRegexpStr));
147166
}
148167
bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
149168
return {std::move(Styles), IgnoreMainLike};
@@ -175,6 +194,9 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
175194
continue;
176195
StyleString = StyleNames[I];
177196
size_t StyleSize = StyleString.size();
197+
StyleString.append("IgnoredRegexp");
198+
Options.store(Opts, StyleString, Styles[I]->IgnoredRegexpStr);
199+
StyleString.resize(StyleSize);
178200
StyleString.append("Prefix");
179201
Options.store(Opts, StyleString, Styles[I]->Prefix);
180202
// Fast replacement of [Pre]fix -> [Suf]fix.
@@ -194,7 +216,7 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
194216
}
195217

196218
static bool matchesStyle(StringRef Name,
197-
IdentifierNamingCheck::NamingStyle Style) {
219+
const IdentifierNamingCheck::NamingStyle &Style) {
198220
static llvm::Regex Matchers[] = {
199221
llvm::Regex("^.*$"),
200222
llvm::Regex("^[a-z][a-z0-9_]*$"),
@@ -681,6 +703,9 @@ static llvm::Optional<RenamerClangTidyCheck::FailureInfo> getFailureInfo(
681703
return None;
682704

683705
const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK];
706+
if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name))
707+
return None;
708+
684709
if (matchesStyle(Name, Style))
685710
return None;
686711

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
5252
NamingStyle() = default;
5353

5454
NamingStyle(llvm::Optional<CaseType> Case, const std::string &Prefix,
55-
const std::string &Suffix)
56-
: Case(Case), Prefix(Prefix), Suffix(Suffix) {}
55+
const std::string &Suffix, const std::string &IgnoredRegexpStr);
56+
NamingStyle(const NamingStyle &O) = delete;
57+
NamingStyle &operator=(NamingStyle &&O) = default;
58+
NamingStyle(NamingStyle &&O) = default;
5759

5860
llvm::Optional<CaseType> Case;
5961
std::string Prefix;
6062
std::string Suffix;
63+
// Store both compiled and non-compiled forms so original value can be
64+
// serialized
65+
llvm::Regex IgnoredRegexp;
66+
std::string IgnoredRegexpStr;
6167
};
6268

6369
struct FileStyle {

clang-tools-extra/clangd/ConfigProvider.cpp

Lines changed: 29 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ConfigProvider.h"
1010
#include "Config.h"
1111
#include "ConfigFragment.h"
12+
#include "support/FileCache.h"
1213
#include "support/ThreadsafeFS.h"
1314
#include "support/Trace.h"
1415
#include "llvm/ADT/ScopeExit.h"
@@ -24,89 +25,28 @@ namespace clangd {
2425
namespace config {
2526

2627
// Threadsafe cache around reading a YAML config file from disk.
27-
class FileConfigCache {
28-
std::mutex Mu;
29-
std::chrono::steady_clock::time_point ValidTime = {};
30-
llvm::SmallVector<CompiledFragment, 1> CachedValue;
31-
llvm::sys::TimePoint<> MTime = {};
32-
unsigned Size = -1;
33-
34-
// Called once we are sure we want to read the file.
35-
// REQUIRES: Cache keys are set. Mutex must be held.
36-
void fillCacheFromDisk(llvm::vfs::FileSystem &FS, DiagnosticCallback DC) {
37-
CachedValue.clear();
38-
39-
auto Buf = FS.getBufferForFile(Path);
40-
// If we failed to read (but stat succeeded), don't cache failure.
41-
if (!Buf) {
42-
Size = -1;
43-
MTime = {};
44-
return;
45-
}
46-
47-
// If file changed between stat and open, we don't know its mtime.
48-
// For simplicity, don't cache the value in this case (use a bad key).
49-
if (Buf->get()->getBufferSize() != Size) {
50-
Size = -1;
51-
MTime = {};
52-
}
53-
54-
// Finally parse and compile the actual fragments.
55-
for (auto &Fragment :
56-
Fragment::parseYAML(Buf->get()->getBuffer(), Path, DC)) {
57-
Fragment.Source.Directory = Directory;
58-
CachedValue.push_back(std::move(Fragment).compile(DC));
59-
}
60-
}
61-
62-
public:
63-
// Must be set before the cache is used. Not a constructor param to allow
64-
// computing ancestor-relative paths to be deferred.
65-
std::string Path;
66-
// Directory associated with this fragment.
28+
class FileConfigCache : public FileCache {
29+
mutable llvm::SmallVector<CompiledFragment, 1> CachedValue;
6730
std::string Directory;
6831

69-
// Retrieves up-to-date config fragments from disk.
70-
// A cached result may be reused if the mtime and size are unchanged.
71-
// (But several concurrent read()s can miss the cache after a single change).
72-
// Future performance ideas:
73-
// - allow caches to be reused based on short elapsed walltime
74-
// - allow latency-sensitive operations to skip revalidating the cache
75-
void read(const ThreadsafeFS &TFS, DiagnosticCallback DC,
76-
llvm::Optional<std::chrono::steady_clock::time_point> FreshTime,
77-
std::vector<CompiledFragment> &Out) {
78-
std::lock_guard<std::mutex> Lock(Mu);
79-
// We're going to update the cache and return whatever's in it.
80-
auto Return = llvm::make_scope_exit(
81-
[&] { llvm::copy(CachedValue, std::back_inserter(Out)); });
82-
83-
// Return any sufficiently recent result without doing any further work.
84-
if (FreshTime && ValidTime >= FreshTime)
85-
return;
86-
87-
// Ensure we bump the ValidTime at the end to allow for reuse.
88-
auto MarkTime = llvm::make_scope_exit(
89-
[&] { ValidTime = std::chrono::steady_clock::now(); });
90-
91-
// Stat is cheaper than opening the file, it's usually unchanged.
92-
assert(llvm::sys::path::is_absolute(Path));
93-
auto FS = TFS.view(/*CWD=*/llvm::None);
94-
auto Stat = FS->status(Path);
95-
// If there's no file, the result is empty. Ensure we have an invalid key.
96-
if (!Stat || !Stat->isRegularFile()) {
97-
MTime = {};
98-
Size = -1;
99-
CachedValue.clear();
100-
return;
101-
}
102-
// If the modified-time and size match, assume the content does too.
103-
if (Size == Stat->getSize() && MTime == Stat->getLastModificationTime())
104-
return;
105-
106-
// OK, the file has actually changed. Update cache key, compute new value.
107-
Size = Stat->getSize();
108-
MTime = Stat->getLastModificationTime();
109-
fillCacheFromDisk(*FS, DC);
32+
public:
33+
FileConfigCache(llvm::StringRef Path, llvm::StringRef Directory)
34+
: FileCache(Path), Directory(Directory) {}
35+
36+
void get(const ThreadsafeFS &TFS, DiagnosticCallback DC,
37+
std::chrono::steady_clock::time_point FreshTime,
38+
std::vector<CompiledFragment> &Out) const {
39+
read(
40+
TFS, FreshTime,
41+
[&](llvm::Optional<llvm::StringRef> Data) {
42+
CachedValue.clear();
43+
if (Data)
44+
for (auto &Fragment : Fragment::parseYAML(*Data, path(), DC)) {
45+
Fragment.Source.Directory = Directory;
46+
CachedValue.push_back(std::move(Fragment).compile(DC));
47+
}
48+
},
49+
[&]() { llvm::copy(CachedValue, std::back_inserter(Out)); });
11050
}
11151
};
11252

@@ -120,17 +60,15 @@ std::unique_ptr<Provider> Provider::fromYAMLFile(llvm::StringRef AbsPath,
12060
std::vector<CompiledFragment>
12161
getFragments(const Params &P, DiagnosticCallback DC) const override {
12262
std::vector<CompiledFragment> Result;
123-
Cache.read(FS, DC, P.FreshTime, Result);
63+
Cache.get(FS, DC, P.FreshTime, Result);
12464
return Result;
12565
};
12666

12767
public:
12868
AbsFileProvider(llvm::StringRef Path, llvm::StringRef Directory,
12969
const ThreadsafeFS &FS)
130-
: FS(FS) {
70+
: Cache(Path, Directory), FS(FS) {
13171
assert(llvm::sys::path::is_absolute(Path));
132-
Cache.Path = Path.str();
133-
Cache.Directory = Directory.str();
13472
}
13573
};
13674

@@ -174,23 +112,21 @@ Provider::fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath,
174112
{
175113
std::lock_guard<std::mutex> Lock(Mu);
176114
for (llvm::StringRef Ancestor : Ancestors) {
177-
auto R = Cache.try_emplace(Ancestor);
115+
auto It = Cache.find(Ancestor);
178116
// Assemble the actual config file path only once.
179-
if (R.second) {
117+
if (It == Cache.end()) {
180118
llvm::SmallString<256> ConfigPath = Ancestor;
181119
path::append(ConfigPath, RelPath);
182-
R.first->second.Path = ConfigPath.str().str();
183-
R.first->second.Directory = Ancestor.str();
120+
It = Cache.try_emplace(Ancestor, ConfigPath.str(), Ancestor).first;
184121
}
185-
Caches.push_back(&R.first->second);
122+
Caches.push_back(&It->second);
186123
}
187124
}
188125
// Finally query each individual file.
189126
// This will take a (per-file) lock for each file that actually exists.
190127
std::vector<CompiledFragment> Result;
191-
for (FileConfigCache *Cache : Caches) {
192-
Cache->read(FS, DC, P.FreshTime, Result);
193-
}
128+
for (FileConfigCache *Cache : Caches)
129+
Cache->get(FS, DC, P.FreshTime, Result);
194130
return Result;
195131
};
196132

clang-tools-extra/clangd/ConfigProvider.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ struct Params {
3838
llvm::StringRef Path;
3939
/// Hint that stale data is OK to improve performance (e.g. avoid IO).
4040
/// FreshTime sets a bound for how old the data can be.
41-
/// If not set, providers should validate caches against the data source.
42-
llvm::Optional<std::chrono::steady_clock::time_point> FreshTime;
41+
/// By default, providers should validate caches against the data source.
42+
std::chrono::steady_clock::time_point FreshTime =
43+
std::chrono::steady_clock::time_point::max();
4344
};
4445

4546
/// Used to report problems in parsing or interpreting a config.

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,10 @@ std::vector<const CXXRecordDecl *> typeParents(const CXXRecordDecl *CXXRD) {
15531553
CXXRD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
15541554
}
15551555

1556+
// Can't query bases without a definition.
1557+
if (!CXXRD->hasDefinition())
1558+
return Result;
1559+
15561560
for (auto Base : CXXRD->bases()) {
15571561
const CXXRecordDecl *ParentDecl = nullptr;
15581562

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ std::vector<SourceLocation> findOccurrencesWithinFile(ParsedAST &AST,
300300
const NamedDecl *lookupSiblingWithName(const ASTContext &Ctx,
301301
const NamedDecl &RenamedDecl,
302302
llvm::StringRef Name) {
303+
trace::Span Tracer("LookupSiblingWithName");
303304
const auto &II = Ctx.Idents.get(Name);
304305
DeclarationName LookupName(&II);
305306
DeclContextLookupResult LookupResult;
@@ -340,6 +341,15 @@ struct InvalidName {
340341
Kind K;
341342
std::string Details;
342343
};
344+
std::string toString(InvalidName::Kind K) {
345+
switch (K) {
346+
case InvalidName::Keywords:
347+
return "Keywords";
348+
case InvalidName::Conflict:
349+
return "Conflict";
350+
}
351+
llvm_unreachable("unhandled InvalidName kind");
352+
}
343353

344354
llvm::Error makeError(InvalidName Reason) {
345355
auto Message = [](InvalidName Reason) {
@@ -359,18 +369,26 @@ llvm::Error makeError(InvalidName Reason) {
359369
// Return details if the rename would produce a conflict.
360370
llvm::Optional<InvalidName> checkName(const NamedDecl &RenameDecl,
361371
llvm::StringRef NewName) {
372+
trace::Span Tracer("CheckName");
373+
static constexpr trace::Metric InvalidNameMetric(
374+
"rename_name_invalid", trace::Metric::Counter, "invalid_kind");
362375
auto &ASTCtx = RenameDecl.getASTContext();
376+
llvm::Optional<InvalidName> Result;
363377
if (isKeyword(NewName, ASTCtx.getLangOpts()))
364-
return InvalidName{InvalidName::Keywords, NewName.str()};
365-
// Name conflict detection.
366-
// Function conflicts are subtle (overloading), so ignore them.
367-
if (RenameDecl.getKind() != Decl::Function) {
368-
if (auto *Conflict = lookupSiblingWithName(ASTCtx, RenameDecl, NewName))
369-
return InvalidName{
370-
InvalidName::Conflict,
371-
Conflict->getLocation().printToString(ASTCtx.getSourceManager())};
378+
Result = InvalidName{InvalidName::Keywords, NewName.str()};
379+
else {
380+
// Name conflict detection.
381+
// Function conflicts are subtle (overloading), so ignore them.
382+
if (RenameDecl.getKind() != Decl::Function) {
383+
if (auto *Conflict = lookupSiblingWithName(ASTCtx, RenameDecl, NewName))
384+
Result = InvalidName{
385+
InvalidName::Conflict,
386+
Conflict->getLocation().printToString(ASTCtx.getSourceManager())};
387+
}
372388
}
373-
return llvm::None;
389+
if (Result)
390+
InvalidNameMetric.record(1, toString(Result->K));
391+
return Result;
374392
}
375393

376394
// AST-based rename, it renames all occurrences in the main file.

0 commit comments

Comments
 (0)