Skip to content

Commit 39eda22

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/95366
2 parents 7e3af56 + ef01c75 commit 39eda22

File tree

1,136 files changed

+33956
-16971
lines changed

Some content is hidden

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

1,136 files changed

+33956
-16971
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function compute-projects-to-test() {
7474
fi
7575
;;
7676
clang)
77-
for p in clang-tools-extra compiler-rt lldb cross-project-tests; do
77+
# lldb is temporarily removed to alleviate Linux pre-commit CI waiting times
78+
for p in clang-tools-extra compiler-rt cross-project-tests; do
7879
echo $p
7980
done
8081
;;

.github/workflows/restart-preempted-libcxx-jobs.yaml renamed to .github/workflows/libcxx-restart-preempted-jobs.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
script: |
3535
const failure_regex = /Process completed with exit code 1./
3636
const preemption_regex = /The runner has received a shutdown signal/
37-
37+
3838
const wf_run = context.payload.workflow_run
3939
core.notice(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`)
4040
@@ -80,30 +80,30 @@ jobs:
8080
}
8181
check_run_ids.push(check_run.id);
8282
}
83-
83+
8484
has_preempted_job = false;
8585
8686
for (check_run_id of check_run_ids) {
8787
console.log('Listing annotations for check run: ' + check_run_id);
88-
88+
8989
annotations = await github.rest.checks.listAnnotations({
9090
owner: context.repo.owner,
9191
repo: context.repo.repo,
9292
check_run_id: check_run_id
9393
})
94-
94+
9595
for (annotation of annotations.data) {
9696
if (annotation.annotation_level != 'failure') {
9797
continue;
9898
}
99-
99+
100100
const preemption_match = annotation.message.match(preemption_regex);
101-
101+
102102
if (preemption_match != null) {
103103
console.log('Found preemption message: ' + annotation.message);
104104
has_preempted_job = true;
105105
}
106-
106+
107107
const failure_match = annotation.message.match(failure_regex);
108108
if (failure_match != null) {
109109
// We only want to restart the workflow if all of the failures were due to preemption.
@@ -115,20 +115,18 @@ jobs:
115115
return;
116116
}
117117
}
118-
}
119-
118+
}
119+
120120
if (!has_preempted_job) {
121121
core.notice('No preempted jobs found. Not restarting workflow.');
122122
await create_check_run('neutral', 'No preempted jobs found. Not restarting workflow.')
123123
return;
124124
}
125-
125+
126126
core.notice("Restarted workflow: " + context.payload.workflow_run.id);
127127
await github.rest.actions.reRunWorkflowFailedJobs({
128128
owner: context.repo.owner,
129129
repo: context.repo.repo,
130130
run_id: context.payload.workflow_run.id
131131
})
132132
await create_check_run('success', 'Restarted workflow run due to preempted job')
133-
134-

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,8 +1479,9 @@ Error LinuxKernelRewriter::tryReadAltInstructions(uint32_t AltInstFeatureSize,
14791479
}
14801480
}
14811481

1482-
BC.outs() << "BOLT-INFO: parsed " << EntryID
1483-
<< " alternative instruction entries\n";
1482+
if (!ParseOnly)
1483+
BC.outs() << "BOLT-INFO: parsed " << EntryID
1484+
<< " alternative instruction entries\n";
14841485

14851486
return Error::success();
14861487
}

clang-tools-extra/clang-doc/tool/CMakeLists.txt

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,38 @@ target_link_libraries(clang-doc
1818
clangDoc
1919
)
2020

21-
install(FILES ../assets/clang-doc-default-stylesheet.css
22-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
23-
COMPONENT clang-doc)
2421

25-
install(FILES ../assets/index.js
26-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
27-
COMPONENT clang-doc)
22+
set(assets
23+
index.js
24+
clang-doc-default-stylesheet.css
25+
)
26+
27+
set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
28+
set(resource_dir "${CMAKE_BINARY_DIR}/share/clang")
29+
set(out_files)
30+
31+
function(copy_files_to_dst src_dir dst_dir file)
32+
set(src "${src_dir}/${file}")
33+
set(dst "${dst_dir}/${file}")
34+
add_custom_command(OUTPUT ${dst}
35+
DEPENDS ${src}
36+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
37+
COMMENT "Copying ${file} to ${dst_dir}"
38+
)
39+
list(APPEND out_files ${dst})
40+
set(out_files ${out_files} PARENT_SCOPE)
41+
endfunction(copy_files_to_dst)
42+
43+
foreach(f ${assets})
44+
install(FILES ${asset_dir}/${f}
45+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
46+
COMPONENT clang-doc)
47+
copy_files_to_dst(${asset_dir} ${resource_dir} ${f})
48+
endforeach(f)
49+
50+
add_custom_target(copy-clang-doc-assets
51+
DEPENDS ${out_files}
52+
COMMENT "Copying Clang-Doc Assets"
53+
)
54+
set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets")
55+
add_dependencies(clang-doc copy-clang-doc-assets)

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

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ReturnConstRefFromParameterCheck.h"
10-
#include "../utils/Matchers.h"
1110
#include "clang/ASTMatchers/ASTMatchFinder.h"
1211
#include "clang/ASTMatchers/ASTMatchers.h"
1312

@@ -18,20 +17,82 @@ namespace clang::tidy::bugprone {
1817
void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
1918
Finder->addMatcher(
2019
returnStmt(
21-
hasReturnValue(declRefExpr(to(parmVarDecl(hasType(hasCanonicalType(
22-
qualType(matchers::isReferenceToConst()).bind("type"))))))),
23-
hasAncestor(functionDecl(hasReturnTypeLoc(
24-
loc(qualType(hasCanonicalType(equalsBoundNode("type"))))))))
20+
hasReturnValue(declRefExpr(
21+
to(parmVarDecl(hasType(hasCanonicalType(
22+
qualType(lValueReferenceType(pointee(
23+
qualType(isConstQualified()))))
24+
.bind("type"))))
25+
.bind("param")))),
26+
hasAncestor(
27+
functionDecl(hasReturnTypeLoc(loc(qualType(
28+
hasCanonicalType(equalsBoundNode("type"))))))
29+
.bind("func")))
2530
.bind("ret"),
2631
this);
2732
}
2833

34+
static bool isSameTypeIgnoringConst(QualType A, QualType B) {
35+
return A.getCanonicalType().withConst() == B.getCanonicalType().withConst();
36+
}
37+
38+
static bool isSameTypeIgnoringConstRef(QualType A, QualType B) {
39+
return isSameTypeIgnoringConst(A.getCanonicalType().getNonReferenceType(),
40+
B.getCanonicalType().getNonReferenceType());
41+
}
42+
43+
static bool hasSameParameterTypes(const FunctionDecl &FD, const FunctionDecl &O,
44+
const ParmVarDecl &PD) {
45+
if (FD.getNumParams() != O.getNumParams())
46+
return false;
47+
for (unsigned I = 0, E = FD.getNumParams(); I < E; ++I) {
48+
const ParmVarDecl *DPD = FD.getParamDecl(I);
49+
const QualType OPT = O.getParamDecl(I)->getType();
50+
if (DPD == &PD) {
51+
if (!llvm::isa<RValueReferenceType>(OPT) ||
52+
!isSameTypeIgnoringConstRef(DPD->getType(), OPT))
53+
return false;
54+
} else {
55+
if (!isSameTypeIgnoringConst(DPD->getType(), OPT))
56+
return false;
57+
}
58+
}
59+
return true;
60+
}
61+
62+
static const Decl *findRVRefOverload(const FunctionDecl &FD,
63+
const ParmVarDecl &PD) {
64+
// Actually it would be better to do lookup in caller site.
65+
// But in most of cases, overloads of LVRef and RVRef will appear together.
66+
// FIXME:
67+
// 1. overload in anonymous namespace
68+
// 2. forward reference
69+
DeclContext::lookup_result LookupResult =
70+
FD.getParent()->lookup(FD.getNameInfo().getName());
71+
if (LookupResult.isSingleResult()) {
72+
return nullptr;
73+
}
74+
for (const Decl *Overload : LookupResult) {
75+
if (Overload == &FD)
76+
continue;
77+
if (const auto *O = dyn_cast<FunctionDecl>(Overload))
78+
if (hasSameParameterTypes(FD, *O, PD))
79+
return O;
80+
}
81+
return nullptr;
82+
}
83+
2984
void ReturnConstRefFromParameterCheck::check(
3085
const MatchFinder::MatchResult &Result) {
86+
const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("func");
87+
const auto *PD = Result.Nodes.getNodeAs<ParmVarDecl>("param");
3188
const auto *R = Result.Nodes.getNodeAs<ReturnStmt>("ret");
3289
const SourceRange Range = R->getRetValue()->getSourceRange();
3390
if (Range.isInvalid())
3491
return;
92+
93+
if (findRVRefOverload(*FD, *PD) != nullptr)
94+
return;
95+
3596
diag(Range.getBegin(),
3697
"returning a constant reference parameter may cause use-after-free "
3798
"when the parameter is constructed from a temporary")

clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) {
4444
unless(isInTemplateInstantiation()))
4545
.bind("call-move");
4646

47-
Finder->addMatcher(MoveCallMatcher, this);
47+
Finder->addMatcher(
48+
expr(anyOf(
49+
castExpr(hasSourceExpression(MoveCallMatcher)),
50+
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(anyOf(
51+
isCopyConstructor(), isMoveConstructor()))),
52+
hasArgument(0, MoveCallMatcher)))),
53+
this);
4854

4955
auto ConstTypeParmMatcher =
5056
qualType(references(isConstQualified())).bind("invocation-parm-type");

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ Changes in existing checks
387387
- Improved :doc:`modernize-use-using <clang-tidy/checks/modernize/use-using>`
388388
check by adding support for detection of typedefs declared on function level.
389389

390+
- Improved :doc:`performance-move-const-arg
391+
<clang-tidy/checks/performance/move-const-arg>` check by ignoring
392+
``std::move()`` calls when their target is used as an rvalue.
393+
390394
- Improved :doc:`performance-unnecessary-copy-initialization
391395
<clang-tidy/checks/performance/unnecessary-copy-initialization>` check by
392396
detecting more cases of constant access. In particular, pointers can be

clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "clang-include-cleaner/IncludeSpeller.h"
1010
#include "clang-include-cleaner/Types.h"
1111
#include "llvm/ADT/SmallVector.h"
12+
#include "llvm/ADT/StringRef.h"
1213
#include "llvm/Support/ErrorHandling.h"
1314
#include "llvm/Support/Registry.h"
1415
#include <memory>
@@ -30,8 +31,14 @@ class DefaultIncludeSpeller : public IncludeSpeller {
3031
return Input.H.verbatim().str();
3132
case Header::Physical:
3233
bool IsAngled = false;
34+
std::string WorkingDir;
35+
if (auto WD = Input.HS.getFileMgr()
36+
.getVirtualFileSystem()
37+
.getCurrentWorkingDirectory())
38+
WorkingDir = *WD;
3339
std::string FinalSpelling = Input.HS.suggestPathToFileForDiagnostics(
34-
Input.H.physical(), Input.Main->tryGetRealPathName(), &IsAngled);
40+
Input.H.resolvedPath(), WorkingDir, Input.Main->tryGetRealPathName(),
41+
&IsAngled);
3542
return IsAngled ? "<" + FinalSpelling + ">" : "\"" + FinalSpelling + "\"";
3643
}
3744
llvm_unreachable("Unknown clang::include_cleaner::Header::Kind enum");
@@ -60,4 +67,4 @@ std::string spellHeader(const IncludeSpeller::Input &Input) {
6067
return Spelling;
6168
}
6269

63-
} // namespace clang::include_cleaner
70+
} // namespace clang::include_cleaner

clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ TEST(IncludeSpeller, CanOverrideSystemHeaders) {
8989
HS, MainFile}));
9090
}
9191

92+
TEST(IncludeSpeller, RelativeIncludeSearchPath) {
93+
TestInputs Inputs;
94+
95+
Inputs.WorkingDir = "/root/inner";
96+
Inputs.ExtraArgs.push_back("-I..");
97+
Inputs.ExtraFiles["/root/foo.h"] = "";
98+
TestAST AST{Inputs};
99+
100+
auto &FM = AST.fileManager();
101+
auto &HS = AST.preprocessor().getHeaderSearchInfo();
102+
const auto *MainFile = AST.sourceManager().getFileEntryForID(
103+
AST.sourceManager().getMainFileID());
104+
105+
EXPECT_EQ("\"foo.h\"",
106+
spellHeader(
107+
{Header{*FM.getOptionalFileRef("/root/foo.h")}, HS, MainFile}));
108+
}
109+
92110
IncludeSpellingStrategy::Add<DummyIncludeSpeller>
93111
Speller("dummy", "Dummy Include Speller");
94112

clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,37 @@ void instantiate(const int &param, const float &paramf, int &mut_param, float &m
143143
}
144144

145145
} // namespace valid
146+
147+
namespace overload {
148+
149+
int const &overload_base(int const &a) { return a; }
150+
int const &overload_base(int &&a);
151+
152+
int const &overload_ret_type(int const &a) { return a; }
153+
void overload_ret_type(int &&a);
154+
155+
int const &overload_params1(int p1, int const &a) { return a; }
156+
int const & overload_params1(int p1, int &&a);
157+
158+
int const &overload_params2(int p1, int const &a, int p2) { return a; }
159+
int const &overload_params2(int p1, int &&a, int p2);
160+
161+
int const &overload_params3(T p1, int const &a, int p2) { return a; }
162+
int const &overload_params3(int p1, int &&a, T p2);
163+
164+
int const &overload_params_const(int p1, int const &a, int const p2) { return a; }
165+
int const &overload_params_const(int const p1, int &&a, int p2);
166+
167+
int const &overload_params_difference1(int p1, int const &a, int p2) { return a; }
168+
// CHECK-MESSAGES: :[[@LINE-1]]:79: warning: returning a constant reference parameter
169+
int const &overload_params_difference1(long p1, int &&a, int p2);
170+
171+
int const &overload_params_difference2(int p1, int const &a, int p2) { return a; }
172+
// CHECK-MESSAGES: :[[@LINE-1]]:79: warning: returning a constant reference parameter
173+
int const &overload_params_difference2(int p1, int &&a, long p2);
174+
175+
int const &overload_params_difference3(int p1, int const &a, int p2) { return a; }
176+
// CHECK-MESSAGES: :[[@LINE-1]]:79: warning: returning a constant reference parameter
177+
int const &overload_params_difference3(int p1, long &&a, int p2);
178+
179+
} // namespace overload

clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,18 @@ void f8() {
114114
int f9() { return M2(1); }
115115

116116
template <typename T>
117-
T f10(const int x10) {
117+
T f_unknown_target(const int x10) {
118118
return std::move(x10);
119-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x10' of the trivially-copyable type 'const int' has no effect; remove std::move() [performance-move-const-arg]
120-
// CHECK-FIXES: return x10;
121119
}
120+
122121
void f11() {
123-
f10<int>(1);
124-
f10<double>(1);
122+
f_unknown_target<int>(1);
123+
f_unknown_target<double>(1);
124+
}
125+
126+
A&& f_return_right_ref() {
127+
static A a{};
128+
return std::move(a);
125129
}
126130

127131
class NoMoveSemantics {

0 commit comments

Comments
 (0)