Skip to content

Commit a8eb019

Browse files
authored
Merge branch 'main' into users/xur-llvm/pgowork
2 parents c987f23 + 0e90a84 commit a8eb019

File tree

623 files changed

+95219
-41956
lines changed

Some content is hidden

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

623 files changed

+95219
-41956
lines changed

.ci/monolithic-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function at-exit {
3838

3939
ccache --print-stats > artifacts/ccache_stats.txt
4040
cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
41-
cp "${BUILD_DIR}"/test-results.*.xml artifacts/
41+
cp "${BUILD_DIR}"/test-results.*.xml artifacts/ || :
4242

4343
# If building fails there will be no results files.
4444
shopt -s nullglob

.ci/monolithic-windows.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function at-exit {
3333
mkdir -p artifacts
3434
sccache --show-stats >> artifacts/sccache_stats.txt
3535
cp "${BUILD_DIR}"/.ninja_log artifacts/.ninja_log
36-
cp "${BUILD_DIR}"/test-results.*.xml artifacts/
36+
cp "${BUILD_DIR}"/test-results.*.xml artifacts/ || :
3737

3838
# If building fails there will be no results files.
3939
shopt -s nullglob

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
/mlir/**/Transforms/SROA.* @moxinilian
129129

130130
# BOLT
131-
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @yota9
131+
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @yota9 @paschalis-mpeis
132132

133133
# Bazel build system.
134134
/utils/bazel/ @rupprecht @keith @aaronmondal

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,19 @@ void RewriteInstance::discoverFileObjects() {
13411341
}
13421342
}
13431343
}
1344+
1345+
// The linker may omit data markers for absolute long veneers. Introduce
1346+
// those markers artificially to assist the disassembler.
1347+
for (BinaryFunction &BF :
1348+
llvm::make_second_range(BC->getBinaryFunctions())) {
1349+
if (BF.getOneName().starts_with("__AArch64AbsLongThunk_") &&
1350+
BF.getSize() == 16 && !BF.getSizeOfDataInCodeAt(8)) {
1351+
BC->errs() << "BOLT-WARNING: missing data marker detected in veneer "
1352+
<< BF << '\n';
1353+
BF.markDataAtOffset(8);
1354+
BC->AddressToConstantIslandMap[BF.getAddress() + 8] = &BF;
1355+
}
1356+
}
13441357
}
13451358

