Skip to content

Commit 5a7faf6

Browse files
authored
Merge branch 'main' into main
2 parents 459fc12 + dc8f2f0 commit 5a7faf6

File tree

1,802 files changed

+67324
-56142
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,802 files changed

+67324
-56142
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,10 @@ BinaryContext::createInstructionPatch(uint64_t Address,
24252425

24262426
std::pair<size_t, size_t>
24272427
BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
2428+
// Use the original size for non-simple functions.
2429+
if (!BF.isSimple() || BF.isIgnored())
2430+
return std::make_pair(BF.getSize(), 0);
2431+
24282432
// Adjust branch instruction to match the current layout.
24292433
if (FixBranches)
24302434
BF.fixBranches();

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,6 +3579,8 @@ bool BinaryFunction::validateCFG() const {
35793579
}
35803580

35813581
void BinaryFunction::fixBranches() {
3582+
assert(isSimple() && "Expected function with valid CFG.");
3583+
35823584
auto &MIB = BC.MIB;
35833585
MCContext *Ctx = BC.Ctx.get();
35843586

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ void DIEBuilder::updateReferences() {
175175
LocExpr.Die.replaceValue(getState().DIEAlloc, LocExpr.Attr, LocExpr.Form,
176176
Value);
177177
}
178-
179-
return;
180178
}
181179

182180
uint32_t DIEBuilder::allocDIE(const DWARFUnit &DU, const DWARFDie &DDie,

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
783783
Inst.setOpcode(RISCV::ADD);
784784
Inst.insert(Inst.begin(), MCOperand::createReg(Reg));
785785
Inst.insert(Inst.begin() + 1, MCOperand::createReg(RISCV::X0));
786-
return;
787786
}
788787

789788
InstructionListType createLoadImmediate(const MCPhysReg Dest,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Check that fixBranches() is not invoked on a broken CFG which could lead to
2+
## unintended consequences including a firing assertion.
3+
4+
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
5+
# RUN: link_fdata %s %t.o %t.fdata
6+
# RUN: llvm-strip --strip-unneeded %t.o
7+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
8+
# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=cdsplit \
9+
# RUN: --data=%t.fdata --reorder-blocks=ext-tsp 2>&1 | FileCheck %s
10+
11+
# CHECK: internal call detected
12+
13+
.text
14+
15+
.globl foo
16+
.type foo, @function
17+
foo:
18+
ret
19+
.size foo, .-foo
20+
21+
## main contains an internal call. ValidateInternalCalls pass will modify CFG
22+
## (making it invalid) and mark the function as non-simple. After that, we
23+
## cannot make any assumption about the CFG.
24+
25+
.globl main
26+
.type main, @function
27+
main:
28+
call .L1
29+
ret
30+
.L1:
31+
pushq %rbp
32+
movq %rsp, %rbp
33+
movl $1, %edi
34+
LLmain_foo1:
35+
call foo
36+
# FDATA: 1 main #LLmain_foo1# 1 foo 0 0 600
37+
movl $4, %edi
38+
xorl %eax, %eax
39+
popq %rbp
40+
retq
41+
.Lmain_end:
42+
.size main, .Lmain_end-main

clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ int main(int argc, char **argv) {
9696
cl::SetVersionPrinter(printVersion);
9797
cl::ParseCommandLineOptions(argc, argv);
9898

99-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
99+
DiagnosticOptions DiagOpts;
100100
DiagnosticsEngine Diagnostics(
101-
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts.get());
101+
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts);
102102

103103
// Determine a formatting style from options.
104104
auto FormatStyleOrError = format::getStyle(FormatStyleOpt, FormatStyleConfig,

clang-tools-extra/clang-change-namespace/tool/ClangChangeNamespace.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ int main(int argc, const char **argv) {
126126
if (int Result = Tool.run(Factory.get()))
127127
return Result;
128128
LangOptions DefaultLangOptions;
129-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
130-
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts);
129+
DiagnosticOptions DiagOpts;
130+
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagOpts);
131131
DiagnosticsEngine Diagnostics(
132-
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
132+
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
133133
&DiagnosticPrinter, false);
134134
auto &FileMgr = Tool.getFiles();
135135
SourceManager Sources(Diagnostics, FileMgr);

clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/Error.h"
1919
#include "llvm/Support/MemoryBuffer.h"
2020
#include "llvm/Support/Mustache.h"
21+
#include "llvm/Support/Path.h"
2122

2223
using namespace llvm;
2324
using namespace llvm::json;
@@ -74,7 +75,50 @@ static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;
7475

7576
static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr;
7677

78+
static Error
79+
setupTemplate(std::unique_ptr<MustacheTemplateFile> &Template,
80+
StringRef TemplatePath,
81+
std::vector<std::pair<StringRef, StringRef>> Partials) {
82+
auto T = MustacheTemplateFile::createMustacheFile(TemplatePath);
83+
if (Error Err = T.takeError())
84+
return Err;
85+
Template = std::move(T.get());
86+
for (const auto &[Name, FileName] : Partials)
87+
if (auto Err = Template->registerPartialFile(Name, FileName))
88+
return Err;
89+
return Error::success();
90+
}
91+
7792
static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
93+
// Template files need to use the native path when they're opened,
94+
// but have to be used in POSIX style when used in HTML.
95+
auto ConvertToNative = [](std::string &&Path) -> std::string {
96+
SmallString<128> PathBuf(Path);
97+
llvm::sys::path::native(PathBuf);
98+
return PathBuf.str().str();
99+
};
100+
101+
std::string NamespaceFilePath =
102+
ConvertToNative(CDCtx.MustacheTemplates.lookup("namespace-template"));
103+
std::string ClassFilePath =
104+
ConvertToNative(CDCtx.MustacheTemplates.lookup("class-template"));
105+
std::string CommentFilePath =
106+
ConvertToNative(CDCtx.MustacheTemplates.lookup("comment-template"));
107+
std::string FunctionFilePath =
108+
ConvertToNative(CDCtx.MustacheTemplates.lookup("function-template"));
109+
std::string EnumFilePath =
110+
ConvertToNative(CDCtx.MustacheTemplates.lookup("enum-template"));
111+
std::vector<std::pair<StringRef, StringRef>> Partials = {
112+
{"Comments", CommentFilePath},
113+
{"FunctionPartial", FunctionFilePath},
114+
{"EnumPartial", EnumFilePath}};
115+
116+
if (Error Err = setupTemplate(NamespaceTemplate, NamespaceFilePath, Partials))
117+
return Err;
118+
119+
if (Error Err = setupTemplate(RecordTemplate, ClassFilePath, Partials))
120+
return Err;
121+
78122
return Error::success();
79123
}
80124

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ set(LLVM_LINK_COMPONENTS
66

77
add_clang_library(clangDocSupport STATIC
88
File.cpp
9-
)
9+
Utils.cpp
10+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//===----------------------------------------------------------------------===//
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 "Utils.h"
10+
#include "llvm/ADT/SmallString.h"
11+
#include "llvm/ADT/StringRef.h"
12+
#include "llvm/Support/FileSystem.h"
13+
#include "llvm/Support/Path.h"
14+
15+
using namespace llvm;
16+
17+
SmallString<128> appendPathNative(StringRef Base, StringRef Path) {
18+
SmallString<128> Default;
19+
sys::path::native(Base, Default);
20+
sys::path::append(Default, Path);
21+
return Default;
22+
}
23+
24+
SmallString<128> appendPathPosix(StringRef Base, StringRef Path) {
25+
SmallString<128> Default;
26+
sys::path::native(Base, Default, sys::path::Style::posix);
27+
sys::path::append(Default, Path);
28+
return Default;
29+
}
30+
31+
void getMustacheHtmlFiles(StringRef AssetsPath,
32+
clang::doc::ClangDocContext &CDCtx) {
33+
assert(!AssetsPath.empty());
34+
assert(sys::fs::is_directory(AssetsPath));
35+
36+
SmallString<128> DefaultStylesheet =
37+
appendPathPosix(AssetsPath, "clang-doc-mustache.css");
38+
SmallString<128> NamespaceTemplate =
39+
appendPathPosix(AssetsPath, "namespace-template.mustache");
40+
SmallString<128> ClassTemplate =
41+
appendPathPosix(AssetsPath, "class-template.mustache");
42+
SmallString<128> EnumTemplate =
43+
appendPathPosix(AssetsPath, "enum-template.mustache");
44+
SmallString<128> FunctionTemplate =
45+
appendPathPosix(AssetsPath, "function-template.mustache");
46+
SmallString<128> CommentTemplate =
47+
appendPathPosix(AssetsPath, "comment-template.mustache");
48+
SmallString<128> IndexJS = appendPathPosix(AssetsPath, "mustache-index.js");
49+
50+
CDCtx.JsScripts.insert(CDCtx.JsScripts.begin(), IndexJS.c_str());
51+
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
52+
DefaultStylesheet.c_str());
53+
CDCtx.MustacheTemplates.insert(
54+
{"namespace-template", NamespaceTemplate.c_str()});
55+
CDCtx.MustacheTemplates.insert({"class-template", ClassTemplate.c_str()});
56+
CDCtx.MustacheTemplates.insert({"enum-template", EnumTemplate.c_str()});
57+
CDCtx.MustacheTemplates.insert(
58+
{"function-template", FunctionTemplate.c_str()});
59+
CDCtx.MustacheTemplates.insert({"comment-template", CommentTemplate.c_str()});
60+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
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+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILE_H
9+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_FILE_H
10+
11+
#include "../Representation.h"
12+
#include "llvm/ADT/SmallString.h"
13+
#include "llvm/ADT/StringRef.h"
14+
15+
/// Appends \p Path to \p Base and returns the appended path.
16+
llvm::SmallString<128> appendPathNative(llvm::StringRef Base,
17+
llvm::StringRef Path);
18+
19+
/// Appends \p Path to \p Base and returns the appended path in posix style.
20+
llvm::SmallString<128> appendPathPosix(llvm::StringRef Base,
21+
llvm::StringRef Path);
22+
23+
void getMustacheHtmlFiles(llvm::StringRef AssetsPath,
24+
clang::doc::ClangDocContext &CDCtx);
25+
26+
#endif

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set(assets
2525
clang-doc-default-stylesheet.css
2626
clang-doc-mustache.css
2727
class-template.mustache
28-
comments-template.mustache
28+
comment-template.mustache
2929
enum-template.mustache
3030
function-template.mustache
3131
namespace-template.mustache

clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
658658
{"bits/syslog-path.h$", "<sys/syslog.h>"},
659659
{"bits/termios.h$", "<termios.h>"},
660660
{"bits/types.h$", "<sys/types.h>"},
661+
{"bits/types/struct_iovec.h$", "<sys/uio.h>"},
661662
{"bits/typesizes.h$", "<sys/types.h>"},
662663
{"bits/uio.h$", "<sys/uio.h>"},
663664
{"bits/ustat.h$", "<sys/ustat.h>"},

clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ int includeFixerMain(int argc, const char **argv) {
455455
}
456456

457457
// Set up a new source manager for applying the resulting replacements.
458-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions);
459-
DiagnosticsEngine Diagnostics(new DiagnosticIDs, &*DiagOpts);
460-
TextDiagnosticPrinter DiagnosticPrinter(outs(), &*DiagOpts);
458+
DiagnosticOptions DiagOpts;
459+
DiagnosticsEngine Diagnostics(new DiagnosticIDs, DiagOpts);
460+
TextDiagnosticPrinter DiagnosticPrinter(outs(), DiagOpts);
461461
SourceManager SM(Diagnostics, tool.getFiles());
462462
Diagnostics.setClient(&DiagnosticPrinter, false);
463463

clang-tools-extra/clang-move/tool/ClangMove.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ int main(int argc, const char **argv) {
176176
}
177177
}
178178

179-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
180-
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts);
179+
DiagnosticOptions DiagOpts;
180+
clang::TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagOpts);
181181
DiagnosticsEngine Diagnostics(
182-
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
182+
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
183183
&DiagnosticPrinter, false);
184184
auto &FileMgr = Tool.getFiles();
185185
SourceManager SM(Diagnostics, FileMgr);

