Skip to content

Commit ed65665

Browse files
committed
Merge tag 'llvmorg-20.1.7' into rustc/20.1-2025-02-13
LLVM Release 20.1.7
2 parents c1118fd + 6146a88 commit ed65665

File tree

95 files changed

+1257
-334
lines changed

Some content is hidden

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

95 files changed

+1257
-334
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/ADT/StringExtras.h"
3434
#include "llvm/ADT/StringRef.h"
3535
#include "llvm/ADT/Twine.h"
36+
#include "llvm/ADT/identity.h"
3637
#include "llvm/Support/Casting.h"
3738
#include "llvm/Support/ErrorHandling.h"
3839
#include "llvm/Support/FormatVariadic.h"
@@ -368,7 +369,11 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
368369
}
369370

370371
if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
371-
return F;
372+
// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
373+
// which has null parameters. Avoid these as they don't contain useful
374+
// information.
375+
if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>()))
376+
return F;
372377
}
373378

374379
return {};

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ void ModuleFileCache::remove(StringRef ModuleName) {
360360
/// Collect the directly and indirectly required module names for \param
361361
/// ModuleName in topological order. The \param ModuleName is guaranteed to
362362
/// be the last element in \param ModuleNames.
363-
llvm::SmallVector<StringRef> getAllRequiredModules(ProjectModules &MDB,
363+
llvm::SmallVector<std::string> getAllRequiredModules(ProjectModules &MDB,
364364
StringRef ModuleName) {
365-
llvm::SmallVector<llvm::StringRef> ModuleNames;
365+
llvm::SmallVector<std::string> ModuleNames;
366366
llvm::StringSet<> ModuleNamesSet;
367367

368368
auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void {
@@ -373,7 +373,7 @@ llvm::SmallVector<StringRef> getAllRequiredModules(ProjectModules &MDB,
373373
if (ModuleNamesSet.insert(RequiredModuleName).second)
374374
Visitor(RequiredModuleName, Visitor);
375375

376-
ModuleNames.push_back(ModuleName);
376+
ModuleNames.push_back(ModuleName.str());
377377
};
378378
VisitDeps(ModuleName, VisitDeps);
379379

@@ -418,28 +418,30 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
418418
// Get Required modules in topological order.
419419
auto ReqModuleNames = getAllRequiredModules(MDB, ModuleName);
420420
for (llvm::StringRef ReqModuleName : ReqModuleNames) {
421-
if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName))
421+
if (BuiltModuleFiles.isModuleUnitBuilt(ReqModuleName))
422422
continue;
423423

424424
if (auto Cached = Cache.getModule(ReqModuleName)) {
425425
if (IsModuleFileUpToDate(Cached->getModuleFilePath(), BuiltModuleFiles,
426426
TFS.view(std::nullopt))) {
427-
log("Reusing module {0} from {1}", ModuleName,
427+
log("Reusing module {0} from {1}", ReqModuleName,
428428
Cached->getModuleFilePath());
429429
BuiltModuleFiles.addModuleFile(std::move(Cached));
430430
continue;
431431
}
432432
Cache.remove(ReqModuleName);
433433
}
434434

435+
std::string ReqFileName =
436+
MDB.getSourceForModuleName(ReqModuleName);
435437
llvm::Expected<ModuleFile> MF = buildModuleFile(
436-
ModuleName, ModuleUnitFileName, getCDB(), TFS, BuiltModuleFiles);
438+
ReqModuleName, ReqFileName, getCDB(), TFS, BuiltModuleFiles);
437439
if (llvm::Error Err = MF.takeError())
438440
return Err;
439441

440-
log("Built module {0} to {1}", ModuleName, MF->getModuleFilePath());
442+
log("Built module {0} to {1}", ReqModuleName, MF->getModuleFilePath());
441443
auto BuiltModuleFile = std::make_shared<const ModuleFile>(std::move(*MF));
442-
Cache.add(ModuleName, BuiltModuleFile);
444+
Cache.add(ReqModuleName, BuiltModuleFile);
443445
BuiltModuleFiles.addModuleFile(std::move(BuiltModuleFile));
444446
}
445447

clang-tools-extra/clangd/ProjectModules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ProjectModules {
4242
llvm::unique_function<void(tooling::CompileCommand &, PathRef) const>;
4343

4444
virtual std::vector<std::string> getRequiredModules(PathRef File) = 0;
45-
virtual PathRef
45+
virtual std::string
4646
getSourceForModuleName(llvm::StringRef ModuleName,
4747
PathRef RequiredSrcFile = PathRef()) = 0;
4848

clang-tools-extra/clangd/ScanningProjectModules.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ModuleDependencyScanner {
6666
///
6767
/// TODO: We should handle the case that there are multiple source files
6868
/// declaring the same module.
69-
PathRef getSourceForModuleName(llvm::StringRef ModuleName) const;
69+
std::string getSourceForModuleName(llvm::StringRef ModuleName) const;
7070

7171
/// Return the direct required modules. Indirect required modules are not
7272
/// included.
@@ -140,7 +140,7 @@ void ModuleDependencyScanner::globalScan(
140140
GlobalScanned = true;
141141
}
142142

143-
PathRef ModuleDependencyScanner::getSourceForModuleName(
143+
std::string ModuleDependencyScanner::getSourceForModuleName(
144144
llvm::StringRef ModuleName) const {
145145
assert(
146146
GlobalScanned &&
@@ -189,7 +189,7 @@ class ScanningAllProjectModules : public ProjectModules {
189189

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

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,16 @@ TEST(ParameterHints, FunctionPointer) {
997997
f3_t f3;
998998
using f4_t = void(__stdcall *)(int param);
999999
f4_t f4;
1000+
__attribute__((noreturn)) f4_t f5;
10001001
void bar() {
10011002
f1($f1[[42]]);
10021003
f2($f2[[42]]);
10031004
f3($f3[[42]]);
10041005
f4($f4[[42]]);
1006+
// This one runs into an edge case in clang's type model
1007+
// and we can't extract the parameter name. But at least
1008+
// we shouldn't crash.
1009+
f5(42);
10051010
}
10061011
)cpp",
10071012
ExpectedHint{"param: ", "f1"}, ExpectedHint{"param: ", "f2"},

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ C++2c Feature Support
314314

315315
- Implemented `P3176R1 The Oxford variadic comma <https://wg21.link/P3176R1>`_
316316

317+
- The error produced when doing arithmetic operations on enums of different types
318+
can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
319+
317320
C++23 Feature Support
318321
^^^^^^^^^^^^^^^^^^^^^
319322
- Removed the restriction to literal types in constexpr functions in C++23 mode.
@@ -909,6 +912,8 @@ Bug Fixes in This Version
909912
being deleted has a potentially throwing destructor (#GH118660).
910913
- Clang now outputs correct values when #embed data contains bytes with negative
911914
signed char values (#GH102798).
915+
- Fix crash due to unknown references and pointer implementation and handling of
916+
base classes. (GH139452)
912917

913918
Bug Fixes to Compiler Builtins
914919
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1113,6 +1118,7 @@ Miscellaneous Clang Crashes Fixed
11131118

11141119
- Fixed a crash when an unscoped enumeration declared by an opaque-enum-declaration within a class template
11151120
with a dependent underlying type is subject to integral promotion. (#GH117960)
1121+
- Fix code completion crash involving PCH serialzied templates. (#GH139019)
11161122

11171123
OpenACC Specific Changes
11181124
------------------------
@@ -1467,6 +1473,9 @@ Crash and bug fixes
14671473
- The ``unix.BlockInCriticalSection`` now recognizes the ``lock()`` member function
14681474
as expected, even if it's inherited from a base class. Fixes (#GH104241).
14691475

1476+
- Fixed a crash when C++20 parenthesized initializer lists are used. This issue
1477+
was causing a crash in clang-tidy. (#GH136041)
1478+
14701479
Improvements
14711480
^^^^^^^^^^^^
14721481

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
75677567
"%sub{select_arith_conv_kind}0 "
75687568
"different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
75697569
InGroup<DeprecatedEnumEnumConversion>;
7570-
def err_conv_mixed_enum_types_cxx26 : Error<
7570+
7571+
def err_conv_mixed_enum_types: Error <
75717572
"invalid %sub{select_arith_conv_kind}0 "
75727573
"different enumeration types%diff{ ($ and $)|}1,2">;
7574+
def zzzz_warn_conv_mixed_enum_types_cxx26 : Warning <
7575+
err_conv_mixed_enum_types.Summary>,
7576+
InGroup<EnumEnumConversion>, DefaultError;
75737577

75747578
def warn_arith_conv_mixed_anon_enum_types : Warning<
75757579
warn_arith_conv_mixed_enum_types.Summary>,

clang/lib/AST/ExprConstant.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,7 +3311,11 @@ static bool HandleLValueBase(EvalInfo &Info, const Expr *E, LValue &Obj,
33113311
return false;
33123312

33133313
// Extract most-derived object and corresponding type.
3314-
DerivedDecl = D.MostDerivedType->getAsCXXRecordDecl();
3314+
// FIXME: After implementing P2280R4 it became possible to get references
3315+
// here. We do MostDerivedType->getAsCXXRecordDecl() in several other
3316+
// locations and if we see crashes in those locations in the future
3317+
// it may make more sense to move this fix into Lvalue::set.
3318+
DerivedDecl = D.MostDerivedType.getNonReferenceType()->getAsCXXRecordDecl();
33153319
if (!CastToDerivedClass(Info, E, Obj, DerivedDecl, D.MostDerivedPathLength))
33163320
return false;
33173321

@@ -3521,7 +3525,12 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
35213525
// should begin within the evaluation of E
35223526
// Used to be C++20 [expr.const]p5.12.2:
35233527
// ... its lifetime began within the evaluation of E;
3524-
if (isa<ParmVarDecl>(VD) && !AllowConstexprUnknown) {
3528+
if (isa<ParmVarDecl>(VD)) {
3529+
if (AllowConstexprUnknown) {
3530+
Result = &Info.CurrentCall->createConstexprUnknownAPValues(VD, Base);
3531+
return true;
3532+
}
3533+
35253534
// Assume parameters of a potential constant expression are usable in
35263535
// constant expressions.
35273536
if (!Info.checkingPotentialConstantExpression() ||

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,7 @@ class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
618618
DefineStd(Builder, "unix", Opts);
619619
Builder.defineMacro("__svr4__");
620620
Builder.defineMacro("__SVR4");
621-
// Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
622-
// newer, but to 500 for everything else. feature_test.h has a check to
623-
// ensure that you are not using C99 with an old version of X/Open or C89
624-
// with a new version.
625-
if (Opts.C99)
626-
Builder.defineMacro("_XOPEN_SOURCE", "600");
627-
else
628-
Builder.defineMacro("_XOPEN_SOURCE", "500");
621+
Builder.defineMacro("_XOPEN_SOURCE", "600");
629622
if (Opts.CPlusPlus) {
630623
Builder.defineMacro("__C99FEATURES__");
631624
Builder.defineMacro("_FILE_OFFSET_BITS", "64");

0 commit comments

Comments
 (0)