13461359
if (!BC->IsLinuxKernel) {

bolt/test/AArch64/veneer-lld-abs.s

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66
# RUN: -fuse-ld=lld -Wl,-q
77
# RUN: llvm-objdump -d %t.exe | FileCheck --check-prefix=CHECK-INPUT %s
88
# RUN: llvm-objcopy --remove-section .rela.mytext %t.exe
9-
# RUN: llvm-bolt %t.exe -o %t.bolt --elim-link-veneers=true --lite=0
9+
# RUN: llvm-bolt %t.exe -o %t.bolt
1010
# RUN: llvm-objdump -d -j .text %t.bolt | \
1111
# RUN: FileCheck --check-prefix=CHECK-OUTPUT %s
1212

13+
## Occasionally, we see the linker not generating $d symbols for long veneers
14+
## causing BOLT to fail veneer elimination.
15+
# RUN: llvm-objcopy --remove-symbol-prefix=\$d %t.exe %t.no-marker.exe
16+
# RUN: llvm-bolt %t.no-marker.exe -o %t.no-marker.bolt \
17+
# RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-BOLT
18+
# RUN: llvm-objdump -d -j .text %t.no-marker.bolt | \
19+
# RUN: FileCheck --check-prefix=CHECK-OUTPUT %s
20+
21+
# CHECK-BOLT-NOT: BOLT-WARNING: unable to disassemble instruction
22+
# CHECK-BOLT: BOLT-WARNING: missing data marker detected in veneer __AArch64AbsLongThunk_far_function
23+
1324
.text
1425
.balign 4
1526
.global far_function

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ getFunctionPrototype(const FunctionDecl *FuncDecl) {
113113
Stream << " " << ParamDecl->getNameAsString();
114114

115115
// Print default argument if it exists
116-
if (ParamDecl->hasDefaultArg()) {
117-
const Expr *DefaultArg = ParamDecl->getDefaultArg();
118-
if (DefaultArg) {
116+
if (ParamDecl->hasDefaultArg() &&
117+
!ParamDecl->hasUninstantiatedDefaultArg()) {
118+
if (const Expr *DefaultArg = ParamDecl->getDefaultArg()) {
119119
Stream << " = ";
120120
DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
121121
}

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static llvm::cl::opt<OutputFormatTy> FormatEnum(
118118
"Documentation in mustache HTML format")),
119119
llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory));
120120

121+
static llvm::ExitOnError ExitOnErr;
122+
121123
static std::string getFormatString() {
122124
switch (FormatEnum) {
123125
case OutputFormatTy::yaml:
@@ -245,10 +247,30 @@ sortUsrToInfo(llvm::StringMap<std::unique_ptr<doc::Info>> &USRToInfo) {
245247
}
246248
}
247249

250+
static llvm::Error handleMappingFailures(llvm::Error Err) {
251+
if (!Err)
252+
return llvm::Error::success();
253+
if (IgnoreMappingFailures) {
254+
llvm::errs() << "Error mapping decls in files. Clang-doc will ignore these "
255+
"files and continue:\n"
256+
<< toString(std::move(Err)) << "\n";
257+
return llvm::Error::success();
258+
}
259+
return Err;
260+
}
261+
262+
static llvm::Error createDirectories(llvm::StringRef OutDirectory) {
263+
if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory))
264+
return llvm::createFileError(OutDirectory, Err);
265+
return llvm::Error::success();
266+
}
267+
248268
int main(int argc, const char **argv) {
249269
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
250270
std::error_code OK;
251271

272+
ExitOnErr.setBanner("clang-doc error: ");
273+
252274
const char *Overview =
253275
R"(Generates documentation from source code and comments.
254276
@@ -261,22 +283,13 @@ Example usage for a project using a compile commands database:
261283
$ clang-doc --executor=all-TUs compile_commands.json
262284
)";
263285

264-
auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
265-
argc, argv, ClangDocCategory, Overview);
266-
267-
if (!Executor) {
268-
llvm::errs() << toString(Executor.takeError()) << "\n";
269-
return 1;
270-
}
286+
auto Executor = ExitOnErr(clang::tooling::createExecutorFromCommandLineArgs(
287+
argc, argv, ClangDocCategory, Overview));
271288

272289
// Fail early if an invalid format was provided.
273290
std::string Format = getFormatString();
274291
llvm::outs() << "Emiting docs in " << Format << " format.\n";
275-
auto G = doc::findGeneratorByName(Format);
276-
if (!G) {
277-
llvm::errs() << toString(G.takeError()) << "\n";
278-
return 1;
279-
}
292+
auto G = ExitOnErr(doc::findGeneratorByName(Format));
280293

281294
ArgumentsAdjuster ArgAdjuster;
282295
if (!DoxygenOnly)
@@ -286,7 +299,7 @@ Example usage for a project using a compile commands database:
286299
ArgAdjuster);
287300

288301
clang::doc::ClangDocContext CDCtx = {
289-
Executor->get()->getExecutionContext(),
302+
Executor->getExecutionContext(),
290303
ProjectName,
291304
PublicOnly,
292305
OutDirectory,
@@ -297,40 +310,24 @@ Example usage for a project using a compile commands database:
297310
{UserStylesheets.begin(), UserStylesheets.end()}};
298311

299312
if (Format == "html") {
300-
if (auto Err = getHtmlAssetFiles(argv[0], CDCtx)) {
301-
llvm::errs() << toString(std::move(Err)) << "\n";
302-
return 1;
303-
}
313+
ExitOnErr(getHtmlAssetFiles(argv[0], CDCtx));
304314
}
305315

306316
if (Format == "mustache") {
307-
if (auto Err = getMustacheHtmlFiles(argv[0], CDCtx)) {
308-
llvm::errs() << toString(std::move(Err)) << "\n";
309-
return 1;
310-
}
317+
ExitOnErr(getMustacheHtmlFiles(argv[0], CDCtx));
311318
}
312319

