Skip to content

Commit f696ba9

Browse files
authored
merge main to amd-staging (llvm#1118)
2 parents 983af84 + 97d1f92 commit f696ba9

File tree

450 files changed

+13261
-7944
lines changed

Some content is hidden

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

450 files changed

+13261
-7944
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
cc: 'gcc-14'
5656
cxx: 'g++-14'
5757
steps:
58-
- uses: actions/checkout@v4
58+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5959
- name: ${{ matrix.config }}.${{ matrix.cxx }}
6060
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
6161
env:
@@ -105,7 +105,7 @@ jobs:
105105
cc: 'clang-18'
106106
cxx: 'clang++-18'
107107
steps:
108-
- uses: actions/checkout@v4
108+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
109109
- name: ${{ matrix.config }}
110110
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
111111
env:
@@ -169,7 +169,7 @@ jobs:
169169
runs-on: ${{ matrix.machine }}
170170
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
171171
steps:
172-
- uses: actions/checkout@v4
172+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
173173
- name: ${{ matrix.config }}
174174
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
175175
env:
@@ -207,11 +207,11 @@ jobs:
207207
os: macos-13
208208
runs-on: ${{ matrix.os }}
209209
steps:
210-
- uses: actions/checkout@v4
211-
- uses: maxim-lobanov/setup-xcode@v1
210+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
211+
- uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
212212
with:
213213
xcode-version: 'latest'
214-
- uses: seanmiddleditch/gha-setup-ninja@master
214+
- uses: seanmiddleditch/gha-setup-ninja@3b1f8f94a2f8254bd26914c4ab9474d4f0015f67 # v6
215215
- name: Build and test
216216
run: |
217217
python3 -m venv .venv
@@ -247,7 +247,7 @@ jobs:
247247
- { config: mingw-dll-i686, mingw: true }
248248
- { config: mingw-incomplete-sysroot, mingw: true }
249249
steps:
250-
- uses: actions/checkout@v4
250+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
251251
- name: Install dependencies
252252
run: |
253253
choco install -y ninja
@@ -275,7 +275,7 @@ jobs:
275275
echo "c:\Program Files\Git\usr\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
276276
- name: Set up the MSVC dev environment
277277
if: ${{ matrix.mingw != true }}
278-
uses: ilammy/msvc-dev-cmd@v1
278+
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
279279
- name: Build and test
280280
run: |
281281
bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}

.github/workflows/libcxx-build-containers.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
packages: write
3333

3434
steps:
35-
- uses: actions/checkout@v4
35+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3636

3737
- name: Build the Linux builder image
3838
working-directory: libcxx/utils/ci
@@ -47,7 +47,7 @@ jobs:
4747
# TAG: ${{ github.sha }}
4848

4949
- name: Log in to GitHub Container Registry
50-
uses: docker/login-action@v3
50+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
5151
with:
5252
registry: ghcr.io
5353
username: ${{ github.actor }}

.github/workflows/libcxx-check-generated-files.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-24.04
1313
steps:
1414
- name: Fetch LLVM sources
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1616

1717
- name: Install dependencies
18-
uses: aminya/setup-cpp@v1
18+
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
1919
with:
2020
clangformat: 17.0.1
2121
ninja: true

.github/workflows/release-asset-audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _get_uploaders(release_version):
2424
return set(
2525
[
2626
"DimitryAndric",
27-
"stefanp-ibm",
27+
"stefanp-synopsys",
2828
"lei137",
2929
"omjavaid",
3030
"nicolerabjohn",

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,11 @@ AST_MATCHER_P(QualType, hasCleanType, Matcher<QualType>, InnerMatcher) {
2727
Finder, Builder);
2828
}
2929

30-
constexpr std::array<StringRef, 2> NameList{
30+
constexpr std::array<StringRef, 2> MakeSmartPtrList{
3131
"::std::make_unique",
3232
"::std::make_shared",
3333
};
3434

35-
Matcher<Expr> constructFrom(Matcher<QualType> TypeMatcher,
36-
Matcher<Expr> ArgumentMatcher) {
37-
return expr(
38-
anyOf(
39-
// construct optional
40-
cxxConstructExpr(argumentCountIs(1U), hasType(TypeMatcher),
41-
hasArgument(0U, ArgumentMatcher)),
42-
// known template methods in std
43-
callExpr(argumentCountIs(1),
44-
callee(functionDecl(
45-
matchers::matchesAnyListedName(NameList),
46-
hasTemplateArgument(0, refersToType(TypeMatcher)))),
47-
hasArgument(0, ArgumentMatcher))),
48-
unless(anyOf(hasAncestor(typeLoc()),
49-
hasAncestor(expr(matchers::hasUnevaluatedContext())))));
50-
}
51-
5235
} // namespace
5336

5437
OptionalValueConversionCheck::OptionalValueConversionCheck(
@@ -74,7 +57,7 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
7457
auto EqualsBoundOptionalType =
7558
qualType(hasCleanType(equalsBoundNode("optional-type")));
7659

77-
auto OptionalDereferenceMatcher = callExpr(
60+
auto OptionalDerefMatcherImpl = callExpr(
7861
anyOf(
7962
cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
8063
hasUnaryOperand(hasType(EqualsBoundOptionalType)))
@@ -88,11 +71,24 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
8871

8972
auto StdMoveCallMatcher =
9073
callExpr(argumentCountIs(1), callee(functionDecl(hasName("::std::move"))),
91-
hasArgument(0, ignoringImpCasts(OptionalDereferenceMatcher)));
74+
hasArgument(0, ignoringImpCasts(OptionalDerefMatcherImpl)));
75+
auto OptionalDerefMatcher =
76+
ignoringImpCasts(anyOf(OptionalDerefMatcherImpl, StdMoveCallMatcher));
77+
9278
Finder->addMatcher(
93-
expr(constructFrom(BindOptionalType,
94-
ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
95-
StdMoveCallMatcher))))
79+
expr(anyOf(
80+
// construct optional
81+
cxxConstructExpr(argumentCountIs(1), hasType(BindOptionalType),
82+
hasArgument(0, OptionalDerefMatcher)),
83+
// known template methods in std
84+
callExpr(
85+
argumentCountIs(1),
86+
callee(functionDecl(
87+
matchers::matchesAnyListedName(MakeSmartPtrList),
88+
hasTemplateArgument(0, refersToType(BindOptionalType)))),
89+
hasArgument(0, OptionalDerefMatcher))),
90+
unless(anyOf(hasAncestor(typeLoc()),
91+
hasAncestor(expr(matchers::hasUnevaluatedContext())))))
9692
.bind("expr"),
9793
this);
9894
}

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
136136
return;
137137

