Skip to content

Commit 4c4c739

Browse files
committed
merge main into amd-staging
2 parents 78664df + d5d6f60 commit 4c4c739

File tree

28 files changed

+1200
-45
lines changed

28 files changed

+1200
-45
lines changed

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ class CachingProjectModules : public ProjectModules {
430430
/// Collect the directly and indirectly required module names for \param
431431
/// ModuleName in topological order. The \param ModuleName is guaranteed to
432432
/// 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;
433+
llvm::SmallVector<std::string> getAllRequiredModules(PathRef RequiredSource,
434+
CachingProjectModules &MDB,
435+
StringRef ModuleName) {
436+
llvm::SmallVector<std::string> ModuleNames;
437437
llvm::StringSet<> ModuleNamesSet;
438438

439439
auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void {
@@ -444,7 +444,7 @@ llvm::SmallVector<StringRef> getAllRequiredModules(PathRef RequiredSource,
444444
if (ModuleNamesSet.insert(RequiredModuleName).second)
445445
Visitor(RequiredModuleName, Visitor);
446446

447-
ModuleNames.push_back(ModuleName);
447+
ModuleNames.push_back(ModuleName.str());
448448
};
449449
VisitDeps(ModuleName, VisitDeps);
450450

@@ -494,28 +494,30 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
494494
// Get Required modules in topological order.
495495
auto ReqModuleNames = getAllRequiredModules(RequiredSource, MDB, ModuleName);
496496
for (llvm::StringRef ReqModuleName : ReqModuleNames) {
497-
if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName))
497+
if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName))
498498
continue;
499499

500500
if (auto Cached = Cache.getModule(ReqModuleName)) {
501501
if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles,
502502
TFS.view(std::nullopt))) {
503-
log("Reusing module {0} from {1}", ModuleName,
503+
log("Reusing module {0} from {1}", ReqModuleName,
504504
Cached->getModuleFilePath());
505505
BuiltModuleFiles.addModuleFile(std::move(Cached));
506506
continue;
507507
}
508508
Cache.remove(ReqModuleName);
509509
}
510510

511+
std::string ReqFileName =
512+
MDB.getSourceForModuleName(ReqModuleName, RequiredSource);
511513
llvm::Expected<ModuleFile> MF = buildModuleFile(
512-
ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles);
514+
ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles);
513515
if (llvm::Error Err = MF.takeError())
514516
return Err;
515517

516-
log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath());
518+
log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath());
517519
auto BuiltModuleFile = std::make_shared<const ModuleFile>(std::move(*MF));
518-
Cache.add(ModuleName, BuiltModuleFile);
520+
Cache.add(ReqModuleName, BuiltModuleFile);
519521
BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile));
520522
}
521523

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

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,6 +3485,7 @@ bool UnwrappedLineParser::parseRequires(bool SeenEqual) {
34853485
case tok::r_paren:
34863486
case tok::kw_noexcept:
34873487
case tok::kw_const:
3488+
case tok::star:
34883489
case tok::amp:
34893490
// This is a requires clause.
34903491
parseRequiresClause(RequiresToken);

clang/test/Misc/target-invalid-cpu-note/riscv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
// TUNE-RISCV32-SAME: {{^}}, syntacore-scr3-rv32
7878
// TUNE-RISCV32-SAME: {{^}}, syntacore-scr4-rv32
7979
// TUNE-RISCV32-SAME: {{^}}, syntacore-scr5-rv32
80+
// TUNE-RISCV32-SAME: {{^}}, andes-45-series
8081
// TUNE-RISCV32-SAME: {{^}}, generic
8182
// TUNE-RISCV32-SAME: {{^}}, generic-ooo
8283
// TUNE-RISCV32-SAME: {{^}}, rocket
@@ -114,6 +115,7 @@
114115
// TUNE-RISCV64-SAME: {{^}}, veyron-v1
115116
// TUNE-RISCV64-SAME: {{^}}, xiangshan-kunminghu
116117
// TUNE-RISCV64-SAME: {{^}}, xiangshan-nanhu
118+
// TUNE-RISCV64-SAME: {{^}}, andes-45-series
117119
// TUNE-RISCV64-SAME: {{^}}, generic
118120
// TUNE-RISCV64-SAME: {{^}}, generic-ooo
119121
// TUNE-RISCV64-SAME: {{^}}, rocket

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,15 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
14531453
ASSERT_EQ(Tokens.size(), 17u) << Tokens;
14541454
EXPECT_TOKEN(Tokens[4], tok::ampamp, TT_PointerOrReference);
14551455
EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
1456+
1457+
Tokens = annotate("auto foo() -> auto *\n"
1458+
" requires(not bar)\n"
1459+
"{\n"
1460+
" return baz;\n"
1461+
"}");
1462+
ASSERT_EQ(Tokens.size(), 18u) << Tokens;
1463+
EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
1464+
EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
14561465
}
14571466

14581467
TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