313320
// Mapping phase
314321
llvm::outs() << "Mapping decls...\n";
315-
auto Err =
316-
Executor->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
317-
if (Err) {
318-
if (IgnoreMappingFailures)
319-
llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
320-
"these files and continue:\n"
321-
<< toString(std::move(Err)) << "\n";
322-
else {
323-
llvm::errs() << toString(std::move(Err)) << "\n";
324-
return 1;
325-
}
326-
}
322+
ExitOnErr(handleMappingFailures(
323+
Executor->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster)));
327324

328325
// Collect values into output by key.
329326
// In ToolResults, the Key is the hashed USR and the value is the
330327
// bitcode-encoded representation of the Info object.
331328
llvm::outs() << "Collecting infos...\n";
332329
llvm::StringMap<std::vector<StringRef>> USRToBitcode;
333-
Executor->get()->getToolResults()->forEachResult(
330+
Executor->getToolResults()->forEachResult(
334331
[&](StringRef Key, StringRef Value) {
335332
USRToBitcode[Key].emplace_back(Value);
336333
});
@@ -391,25 +388,13 @@ Example usage for a project using a compile commands database:
391388
sortUsrToInfo(USRToInfo);
392389

393390
// Ensure the root output directory exists.
394-
if (std::error_code Err = llvm::sys::fs::create_directories(OutDirectory);
395-
Err != std::error_code()) {
396-
llvm::errs() << "Failed to create directory '" << OutDirectory << "'\n";
397-
return 1;
398-
}
391+
ExitOnErr(createDirectories(OutDirectory));
399392

400393
// Run the generator.
401394
llvm::outs() << "Generating docs...\n";
402-
if (auto Err =
403-
G->get()->generateDocs(OutDirectory, std::move(USRToInfo), CDCtx)) {
404-
llvm::errs() << toString(std::move(Err)) << "\n";
405-
return 1;
406-
}
407-
395+
ExitOnErr(G->generateDocs(OutDirectory, std::move(USRToInfo), CDCtx));
408396
llvm::outs() << "Generating assets for docs...\n";
409-
Err = G->get()->createResources(CDCtx);
410-
if (Err) {
411-
llvm::outs() << "warning: " << toString(std::move(Err)) << "\n";
412-
}
397+
ExitOnErr(G->createResources(CDCtx));
413398

414399
return 0;
415400
}

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class FailedPrerequisiteModules : public PrerequisiteModules {
8484

8585
// We shouldn't adjust the compilation commands based on
8686
// FailedPrerequisiteModules.
87-
void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
88-
}
87+
void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {}
8988

9089
// FailedPrerequisiteModules can never be reused.
9190
bool
@@ -430,21 +429,21 @@ class CachingProjectModules : public ProjectModules {
430429
/// Collect the directly and indirectly required module names for \param
431430
/// ModuleName in topological order. The \param ModuleName is guaranteed to
432431
/// be the last element in \param ModuleNames.
433-
llvm::SmallVector<StringRef> getAllRequiredModules(PathRef RequiredSource,
434-
CachingProjectModules &MDB,
435-
StringRef ModuleName) {
436-
llvm::SmallVector<llvm::StringRef> ModuleNames;
432+
llvm::SmallVector<std::string> getAllRequiredModules(PathRef RequiredSource,
433+
CachingProjectModules &MDB,
434+
StringRef ModuleName) {
435+
llvm::SmallVector<std::string> ModuleNames;
437436
llvm::StringSet<> ModuleNamesSet;
438437

439438
auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void {
440439
ModuleNamesSet.insert(ModuleName);
441440

442-
for (StringRef RequiredModuleName : MDB.getRequiredModules(
441+
for (const std::string &RequiredModuleName : MDB.getRequiredModules(
443442
MDB.getSourceForModuleName(ModuleName, RequiredSource)))
444443
if (ModuleNamesSet.insert(RequiredModuleName).second)
445444
Visitor(RequiredModuleName, Visitor);
446445

447-
ModuleNames.push_back(ModuleName);
446+
ModuleNames.push_back(ModuleName.str());
448447
};
449448
VisitDeps(ModuleName, VisitDeps);
450449

@@ -494,28 +493,30 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
494493
// Get Required modules in topological order.
495494
auto ReqModuleNames = getAllRequiredModules(RequiredSource, MDB, ModuleName);
496495
for (llvm::StringRef ReqModuleName : ReqModuleNames) {
497-
if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName))
496+
if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName))
498497
continue;
499498

500499
if (auto Cached = Cache.getModule(ReqModuleName)) {
501500
if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles,
502501
TFS.view(std::nullopt))) {
503-
log("Reusing module {0} from {1}", ModuleName,
502+
log("Reusing module {0} from {1}", ReqModuleName,
504503
Cached->getModuleFilePath());
505504
BuiltModuleFiles.addModuleFile(std::move(Cached));
506505
continue;
507506
}
508507
Cache.remove(ReqModuleName);
509508
}
510509

510+
std::string ReqFileName =
511+
MDB.getSourceForModuleName(ReqModuleName, RequiredSource);
511512
llvm::Expected<ModuleFile> MF = buildModuleFile(
512-
ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles);
513+
ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles);
513514
if (llvm::Error Err = MF.takeError())
514515
return Err;
515516

