Skip to content

Commit 73e3098

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:52ada07ef5df2829e90ca2dd48305465a55e8121 into amd-gfx:cb528432c2ad
Local branch amd-gfx cb52843 Merged main:e8740d4eb1c88e968b155f73ac745f80b4681589 into amd-gfx:35293f0c8e63 Remote branch main 52ada07 build_llvm_release.bat: add tarball export to x64 release (llvm#79840)
2 parents cb52843 + 52ada07 commit 73e3098

File tree

243 files changed

+19356
-1471
lines changed

Some content is hidden

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

243 files changed

+19356
-1471
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ClangdServer.h"
1212
#include "ConfigProvider.h"
1313
#include "Diagnostics.h"
14+
#include "Feature.h"
1415
#include "FeatureModule.h"
1516
#include "LSPBinder.h"
1617
#include "LSPClient.h"
@@ -198,6 +199,9 @@ TEST_F(LSPTest, RecordsLatencies) {
198199
// clang-tidy's renames are converted to clangd's internal rename functionality,
199200
// see clangd#1589 and clangd#741
200201
TEST_F(LSPTest, ClangTidyRename) {
202+
// This test requires clang-tidy checks to be linked in.
203+
if (!CLANGD_TIDY_CHECKS)
204+
return;
201205
Annotations Header(R"cpp(
202206
void [[foo]]();
203207
)cpp");
@@ -214,7 +218,9 @@ TEST_F(LSPTest, ClangTidyRename) {
214218
Client.didOpen("foo.hpp", Header.code());
215219
Client.didOpen("foo.cpp", Source.code());
216220

217-
auto RenameDiag = Client.diagnostics("foo.cpp").value().at(0);
221+
auto Diags = Client.diagnostics("foo.cpp");
222+
ASSERT_TRUE(Diags && !Diags->empty());
223+
auto RenameDiag = Diags->front();
218224

219225
auto RenameCommand =
220226
(*Client

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
128128

129129
bool VisitDeclRefExpr(DeclRefExpr *DRE) {
130130
auto *FD = DRE->getFoundDecl();
131+
// Prefer the underlying decl if FoundDecl isn't a shadow decl, e.g:
132+
// - For templates, found-decl is always primary template, but we want the
133+
// specializaiton itself.
134+
if (!llvm::isa<UsingShadowDecl>(FD))
135+
FD = DRE->getDecl();
131136
// For refs to non-meber-like decls, use the found decl.
132137
// For member-like decls, we should have a reference from the qualifier to
133138
// the container decl instead, which is preferred as it'll handle

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ TEST(WalkAST, VarTemplates) {
213213
template<typename T> T* $explicit^Foo<T*> = nullptr;)cpp",
214214
"int *x = ^Foo<int *>;"),
215215
ElementsAre(Decl::VarTemplateSpecialization));
216+
// Implicit specializations through explicit instantiations has source
217+
// locations pointing at the primary template.
216218
EXPECT_THAT(testWalk(R"cpp(
217219
template<typename T> T $explicit^Foo = 0;
218220
template int Foo<int>;)cpp",
@@ -239,18 +241,19 @@ TEST(WalkAST, FunctionTemplates) {
239241
EXPECT_THAT(testWalk(R"cpp(
240242
template <typename T> void $explicit^foo() {})cpp",
241243
"auto x = []{ ^foo<int>(); };"),
242-
ElementsAre(Decl::FunctionTemplate));
243-
// FIXME: DeclRefExpr points at primary template, not the specialization.
244+
ElementsAre(Decl::Function));
244245
EXPECT_THAT(testWalk(R"cpp(
245-
template<typename T> void $explicit^foo() {}
246-
template<> void foo<int>(){})cpp",
246+
template<typename T> void foo() {}
247+
template<> void $explicit^foo<int>(){})cpp",
247248
"auto x = []{ ^foo<int>(); };"),
248-
ElementsAre(Decl::FunctionTemplate));
249+
ElementsAre(Decl::Function));
250+
// The decl is actually the specialization, but explicit instantations point
251+
// at the primary template.
249252
EXPECT_THAT(testWalk(R"cpp(
250253
template<typename T> void $explicit^foo() {};
251254
template void foo<int>();)cpp",
252255
"auto x = [] { ^foo<int>(); };"),
253-
ElementsAre(Decl::FunctionTemplate));
256+
ElementsAre(Decl::Function));
254257
}
255258
TEST(WalkAST, TemplateSpecializationsFromUsingDecl) {
256259
// Class templates
@@ -548,7 +551,8 @@ TEST(WalkAST, Concepts) {
548551
testWalk(Concept, "template<typename T> void func() requires ^Foo<T> {}");
549552
testWalk(Concept, "void func(^Foo auto x) {}");
550553
// FIXME: Foo should be explicitly referenced.
551-
testWalk("template<typename T> concept Foo = true;", "void func() { ^Foo auto x = 1; }");
554+
testWalk("template<typename T> concept Foo = true;",
555+
"void func() { ^Foo auto x = 1; }");
552556
}
553557

554558
TEST(WalkAST, FriendDecl) {

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ Bug Fixes to C++ Support
277277
(`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
278278
- Correctly immediate-escalate lambda conversion functions.
279279
(`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
280+
- Fixed an issue where template parameters of a nested abbreviated generic lambda within
281+
a requires-clause lie at the same depth as those of the surrounding lambda. This,
282+
in turn, results in the wrong template argument substitution during constraint checking.
283+
(`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_)
280284

281285
Bug Fixes to AST Handling
282286
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/StandardCPlusPlusModules.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ headers to:
868868
...
869869
#endif
870870

871+
If the modules imported by your library provides such headers too, remember to add them to
872+
your ``your_library_imported.h`` too.
873+
871874
Importing modules
872875
~~~~~~~~~~~~~~~~~
873876

clang/docs/analyzer/checkers.rst

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ Check for undefined results of binary operators.
213213
214214
core.VLASize (C)
215215
""""""""""""""""
216-
Check for declarations of Variable Length Arrays of undefined or zero size.
217-
218-
Check for declarations of VLA of undefined or zero size.
216+
Check for declarations of Variable Length Arrays (VLA) of undefined, zero or negative
217+
size.
219218
220219
.. code-block:: c
221220
@@ -229,6 +228,28 @@ Check for declarations of Variable Length Arrays of undefined or zero size.
229228
int vla2[x]; // warn: zero size
230229
}
231230
231+
232+
The checker also gives warning if the `TaintPropagation` checker is switched on
233+
and an unbound, attacker controlled (tainted) value is used to define
234+
the size of the VLA.
235+
236+
.. code-block:: c
237+
238+
void taintedVLA(void) {
239+
int x;
240+
scanf("%d", &x);
241+
int vla[x]; // Declared variable-length array (VLA) has tainted (attacker controlled) size, that can be 0 or negative
242+
}
243+
244+
void taintedVerfieidVLA(void) {
245+
int x;
246+
scanf("%d", &x);
247+
if (x<1)
248+
return;
249+
int vla[x]; // no-warning. The analyzer can prove that x must be positive.
250+
}
251+
252+
232253
.. _core-uninitialized-ArraySubscript:
233254
234255
core.uninitialized.ArraySubscript (C)

clang/include/clang/Basic/arm_sme.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ let TargetGuard = "sme" in {
142142
def SVZERO_MASK_ZA : SInst<"svzero_mask_za", "vi", "", MergeNone, "aarch64_sme_zero",
143143
[IsOverloadNone, IsStreamingCompatible, IsInOutZA],
144144
[ImmCheck<0, ImmCheck0_255>]>;
145-
def SVZERO_ZA : SInst<"svzero_za", "v", "", MergeNone, "aarch64_sme_zero",
145+
def SVZERO_ZA : SInst<"svzero_za", "vv", "", MergeNone, "aarch64_sme_zero",
146146
[IsOverloadNone, IsStreamingCompatible, IsOutZA]>;
147147
}
148148

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -691,16 +691,19 @@ class ASTUnit {
691691
/// lifetime is expected to extend past that of the returned ASTUnit.
692692
///
693693
/// \returns - The initialized ASTUnit or null if the AST failed to load.
694-
static std::unique_ptr<ASTUnit> LoadFromASTFile(
695-
const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
696-
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
697-
const FileSystemOptions &FileSystemOpts,
698-
std::shared_ptr<HeaderSearchOptions> HSOpts, bool OnlyLocalDecls = false,
699-
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
700-
bool AllowASTWithCompilerErrors = false,
701-
bool UserFilesAreVolatile = false,
702-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
703-
llvm::vfs::getRealFileSystem());
694+
static std::unique_ptr<ASTUnit>
695+
LoadFromASTFile(const std::string &Filename,
696+
const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
697+
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
698+
const FileSystemOptions &FileSystemOpts,
699+
std::shared_ptr<HeaderSearchOptions> HSOpts,
700+
std::shared_ptr<LangOptions> LangOpts = nullptr,
701+
bool OnlyLocalDecls = false,
702+
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
703+
bool AllowASTWithCompilerErrors = false,
704+
bool UserFilesAreVolatile = false,
705+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
706+
llvm::vfs::getRealFileSystem());
704707

705708
private:
706709
/// Helper function for \c LoadFromCompilerInvocation() and

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ class CompilerInstance : public ModuleLoader {
311311

312312
LangOptions &getLangOpts() { return Invocation->getLangOpts(); }
313313
const LangOptions &getLangOpts() const { return Invocation->getLangOpts(); }
314+
std::shared_ptr<LangOptions> getLangOptsPtr() const {
315+
return Invocation->getLangOptsPtr();
316+
}
314317

315318
PreprocessorOptions &getPreprocessorOpts() {
316319
return Invocation->getPreprocessorOpts();

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class CompilerInvocation : public CompilerInvocationBase {
271271
std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
272272
return PPOpts;
273273
}
274+
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
274275
/// @}
275276

276277
/// Create a compiler invocation from a list of input options.

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8540,7 +8540,7 @@ class Sema final {
85408540
/// if the arguments are dependent.
85418541
ExprResult CheckVarTemplateId(const CXXScopeSpec &SS,
85428542
const DeclarationNameInfo &NameInfo,
8543-
VarTemplateDecl *Template,
8543+
VarTemplateDecl *Template, NamedDecl *FoundD,
85448544
SourceLocation TemplateLoc,
85458545
const TemplateArgumentListInfo *TemplateArgs);
85468546

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,12 @@ template <class Emitter>
25102510
bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
25112511
assert(!VD->isInvalidDecl() && "Trying to constant evaluate an invalid decl");
25122512

2513+
// Global variable we've already seen but that's uninitialized means
2514+
// evaluating the initializer failed. Just return failure.
2515+
if (std::optional<unsigned> Index = P.getGlobal(VD);
2516+
Index && !P.getPtrGlobal(*Index).isInitialized())
2517+
return false;
2518+
25132519
// Create and initialize the variable.
25142520
if (!this->visitVarDecl(VD))
25152521
return false;

clang/lib/AST/Interp/Descriptor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ struct Descriptor final {
213213
bool isRecord() const { return !IsArray && ElemRecord; }
214214
/// Checks if this is a dummy descriptor.
215215
bool isDummy() const { return IsDummy; }
216+
217+
void dump() const;
218+
void dump(llvm::raw_ostream &OS) const;
216219
};
217220

218221
/// Bitfield tracking the initialisation status of elements of primitive arrays.

clang/lib/AST/Interp/Disasm.cpp

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Opcode.h"
1717
#include "PrimType.h"
1818
#include "Program.h"
19+
#include "clang/AST/ASTDumperUtils.h"
1920
#include "clang/AST/DeclCXX.h"
2021
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/Format.h"
@@ -55,7 +56,10 @@ inline IntegralAP<true> ReadArg<IntegralAP<true>>(Program &P, CodePtr &OpPC) {
5556
LLVM_DUMP_METHOD void Function::dump() const { dump(llvm::errs()); }
5657

5758
LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
58-
OS << getName() << " " << (const void *)this << "\n";
59+
{
60+
ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_GREEN, true});
61+
OS << getName() << " " << (const void *)this << "\n";
62+
}
5963
OS << "frame size: " << getFrameSize() << "\n";
6064
OS << "arg size: " << getArgSize() << "\n";
6165
OS << "rvo: " << hasRVO() << "\n";
@@ -83,14 +87,75 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) const {
8387
LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
8488

8589
LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
86-
OS << ":: Program\n";
87-
OS << "Global Variables: " << Globals.size() << "\n";
88-
OS << "Functions: " << Funcs.size() << "\n";
89-
OS << "\n";
90-
for (auto &Func : Funcs) {
90+
{
91+
ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_RED, true});
92+
OS << "\n:: Program\n";
93+
}
94+
95+
{
96+
ColorScope SC(OS, true, {llvm::raw_ostream::WHITE, true});
97+
OS << "Total memory : " << Allocator.getTotalMemory() << " bytes\n";
98+
OS << "Global Variables: " << Globals.size() << "\n";
99+
}
100+
unsigned GI = 0;
101+
for (const Global *G : Globals) {
102+
const Descriptor *Desc = G->block()->getDescriptor();
103+
OS << GI << ": " << (void *)G->block() << " ";
104+
{
105+
Pointer GP = getPtrGlobal(GI);
106+
ColorScope SC(OS, true,
107+
GP.isInitialized()
108+
? TerminalColor{llvm::raw_ostream::GREEN, false}
109+
: TerminalColor{llvm::raw_ostream::RED, false});
110+
OS << (GP.isInitialized() ? "initialized " : "uninitialized ");
111+
}
112+
Desc->dump(OS);
113+
OS << "\n";
114+
++GI;
115+
}
116+
117+
{
118+
ColorScope SC(OS, true, {llvm::raw_ostream::WHITE, true});
119+
OS << "Functions: " << Funcs.size() << "\n";
120+
}
121+
for (const auto &Func : Funcs) {
91122
Func.second->dump();
92123
}
93-
for (auto &Anon : AnonFuncs) {
124+
for (const auto &Anon : AnonFuncs) {
94125
Anon->dump();
95126
}
96127
}
128+
129+
LLVM_DUMP_METHOD void Descriptor::dump() const {
130+
dump(llvm::errs());
131+
llvm::errs() << '\n';
132+
}
133+
134+
LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const {
135+
// Source
136+
{
137+
ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});
138+
if (const auto *ND = dyn_cast_if_present<NamedDecl>(asDecl()))
139+
OS << ND->getName();
140+
else if (asExpr())
141+
OS << "expr (TODO)";
142+
}
143+
144+
// Print a few interesting bits about the descriptor.
145+
if (isPrimitiveArray())
146+
OS << " primitive-array";
147+
else if (isCompositeArray())
148+
OS << " composite-array";
149+
else if (isRecord())
150+
OS << " record";
151+
else if (isPrimitive())
152+
OS << " primitive";
153+
154+
if (isZeroSizeArray())
155+
OS << " zero-size-arrary";
156+
else if (isUnknownSizeArray())
157+
OS << " unknown-size-array";
158+
159+
if (isDummy())
160+
OS << " dummy";
161+
}

clang/lib/AST/Interp/Interp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
462462
if (S.getLangOpts().CPlusPlus11) {
463463
const FunctionDecl *DiagDecl = F->getDecl();
464464

465+
// Invalid decls have been diagnosed before.
466+
if (DiagDecl->isInvalidDecl())
467+
return false;
468+
465469
// If this function is not constexpr because it is an inherited
466470
// non-constexpr constructor, diagnose that directly.
467471
const auto *CD = dyn_cast<CXXConstructorDecl>(DiagDecl);

clang/lib/AST/Interp/Program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
102102
return I;
103103
}
104104

105-
Pointer Program::getPtrGlobal(unsigned Idx) {
105+
Pointer Program::getPtrGlobal(unsigned Idx) const {
106106
assert(Idx < Globals.size());
107107
return Pointer(Globals[Idx]->block());
108108
}

clang/lib/AST/Interp/Program.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Program final {
6767
unsigned createGlobalString(const StringLiteral *S);
6868

6969
/// Returns a pointer to a global.
70-
Pointer getPtrGlobal(unsigned Idx);
70+
Pointer getPtrGlobal(unsigned Idx) const;
7171

7272
/// Returns the value of a global.
7373
Block *getGlobal(unsigned Idx) {
@@ -190,6 +190,7 @@ class Program final {
190190
std::byte *data() { return B.data(); }
191191
/// Return a pointer to the block.
192192
Block *block() { return &B; }
193+
const Block *block() const { return &B; }
193194

194195
private:
195196
/// Required metadata - does not actually track pointers.

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,13 @@ StringRef AArch64TargetInfo::getFeatureDependencies(StringRef Name) const {
667667
}
668668

669669
bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
670-
return llvm::AArch64::parseArchExtension(FeatureStr).has_value();
670+
// CPU features might be separated by '+', extract them and check
671+
llvm::SmallVector<StringRef, 8> Features;
672+
FeatureStr.split(Features, "+");
673+
for (auto &Feature : Features)
674+
if (!llvm::AArch64::parseArchExtension(Feature.trim()).has_value())
675+
return false;
676+
return true;
671677
}
672678

673679
bool AArch64TargetInfo::hasFeature(StringRef Feature) const {

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
165165
DiagnosticsEngine &Diags) override;
166166
ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
167167
bool supportsTargetAttributeTune() const override { return true; }
168-
168+
bool supportsCpuSupports() const override { return true; }
169169
bool checkArithmeticFenceSupported() const override { return true; }
170170

171171
bool hasBFloat16Type() const override;

0 commit comments

Comments
 (0)