lld/ELF/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ struct Config {
235235
ReportPolicy zGcsReport = ReportPolicy::None;
236236
ReportPolicy zGcsReportDynamic = ReportPolicy::None;
237237
ReportPolicy zExecuteOnlyReport = ReportPolicy::None;
238+
ReportPolicy zZicfilpUnlabeledReport = ReportPolicy::None;
239+
ReportPolicy zZicfilpFuncSigReport = ReportPolicy::None;
240+
ReportPolicy zZicfissReport = ReportPolicy::None;
238241
bool ltoBBAddrMap;
239242
llvm::StringRef ltoBasicBlockSections;
240243
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;

lld/ELF/Driver.cpp

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,18 @@ static void checkOptions(Ctx &ctx) {
419419
<< "--pcrel-optimize is only supported on PowerPC64 targets";
420420
}
421421

422-
if (ctx.arg.relaxGP && ctx.arg.emachine != EM_RISCV)
423-
ErrAlways(ctx) << "--relax-gp is only supported on RISC-V targets";
422+
if (ctx.arg.emachine != EM_RISCV) {
423+
if (ctx.arg.relaxGP)
424+
ErrAlways(ctx) << "--relax-gp is only supported on RISC-V targets";
425+
if (ctx.arg.zZicfilpUnlabeledReport != ReportPolicy::None)
426+
ErrAlways(ctx) << "-z zicfilip-unlabeled-report is only supported on "
427+
"RISC-V targets";
428+
if (ctx.arg.zZicfilpFuncSigReport != ReportPolicy::None)
429+
ErrAlways(ctx) << "-z zicfilip-func-sig-report is only supported on "
430+
"RISC-V targets";
431+
if (ctx.arg.zZicfissReport != ReportPolicy::None)
432+
ErrAlways(ctx) << "-z zicfiss-report is only supported on RISC-V targets";
433+
}
424434

425435
if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 &&
426436
ctx.arg.zCetReport != ReportPolicy::None)
@@ -1648,7 +1658,11 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16481658
std::make_pair("execute-only-report", &ctx.arg.zExecuteOnlyReport),
16491659
std::make_pair("gcs-report", &ctx.arg.zGcsReport),
16501660
std::make_pair("gcs-report-dynamic", &ctx.arg.zGcsReportDynamic),
1651-
std::make_pair("pauth-report", &ctx.arg.zPauthReport)};
1661+
std::make_pair("pauth-report", &ctx.arg.zPauthReport),
1662+
std::make_pair("zicfilp-unlabeled-report",
1663+
&ctx.arg.zZicfilpUnlabeledReport),
1664+
std::make_pair("zicfilp-func-sig-report", &ctx.arg.zZicfilpFuncSigReport),
1665+
std::make_pair("zicfiss-report", &ctx.arg.zZicfissReport)};
16521666
bool hasGcsReportDynamic = false;
16531667
for (opt::Arg *arg : args.filtered(OPT_z)) {
16541668
std::pair<StringRef, StringRef> option =
@@ -2842,9 +2856,12 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
28422856
// For AArch64 PAuth-enabled object files, the core info of all of them must
28432857
// match. Missing info for some object files with matching info for remaining
28442858
// ones can be allowed (see -z pauth-report).
2859+
//
2860+
// RISC-V Zicfilp/Zicfiss extension also use the same mechanism to record
2861+
// enabled features in the GNU_PROPERTY_RISCV_FEATURE_1_AND bit mask.
28452862
static void readSecurityNotes(Ctx &ctx) {
28462863
if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 &&
2847-
ctx.arg.emachine != EM_AARCH64)
2864+
ctx.arg.emachine != EM_AARCH64 && ctx.arg.emachine != EM_RISCV)
28482865
return;
28492866