516-
log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath());
517+
log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath());
517518
auto BuiltModuleFile = std::make_shared<const ModuleFile>(std::move(*MF));
518-
Cache.add(ModuleName, BuiltModuleFile);
519+
Cache.add(ReqModuleName, BuiltModuleFile);
519520
BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile));
520521
}
521522

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# A smoke test to check that a simple dependency chain for modules can work.
2+
#
3+
# RUN: rm -fr %t
4+
# RUN: mkdir -p %t
5+
# RUN: split-file %s %t
6+
#
7+
# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp
8+
# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json
9+
# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp
10+
#
11+
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
12+
# (with the extra slash in the front), so we add it here.
13+
# RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.tmp > %/t/definition.jsonrpc
14+
#
15+
# RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \
16+
# RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc
17+
18+
#--- A-frag.cppm
19+
export module A:frag;
20+
export void printA() {}
21+
22+
#--- A.cppm
23+
export module A;
24+
export import :frag;
25+
26+
#--- Use.cpp
27+
import A;
28+
void foo() {
29+
print
30+
}
31+
32+
#--- compile_commands.json.tmpl
33+
[
34+
{
35+
"directory": "DIR",
36+
"command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp",
37+
"file": "DIR/Use.cpp"
38+
},
39+
{
40+
"directory": "DIR",
41+
"command": "CLANG_CC -std=c++20 DIR/A.cppm --precompile -o DIR/A.pcm",
42+
"file": "DIR/A.cppm"
43+
},
44+
{
45+
"directory": "DIR",
46+
"command": "CLANG_CC -std=c++20 DIR/A-frag.cppm --precompile -o DIR/A-frag.pcm",
47+
"file": "DIR/A-frag.cppm"
48+
}
49+
]
50+
51+
#--- definition.jsonrpc.tmpl
52+
{
53+
"jsonrpc": "2.0",
54+
"id": 0,
55+
"method": "initialize",
56+
"params": {
57+
"processId": 123,
58+
"rootPath": "clangd",
59+
"capabilities": {
60+
"textDocument": {
61+
"completion": {
62+
"completionItem": {
63+
"snippetSupport": true
64+
}
65+
}
66+
}
67+
},
68+
"trace": "off"
69+
}
70+
}
71+
---
72+
{
73+
"jsonrpc": "2.0",
74+
"method": "textDocument/didOpen",
75+
"params": {
76+
"textDocument": {
77+
"uri": "file://DIR/Use.cpp",
78+
"languageId": "cpp",
79+
"version": 1,
80+
"text": "import A;\nvoid foo() {\n print\n}\n"
81+
}
82+
}
83+
}
84+
85+
# CHECK: "message"{{.*}}printA{{.*}}(fix available)
86+
87+
---
88+
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}}
89+
---
90+
{"jsonrpc":"2.0","id":2,"method":"shutdown"}
91+
---
92+
{"jsonrpc":"2.0","method":"exit"}

0 commit comments

Comments
 (0)