clang-tools-extra/clang-query/Query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
172172
clang::SourceRange R = BI->second.getSourceRange();
173173
if (R.isValid()) {
174174
TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(),
175-
&AST->getDiagnostics().getDiagnosticOptions());
175+
AST->getDiagnostics().getDiagnosticOptions());
176176
TD.emitDiagnostic(
177177
FullSourceLoc(R.getBegin(), AST->getSourceManager()),
178178
DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",

clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ int main(int argc, const char **argv) {
7272

7373
int ExitCode = Tool.run(Factory.get());
7474
LangOptions DefaultLangOptions;
75-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
76-
TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts);
75+
DiagnosticOptions DiagOpts;
76+
TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagOpts);
7777
DiagnosticsEngine Diagnostics(
78-
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
78+
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), DiagOpts,
7979
&DiagnosticPrinter, false);
8080

8181
auto &FileMgr = Tool.getFiles();

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,14 @@ class ErrorReporter {
9797
ErrorReporter(ClangTidyContext &Context, FixBehaviour ApplyFixes,
9898
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS)
9999
: Files(FileSystemOptions(), std::move(BaseFS)),
100-
DiagOpts(new DiagnosticOptions()),
101-
DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), &*DiagOpts)),
102-
Diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts,
100+
DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), DiagOpts)),
101+
Diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), DiagOpts,
103102
DiagPrinter),
104103
SourceMgr(Diags, Files), Context(Context), ApplyFixes(ApplyFixes) {
105-
DiagOpts->ShowColors = Context.getOptions().UseColor.value_or(
104+
DiagOpts.ShowColors = Context.getOptions().UseColor.value_or(
106105
llvm::sys::Process::StandardOutHasColors());
107106
DiagPrinter->BeginSourceFile(LangOpts);
108-
if (DiagOpts->ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
107+
if (DiagOpts.ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
109108
llvm::sys::Process::UseANSIEscapeCodes(true);
110109
}
111110
}
@@ -308,7 +307,7 @@ class ErrorReporter {
308307

309308
FileManager Files;
310309
LangOptions LangOpts; // FIXME: use langopts from each original file
311-
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
310+
DiagnosticOptions DiagOpts;
312311
DiagnosticConsumer *DiagPrinter;
313312
DiagnosticsEngine Diags;
314313
SourceManager SourceMgr;
@@ -516,10 +515,10 @@ getCheckOptions(const ClangTidyOptions &Options,
516515
Options),
517516
AllowEnablingAnalyzerAlphaCheckers);
518517
ClangTidyDiagnosticConsumer DiagConsumer(Context);
519-
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(),
520-
llvm::makeIntrusiveRefCnt<DiagnosticOptions>(),
518+
auto DiagOpts = std::make_unique<DiagnosticOptions>();
519+
DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
521520
&DiagConsumer, /*ShouldOwnClient=*/false);
522-
Context.setDiagnosticsEngine(&DE);
521+
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
523522
ClangTidyASTConsumerFactory Factory(Context);
524523
return Factory.getCheckOptions();
525524
}
@@ -558,9 +557,10 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
558557
Context.setProfileStoragePrefix(StoreCheckProfile);
559558

560559
ClangTidyDiagnosticConsumer DiagConsumer(Context, nullptr, true, ApplyAnyFix);
561-
DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions(),
562-
&DiagConsumer, /*ShouldOwnClient=*/false);
563-
Context.setDiagnosticsEngine(&DE);
560+
auto DiagOpts = std::make_unique<DiagnosticOptions>();
561+
DiagnosticsEngine DE(new DiagnosticIDs(), *DiagOpts, &DiagConsumer,
562+
/*ShouldOwnClient=*/false);
563+
Context.setDiagnosticsEngine(std::move(DiagOpts), &DE);
564564
Tool.setDiagnosticConsumer(&DiagConsumer);
565565

566566
class ActionFactory : public FrontendActionFactory {

0 commit comments

Comments
 (0)