Skip to content

Commit 1fb99a4

Browse files
committed
Merge remote-tracking branch 'origin/main' into pr/gather-scatter-size
2 parents 82d50a9 + 08028d6 commit 1fb99a4

File tree

471 files changed

+13822
-5275
lines changed

Some content is hidden

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

471 files changed

+13822
-5275
lines changed

.ci/metrics/metrics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ def get_metrics(github_repo: github.Repository, workflows_to_track: dict[str, in
8080
completed_at = workflow_jobs[0].completed_at
8181

8282
job_result = int(workflow_jobs[0].conclusion == "success")
83+
if job_result:
84+
# We still might want to mark the job as a failure if one of the steps
85+
# failed. This is required due to use setting continue-on-error in
86+
# the premerge pipeline to prevent sending emails while we are
87+
# testing the infrastructure.
88+
# TODO(boomanaiden154): Remove this once the premerge pipeline is no
89+
# longer in a testing state and we can directly assert the workflow
90+
# result.
91+
for step in workflow_jobs[0].steps:
92+
if step.conclusion != "success":
93+
job_result = 0
94+
break
8395

8496
queue_time = started_at - created_at
8597
run_time = completed_at - started_at

.github/workflows/spirv-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
build_target: check-llvm-codegen-spirv
2727
projects:
2828
extra_cmake_args: '-DLLVM_TARGETS_TO_BUILD="" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="SPIRV" -DLLVM_INCLUDE_SPIRV_TOOLS_TESTS=ON'
29-
os_list: '["ubuntu-latest"]'
29+
os_list: '["ubuntu-22.04"]'

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ void ClangTidyCheck::OptionsView::store<bool>(
163163
store(Options, LocalName, Value ? StringRef("true") : StringRef("false"));
164164
}
165165

166-
std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
167-
StringRef LocalName, ArrayRef<NameAndValue> Mapping, bool CheckGlobal,
168-
bool IgnoreCase) const {
166+
std::optional<int64_t>
167+
ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
168+
ArrayRef<NameAndValue> Mapping,
169+
bool CheckGlobal) const {
169170
if (!CheckGlobal && Context->getOptionsCollector())
170171
Context->getOptionsCollector()->insert((NamePrefix + LocalName).str());
171172
auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix,
@@ -178,12 +179,10 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
178179
StringRef Closest;
179180
unsigned EditDistance = 3;
180181
for (const auto &NameAndEnum : Mapping) {
181-
if (IgnoreCase) {
182-
if (Value.equals_insensitive(NameAndEnum.second))
183-
return NameAndEnum.first;
184-
} else if (Value == NameAndEnum.second) {
182+
if (Value == NameAndEnum.second) {
185183
return NameAndEnum.first;
186-
} else if (Value.equals_insensitive(NameAndEnum.second)) {
184+
}
185+
if (Value.equals_insensitive(NameAndEnum.second)) {
187186
Closest = NameAndEnum.second;
188187
EditDistance = 0;
189188
continue;

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
333333
/// supply the mapping required to convert between ``T`` and a string.
334334
template <typename T>
335335
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
336-
get(StringRef LocalName, bool IgnoreCase = false) const {
336+
get(StringRef LocalName) const {
337337
if (std::optional<int64_t> ValueOr =
338-
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
338+
getEnumInt(LocalName, typeEraseMapping<T>(), false))
339339
return static_cast<T>(*ValueOr);
340340
return std::nullopt;
341341
}
@@ -353,9 +353,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
353353
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
354354
/// supply the mapping required to convert between ``T`` and a string.
355355
template <typename T>
356-
std::enable_if_t<std::is_enum_v<T>, T> get(StringRef LocalName, T Default,
357-
bool IgnoreCase = false) const {
358-
return get<T>(LocalName, IgnoreCase).value_or(Default);
356+
std::enable_if_t<std::is_enum_v<T>, T> get(StringRef LocalName,
357+
T Default) const {
358+
return get<T>(LocalName).value_or(Default);
359359
}
360360

361361
/// Read a named option from the ``Context`` and parse it as an
@@ -373,9 +373,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
373373
/// supply the mapping required to convert between ``T`` and a string.
374374
template <typename T>
375375
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
376-
getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
376+
getLocalOrGlobal(StringRef LocalName) const {
377377
if (std::optional<int64_t> ValueOr =
378-
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
378+
getEnumInt(LocalName, typeEraseMapping<T>(), true))
379379
return static_cast<T>(*ValueOr);
380380
return std::nullopt;
381381
}
@@ -394,10 +394,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
394394
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
395395
/// supply the mapping required to convert between ``T`` and a string.
396396
template <typename T>
397-
std::enable_if_t<std::is_enum_v<T>, T>
398-
getLocalOrGlobal(StringRef LocalName, T Default,
399-
bool IgnoreCase = false) const {
400-
return getLocalOrGlobal<T>(LocalName, IgnoreCase).value_or(Default);
397+
std::enable_if_t<std::is_enum_v<T>, T> getLocalOrGlobal(StringRef LocalName,
398+
T Default) const {
399+
return getLocalOrGlobal<T>(LocalName).value_or(Default);
401400
}
402401

403402
/// Stores an option with the check-local name \p LocalName with
@@ -454,7 +453,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
454453

455454
std::optional<int64_t> getEnumInt(StringRef LocalName,
456455
ArrayRef<NameAndValue> Mapping,
457-
bool CheckGlobal, bool IgnoreCase) const;
456+
bool CheckGlobal) const;
458457

459458
template <typename T>
460459
std::enable_if_t<std::is_enum_v<T>, std::vector<NameAndValue>>

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/ADT/SmallString.h"
1313
#include "llvm/Support/Debug.h"
1414
#include "llvm/Support/Errc.h"
15+
#include "llvm/Support/ErrorOr.h"
1516
#include "llvm/Support/FileSystem.h"
1617
#include "llvm/Support/MemoryBufferRef.h"
1718
#include "llvm/Support/Path.h"
@@ -298,12 +299,11 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
298299
if (ConfigOptions.InheritParentConfig.value_or(false)) {
299300
LLVM_DEBUG(llvm::dbgs()
300301
<< "Getting options for file " << FileName << "...\n");
301-
assert(FS && "FS must be set.");
302302

303-
llvm::SmallString<128> AbsoluteFilePath(FileName);
304-
305-
if (!FS->makeAbsolute(AbsoluteFilePath)) {
306-
addRawFileOptions(AbsoluteFilePath, RawOptions);
303+
llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
304+
getNormalizedAbsolutePath(FileName);
305+
if (AbsoluteFilePath) {
306+
addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
307307
}
308308
}
309309
RawOptions.emplace_back(ConfigOptions,
@@ -334,6 +334,17 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
334334
OverrideOptions(std::move(OverrideOptions)),
335335
ConfigHandlers(std::move(ConfigHandlers)) {}
336336

337+
llvm::ErrorOr<llvm::SmallString<128>>
338+
FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
339+
assert(FS && "FS must be set.");
340+
llvm::SmallString<128> NormalizedAbsolutePath = {Path};
341+
std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
342+
if (Err)
343+
return Err;
344+
llvm::sys::path::remove_dots(NormalizedAbsolutePath, /*remove_dot_dot=*/true);
345+
return NormalizedAbsolutePath;
346+
}
347+
337348
void FileOptionsBaseProvider::addRawFileOptions(
338349
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
339350
auto CurSize = CurOptions.size();
@@ -397,16 +408,15 @@ std::vector<OptionsSource>
397408
FileOptionsProvider::getRawOptions(StringRef FileName) {
398409
LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
399410
<< "...\n");
400-
assert(FS && "FS must be set.");
401-
402-
llvm::SmallString<128> AbsoluteFilePath(FileName);
403411

404-
if (FS->makeAbsolute(AbsoluteFilePath))
412+
llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
413+
getNormalizedAbsolutePath(FileName);
414+
if (!AbsoluteFilePath)
405415
return {};
406416

407417
std::vector<OptionsSource> RawOptions =
408-
DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
409-
addRawFileOptions(AbsoluteFilePath, RawOptions);
418+
DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
419+
addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
410420
OptionsSource CommandLineOptions(OverrideOptions,
411421
OptionsSourceTypeCheckCommandLineOption);
412422

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
1111

1212
#include "llvm/ADT/IntrusiveRefCntPtr.h"
13+
#include "llvm/ADT/SmallString.h"
1314
#include "llvm/ADT/StringMap.h"
1415
#include "llvm/ADT/StringRef.h"
1516
#include "llvm/Support/ErrorOr.h"
@@ -237,6 +238,9 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
237238
void addRawFileOptions(llvm::StringRef AbsolutePath,
238239
std::vector<OptionsSource> &CurOptions);
239240

241+
llvm::ErrorOr<llvm::SmallString<128>>
242+
getNormalizedAbsolutePath(llvm::StringRef AbsolutePath);
243+
240244
/// Try to read configuration files from \p Directory using registered
241245
/// \c ConfigHandlers.
242246
std::optional<OptionsSource> tryReadConfigFile(llvm::StringRef Directory);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "InaccurateEraseCheck.h"
3434
#include "IncDecInConditionsCheck.h"
3535
#include "IncorrectEnableIfCheck.h"
36+
#include "IncorrectEnableSharedFromThisCheck.h"
3637
#include "IncorrectRoundingsCheck.h"
3738
#include "InfiniteLoopCheck.h"
3839
#include "IntegerDivisionCheck.h"
@@ -144,6 +145,8 @@ class BugproneModule : public ClangTidyModule {
144145
"bugprone-inaccurate-erase");
145146
CheckFactories.registerCheck<IncorrectEnableIfCheck>(
146147
"bugprone-incorrect-enable-if");
148+
CheckFactories.registerCheck<IncorrectEnableSharedFromThisCheck>(
149+
"bugprone-incorrect-enable-shared-from-this");
147150
CheckFactories.registerCheck<ReturnConstRefFromParameterCheck>(
148151
"bugprone-return-const-ref-from-parameter");
149152
CheckFactories.registerCheck<SwitchMissingDefaultCaseCheck>(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ add_clang_library(clangTidyBugproneModule STATIC
2727
ForwardingReferenceOverloadCheck.cpp
2828
ImplicitWideningOfMultiplicationResultCheck.cpp
2929
InaccurateEraseCheck.cpp
30+
IncorrectEnableIfCheck.cpp
31+
IncorrectEnableSharedFromThisCheck.cpp
32+
ReturnConstRefFromParameterCheck.cpp
33+
SuspiciousStringviewDataUsageCheck.cpp
34+
SwitchMissingDefaultCaseCheck.cpp
3035
IncDecInConditionsCheck.cpp
3136
IncorrectEnableIfCheck.cpp
3237
IncorrectRoundingsCheck.cpp
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===--- IncorrectEnableSharedFromThisCheck.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 "IncorrectEnableSharedFromThisCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/DeclCXX.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
14+
using namespace clang::ast_matchers;
15+
16+
namespace clang::tidy::bugprone {
17+
18+
void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) {
19+
const auto EnableSharedFromThis =
20+
cxxRecordDecl(hasName("enable_shared_from_this"), isInStdNamespace());
21+
const auto QType = hasCanonicalType(hasDeclaration(
22+
cxxRecordDecl(
23+
anyOf(EnableSharedFromThis.bind("enable_rec"),
24+
cxxRecordDecl(hasAnyBase(cxxBaseSpecifier(
25+
isPublic(), hasType(hasCanonicalType(
26+
hasDeclaration(EnableSharedFromThis))))))))
27+
.bind("base_rec")));
28+
Finder->addMatcher(
29+
cxxRecordDecl(
30+
unless(isExpansionInSystemHeader()),
31+
hasDirectBase(cxxBaseSpecifier(unless(isPublic()), hasType(QType))
32+
.bind("base")))
33+
.bind("derived"),
34+
this);
35+
}
36+
37+
void IncorrectEnableSharedFromThisCheck::check(
38+
const MatchFinder::MatchResult &Result) {
39+
const auto *BaseSpec = Result.Nodes.getNodeAs<CXXBaseSpecifier>("base");
40+
const auto *Base = Result.Nodes.getNodeAs<CXXRecordDecl>("base_rec");
41+
const auto *Derived = Result.Nodes.getNodeAs<CXXRecordDecl>("derived");
42+
const bool IsEnableSharedFromThisDirectBase =
43+
Result.Nodes.getNodeAs<CXXRecordDecl>("enable_rec") == Base;
44+
const bool HasWrittenAccessSpecifier =
45+
BaseSpec->getAccessSpecifierAsWritten() != AS_none;
46+
const auto ReplacementRange = CharSourceRange(
47+
SourceRange(BaseSpec->getBeginLoc()), HasWrittenAccessSpecifier);
48+
const llvm::StringRef Replacement =
49+
HasWrittenAccessSpecifier ? "public" : "public ";
50+
const FixItHint Hint =
51+
IsEnableSharedFromThisDirectBase
52+
? FixItHint::CreateReplacement(ReplacementRange, Replacement)
53+
: FixItHint();
54+
diag(Derived->getLocation(),
55+
"%2 is not publicly inheriting from "
56+
"%select{%1 which inherits from |}0'std::enable_shared_"
57+
"from_this', "
58+
"which will cause unintended behaviour "
59+
"when using 'shared_from_this'; make the inheritance "
60+
"public",
61+
DiagnosticIDs::Warning)
62+
<< IsEnableSharedFromThisDirectBase << Base << Derived << Hint;
63+
}
64+
65+
} // namespace clang::tidy::bugprone
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- IncorrectEnableSharedFromThisCheck.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_INCORRECTENABLESHAREDFROMTHISCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INCORRECTENABLESHAREDFROMTHISCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Detect classes or structs that do not publicly inherit from
17+
/// ``std::enable_shared_from_this``, because unintended behavior will
18+
/// otherwise occur when calling ``shared_from_this``.
19+
///
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/incorrect-enable-shared-from-this.html
22+
class IncorrectEnableSharedFromThisCheck : public ClangTidyCheck {
23+
public:
24+
IncorrectEnableSharedFromThisCheck(StringRef Name, ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context) {}
26+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
27+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
29+
return LangOpts.CPlusPlus11;
30+
}
31+
};
32+
33+
} // namespace clang::tidy::bugprone
34+
35+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INCORRECTENABLESHAREDFROMTHISCHECK_H

0 commit comments

Comments
 (0)