28502867
ctx.arg.andFeatures = -1;
@@ -2896,6 +2913,33 @@ static void readSecurityNotes(Ctx &ctx) {
28962913
<< ": -z cet-report: file does not have "
28972914
"GNU_PROPERTY_X86_FEATURE_1_SHSTK property";
28982915

2916+
if (ctx.arg.emachine == EM_RISCV) {
2917+
reportUnless(ctx.arg.zZicfilpUnlabeledReport,
2918+
features & GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED)
2919+
<< f
2920+
<< ": -z zicfilp-unlabeled-report: file does not have "
2921+
"GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED property";
2922+
2923+
reportUnless(ctx.arg.zZicfilpFuncSigReport,
2924+
features & GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG)
2925+
<< f
2926+
<< ": -z zicfilp-func-sig-report: file does not have "
2927+
"GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG property";
2928+
2929+
if ((features & GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED) &&
2930+
(features & GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG))
2931+
Err(ctx) << f
2932+
<< ": file has conflicting properties: "
2933+
"GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED and "
2934+
"GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG";
2935+
2936+
reportUnless(ctx.arg.zZicfissReport,
2937+
features & GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS)
2938+
<< f
2939+
<< ": -z zicfiss-report: file does not have "
2940+
"GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS property";
2941+
}
2942+
28992943
if (ctx.arg.zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
29002944
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
29012945
if (ctx.arg.zBtiReport == ReportPolicy::None)

lld/ELF/InputFiles.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ static void parseGnuPropertyNote(Ctx &ctx, ELFFileBase &f,
968968
}
969969
// Read the following info from the .note.gnu.property section and write it to
970970
// the corresponding fields in `ObjFile`:
971-
// - Feature flags (32 bits) representing x86 or AArch64 features for
971+
// - Feature flags (32 bits) representing x86, AArch64 or RISC-V features for
972972
// hardware-assisted call flow control;
973973
// - AArch64 PAuth ABI core info (16 bytes).
974974
template <class ELFT>
@@ -977,6 +977,22 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
977977
using Elf_Nhdr = typename ELFT::Nhdr;
978978
using Elf_Note = typename ELFT::Note;
979979

980+
uint32_t featureAndType;
981+
switch (ctx.arg.emachine) {
982+
case EM_386:
983+
case EM_X86_64:
984+
featureAndType = GNU_PROPERTY_X86_FEATURE_1_AND;
985+
break;
986+
case EM_AARCH64:
987+
featureAndType = GNU_PROPERTY_AARCH64_FEATURE_1_AND;
988+
break;
989+
case EM_RISCV:
990+
featureAndType = GNU_PROPERTY_RISCV_FEATURE_1_AND;
991+
break;
992+
default:
993+
return;
994+
}
995+
980996
ArrayRef<uint8_t> data = sec.content();
981997
auto err = [&](const uint8_t *place) -> ELFSyncStream {
982998
auto diag = Err(ctx);
@@ -997,10 +1013,6 @@ static void readGnuProperty(Ctx &ctx, const InputSection &sec,
9971013
continue;
9981014
}
9991015

1000-
uint32_t featureAndType = ctx.arg.emachine == EM_AARCH64
1001-
? GNU_PROPERTY_AARCH64_FEATURE_1_AND
1002-
: GNU_PROPERTY_X86_FEATURE_1_AND;
1003-
10041016
// Read a body of a NOTE record, which consists of type-length-value fields.
10051017
ArrayRef<uint8_t> desc = note.getDesc(sec.addralign);
10061018
const uint8_t *base = sec.content().data();
@@ -1064,9 +1076,9 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
10641076
}
10651077

10661078
// Object files that use processor features such as Intel Control-Flow
1067-
// Enforcement (CET) or AArch64 Branch Target Identification BTI, use a
1068-
// .note.gnu.property section containing a bitfield of feature bits like the
1069-
// GNU_PROPERTY_X86_FEATURE_1_IBT flag. Read a bitmap containing the flag.
1079+
// Enforcement (CET), AArch64 Branch Target Identification BTI or RISC-V
1080+
// Zicfilp/Zicfiss extensions, use a .note.gnu.property section containing
1081+
// a bitfield of feature bits like the GNU_PROPERTY_X86_FEATURE_1_IBT flag.
10701082
//
10711083
// Since we merge bitmaps from multiple object files to create a new
10721084
// .note.gnu.property containing a single AND'ed bitmap, we discard an input

lld/ELF/SyntheticSections.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,28 @@ GnuPropertySection::GnuPropertySection(Ctx &ctx)
322322
ctx.arg.wordsize) {}
323323

324324
void GnuPropertySection::writeTo(uint8_t *buf) {
325+
uint32_t featureAndType;
326+
switch (ctx.arg.emachine) {
327+
case EM_386:
328+
case EM_X86_64:
329+
featureAndType = GNU_PROPERTY_X86_FEATURE_1_AND;
330+
break;
331+
case EM_AARCH64:
332+
featureAndType = GNU_PROPERTY_AARCH64_FEATURE_1_AND;
333+
break;
334+
case EM_RISCV:
335+
featureAndType = GNU_PROPERTY_RISCV_FEATURE_1_AND;
336+
break;
337+
default:
338+
llvm_unreachable(
339+
"target machine does not support .note.gnu.property section");
340+
}
341+
325342
write32(ctx, buf, 4); // Name size
326343
write32(ctx, buf + 4, getSize() - 16); // Content size
327344
write32(ctx, buf + 8, NT_GNU_PROPERTY_TYPE_0); // Type
328345
memcpy(buf + 12, "GNU", 4); // Name string
329346

330-
uint32_t featureAndType = ctx.arg.emachine == EM_AARCH64
331-
? GNU_PROPERTY_AARCH64_FEATURE_1_AND
332-
: GNU_PROPERTY_X86_FEATURE_1_AND;
333-
334347
unsigned offset = 16;
335348
if (ctx.arg.andFeatures != 0) {
336349
write32(ctx, buf + offset + 0, featureAndType); // Feature type

0 commit comments

Comments
 (0)