138138
VariableCategory VC = VariableCategory::Value;
139-
if (Variable->getType()->isReferenceType())
139+
const QualType VT = Variable->getType();
140+
if (VT->isReferenceType())
140141
VC = VariableCategory::Reference;
141-
if (Variable->getType()->isPointerType())
142+
else if (VT->isPointerType())
142143
VC = VariableCategory::Pointer;
143-
if (Variable->getType()->isArrayType()) {
144-
if (const auto *ArrayT = dyn_cast<ArrayType>(Variable->getType())) {
145-
if (ArrayT->getElementType()->isPointerType())
146-
VC = VariableCategory::Pointer;
147-
}
148-
}
144+
else if (const auto *ArrayT = dyn_cast<ArrayType>(VT))
145+
if (ArrayT->getElementType()->isPointerType())
146+
VC = VariableCategory::Pointer;
149147

150148
// Each variable can only be in one category: Value, Pointer, Reference.
151149
// Analysis can be controlled for every category.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
//===--- AmbiguousSmartptrResetCallCheck.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 "AmbiguousSmartptrResetCallCheck.h"
10+
#include "../utils/OptionsUtils.h"
11+
#include "clang/AST/ASTContext.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
14+
#include "clang/Lex/Lexer.h"
15+
16+
using namespace clang::ast_matchers;
17+
18+
namespace clang::tidy::readability {
19+
20+
namespace {
21+
22+
AST_MATCHER(CXXMethodDecl, hasOnlyDefaultParameters) {
23+
for (const auto *Param : Node.parameters()) {
24+
if (!Param->hasDefaultArg())
25+
return false;
26+
}
27+
28+
return true;
29+
}
30+
31+
const auto DefaultSmartPointers = "::std::shared_ptr;::std::unique_ptr;"
32+
"::boost::shared_ptr";
33+
} // namespace
34+
35+
AmbiguousSmartptrResetCallCheck::AmbiguousSmartptrResetCallCheck(
36+
StringRef Name, ClangTidyContext *Context)
37+
: ClangTidyCheck(Name, Context),
38+
SmartPointers(utils::options::parseStringList(
39+
Options.get("SmartPointers", DefaultSmartPointers))) {}
40+
41+
void AmbiguousSmartptrResetCallCheck::storeOptions(
42+
ClangTidyOptions::OptionMap &Opts) {
43+
Options.store(Opts, "SmartPointers",
44+
utils::options::serializeStringList(SmartPointers));
45+
}
46+
47+
void AmbiguousSmartptrResetCallCheck::registerMatchers(MatchFinder *Finder) {
48+
const auto IsSmartptr = hasAnyName(SmartPointers);
49+
50+
const auto ResetMethod =
51+
cxxMethodDecl(hasName("reset"), hasOnlyDefaultParameters());
52+
53+
const auto TypeWithReset =
54+
anyOf(cxxRecordDecl(
55+
anyOf(hasMethod(ResetMethod),
56+
isDerivedFrom(cxxRecordDecl(hasMethod(ResetMethod))))),
57+
classTemplateSpecializationDecl(
58+
hasSpecializedTemplate(classTemplateDecl(has(ResetMethod)))));
59+
60+
const auto SmartptrWithReset = expr(hasType(hasUnqualifiedDesugaredType(
61+
recordType(hasDeclaration(classTemplateSpecializationDecl(
62+
IsSmartptr,
63+
hasTemplateArgument(
64+
0, templateArgument(refersToType(hasUnqualifiedDesugaredType(
65+
recordType(hasDeclaration(TypeWithReset))))))))))));
66+
67+
Finder->addMatcher(
68+
cxxMemberCallExpr(
69+
callee(ResetMethod),
70+
unless(hasAnyArgument(expr(unless(cxxDefaultArgExpr())))),
71+
anyOf(on(cxxOperatorCallExpr(hasOverloadedOperatorName("->"),
72+
hasArgument(0, SmartptrWithReset))
73+
.bind("ArrowOp")),
74+
on(SmartptrWithReset)))
75+
.bind("MemberCall"),
76+
this);
77+
}
78+
79+
void AmbiguousSmartptrResetCallCheck::check(
80+
const MatchFinder::MatchResult &Result) {
81+
const auto *MemberCall =
82+
Result.Nodes.getNodeAs<CXXMemberCallExpr>("MemberCall");
83+
assert(MemberCall);
84+
85+
if (const auto *Arrow =
86+
Result.Nodes.getNodeAs<CXXOperatorCallExpr>("ArrowOp")) {
87+
const CharSourceRange SmartptrSourceRange =
88+
Lexer::getAsCharRange(Arrow->getArg(0)->getSourceRange(),
89+
*Result.SourceManager, getLangOpts());
90+
91+
diag(MemberCall->getBeginLoc(),
92+
"ambiguous call to 'reset()' on a pointee of a smart pointer, prefer "
93+
"more explicit approach");
94+
95+
diag(MemberCall->getBeginLoc(),
96+
"consider dereferencing smart pointer to call 'reset' method "
97+
"of the pointee here",
98+
DiagnosticIDs::Note)
99+
<< FixItHint::CreateInsertion(SmartptrSourceRange.getBegin(), "(*")
100+
<< FixItHint::CreateInsertion(SmartptrSourceRange.getEnd(), ")")
101+
<< FixItHint::CreateReplacement(
102+
CharSourceRange::getCharRange(
103+
Arrow->getOperatorLoc(),
104+
Arrow->getOperatorLoc().getLocWithOffset(2)),
105+
".");
106+
} else {
107+
const auto *Member = cast<MemberExpr>(MemberCall->getCallee());
108+
assert(Member);
109+
110+
diag(MemberCall->getBeginLoc(),
111+
"ambiguous call to 'reset()' on a smart pointer with pointee that "
112+
"also has a 'reset()' method, prefer more explicit approach");
113+
114+
diag(MemberCall->getBeginLoc(),
115+
"consider assigning the pointer to 'nullptr' here",
116+
DiagnosticIDs::Note)
117+
<< FixItHint::CreateReplacement(
118+
SourceRange(Member->getOperatorLoc(), Member->getOperatorLoc()),
119+
" =")
120+
<< FixItHint::CreateReplacement(
121+
SourceRange(Member->getMemberLoc(), MemberCall->getEndLoc()),
122+
" nullptr");
123+
}
124+
}
125+
126+
} // namespace clang::tidy::readability
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- AmbiguousSmartptrResetCallCheck.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_READABILITY_AMBIGUOUSSMARTPTRRESETCALLCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AMBIGUOUSSMARTPTRRESETCALLCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::readability {
15+
16+
/// Finds potentially erroneous calls to 'reset' method on smart pointers when
17+
/// the pointee type also has a 'reset' method
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/ambiguous-smartptr-reset-call.html
21+
class AmbiguousSmartptrResetCallCheck : public ClangTidyCheck {
22+
public:
23+
AmbiguousSmartptrResetCallCheck(StringRef Name, ClangTidyContext *Context);
24+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
25+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
26+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
27+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28+
return LangOpts.CPlusPlus;
29+
}
30+
31+
private:
32+
const std::vector<StringRef> SmartPointers;
33+
};
34+
35+
} // namespace clang::tidy::readability
36+
37+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AMBIGUOUSSMARTPTRRESETCALLCHECK_H

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

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

66
add_clang_library(clangTidyReadabilityModule STATIC
7+
AmbiguousSmartptrResetCallCheck.cpp
78
AvoidConstParamsInDecls.cpp
89
AvoidNestedConditionalOperatorCheck.cpp
910
AvoidReturnWithVoidValueCheck.cpp

clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.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 "AmbiguousSmartptrResetCallCheck.h"
1213
#include "AvoidConstParamsInDecls.h"
1314
#include "AvoidNestedConditionalOperatorCheck.h"
1415
#include "AvoidReturnWithVoidValueCheck.h"
@@ -68,6 +69,8 @@ namespace readability {
6869
class ReadabilityModule : public ClangTidyModule {
6970
public:
7071
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
72+
CheckFactories.registerCheck<AmbiguousSmartptrResetCallCheck>(
73+
"readability-ambiguous-smartptr-reset-call");
7174
CheckFactories.registerCheck<AvoidConstParamsInDecls>(
7275
"readability-avoid-const-params-in-decls");
7376
CheckFactories.registerCheck<AvoidNestedConditionalOperatorCheck>(

0 commit comments

Comments
 (0)