Skip to content

Commit e740f93

Browse files
authored
Merge branch 'llvm:main' into implement-dynamic-pack-lowering
2 parents e68b32e + a8081ed commit e740f93

File tree

739 files changed

+19396
-7386
lines changed

Some content is hidden

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

739 files changed

+19396
-7386
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Martin Storsjö <[email protected]>
4343
Med Ismail Bennani <[email protected]> <[email protected]>
4444
Med Ismail Bennani <[email protected]> <[email protected]>
4545
Ramkumar Ramachandra <[email protected]> <[email protected]>
46+
Ramkumar Ramachandra <[email protected]> <[email protected]>
4647
Saleem Abdulrasool <[email protected]>
4748
4849
Wang Pengcheng <[email protected]>

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "llvm/Support/MemoryBuffer.h"
2929
#include "llvm/Support/Path.h"
3030
#include "llvm/Support/Program.h"
31-
#include "llvm/TargetParser/Host.h"
3231
#include <iterator>
3332
#include <optional>
3433
#include <string>
@@ -187,12 +186,6 @@ static std::string resolveDriver(llvm::StringRef Driver, bool FollowSymlink,
187186

188187
} // namespace
189188

190-
CommandMangler::CommandMangler() {
191-
Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
192-
? llvm::cl::TokenizeWindowsCommandLine
193-
: llvm::cl::TokenizeGNUCommandLine;
194-
}
195-
196189
CommandMangler CommandMangler::detect() {
197190
CommandMangler Result;
198191
Result.ClangPath = detectClangPath();
@@ -213,14 +206,6 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
213206
if (Cmd.empty())
214207
return;
215208

216-
// FS used for expanding response files.
217-
// FIXME: ExpandResponseFiles appears not to provide the usual
218-
// thread-safety guarantees, as the access to FS is not locked!
219-
// For now, use the real FS, which is known to be threadsafe (if we don't
220-
// use/change working directory, which ExpandResponseFiles doesn't).
221-
auto FS = llvm::vfs::getRealFileSystem();
222-
tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
223-
224209
auto &OptTable = clang::driver::getDriverOptTable();
225210
// OriginalArgs needs to outlive ArgList.
226211
llvm::SmallVector<const char *, 16> OriginalArgs;

clang-tools-extra/clangd/CompileCommands.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ struct CommandMangler {
5151
llvm::StringRef TargetFile) const;
5252

5353
private:
54-
CommandMangler();
55-
5654
Memoize<llvm::StringMap<std::string>> ResolvedDrivers;
5755
Memoize<llvm::StringMap<std::string>> ResolvedDriversNoFollow;
58-
llvm::cl::TokenizerCallback Tokenizer;
5956
};
6057

6158
// Removes args from a command-line in a semantically-aware way.

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#include "clang/Tooling/CompilationDatabase.h"
1919
#include "clang/Tooling/CompilationDatabasePluginRegistry.h"
2020
#include "clang/Tooling/JSONCompilationDatabase.h"
21+
#include "clang/Tooling/Tooling.h"
2122
#include "llvm/ADT/PointerIntPair.h"
2223
#include "llvm/ADT/STLExtras.h"
2324
#include "llvm/ADT/ScopeExit.h"
2425
#include "llvm/ADT/SmallString.h"
2526
#include "llvm/ADT/StringMap.h"
2627
#include "llvm/Support/Path.h"
2728
#include "llvm/Support/VirtualFileSystem.h"
29+
#include "llvm/TargetParser/Host.h"
2830
#include <atomic>
2931
#include <chrono>
3032
#include <condition_variable>
@@ -244,7 +246,16 @@ static std::unique_ptr<tooling::CompilationDatabase>
244246
parseJSON(PathRef Path, llvm::StringRef Data, std::string &Error) {
245247
if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
246248
Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
247-
return tooling::inferMissingCompileCommands(std::move(CDB));
249+
// FS used for expanding response files.
250+
// FIXME: ExpandResponseFilesDatabase appears not to provide the usual
251+
// thread-safety guarantees, as the access to FS is not locked!
252+
// For now, use the real FS, which is known to be threadsafe (if we don't
253+
// use/change working directory, which ExpandResponseFilesDatabase doesn't).
254+
// NOTE: response files have to be expanded before inference because
255+
// inference needs full command line to check/fix driver mode and file type.
256+
auto FS = llvm::vfs::getRealFileSystem();
257+
return tooling::inferMissingCompileCommands(
258+
expandResponseFiles(std::move(CDB), std::move(FS)));
248259
}
249260
return nullptr;
250261
}
@@ -744,6 +755,22 @@ OverlayCDB::getCompileCommand(PathRef File) const {
744755
if (It != Commands.end())
745756
Cmd = It->second;
746757
}
758+
if (Cmd) {
759+
// FS used for expanding response files.
760+
// FIXME: ExpandResponseFiles appears not to provide the usual
761+
// thread-safety guarantees, as the access to FS is not locked!
762+
// For now, use the real FS, which is known to be threadsafe (if we don't
763+
// use/change working directory, which ExpandResponseFiles doesn't).
764+
auto FS = llvm::vfs::getRealFileSystem();
765+
auto Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
766+
? llvm::cl::TokenizeWindowsCommandLine
767+
: llvm::cl::TokenizeGNUCommandLine;
768+
// Compile command pushed via LSP protocol may have response files that need
769+
// to be expanded before further processing. For CDB for files it happens in
770+
// the main CDB when reading it from the JSON file.
771+
tooling::addExpandedResponseFiles(Cmd->CommandLine, Cmd->Directory,
772+
Tokenizer, *FS);
773+
}
747774
if (!Cmd)
748775
Cmd = DelegatingCDB::getCompileCommand(File);
749776
if (!Cmd)

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,6 @@ TEST(CommandMangler, ConfigEdits) {
209209
ElementsAre(_, "--driver-mode=g++", "--hello", "--", "FOO.CC"));
210210
}
211211

212-
TEST(CommandMangler, ExpandedResponseFiles) {
213-
SmallString<1024> Path;
214-
int FD;
215-
ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("args", "", FD, Path));
216-
llvm::raw_fd_ostream OutStream(FD, true);
217-
OutStream << "-Wall";
218-
OutStream.close();
219-
220-
auto Mangler = CommandMangler::forTests();
221-
tooling::CompileCommand Cmd;
222-
Cmd.CommandLine = {"clang", ("@" + Path).str(), "foo.cc"};
223-
Mangler(Cmd, "foo.cc");
224-
EXPECT_THAT(Cmd.CommandLine, ElementsAre(_, "-Wall", "--", "foo.cc"));
225-
}
226-
227212
static std::string strip(llvm::StringRef Arg, llvm::StringRef Argv) {
228213
llvm::SmallVector<llvm::StringRef> Parts;
229214
llvm::SplitString(Argv, Parts);

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ TEST_F(OverlayCDBTest, Adjustments) {
163163
"-DFallback", "-DAdjust_baz.cc"));
164164
}
165165

166+
TEST_F(OverlayCDBTest, ExpandedResponseFiles) {
167+
SmallString<1024> Path;
168+
int FD;
169+
ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("args", "", FD, Path));
170+
llvm::raw_fd_ostream OutStream(FD, true);
171+
OutStream << "-Wall";
172+
OutStream.close();
173+
174+
OverlayCDB CDB(Base.get(), {"-DFallback"});
175+
auto Override = cmd(testPath("foo.cc"), ("@" + Path).str());
176+
CDB.setCompileCommand(testPath("foo.cc"), Override);
177+
EXPECT_THAT(CDB.getCompileCommand(testPath("foo.cc"))->CommandLine,
178+
Contains("-Wall"));
179+
}
180+
166181
TEST(GlobalCompilationDatabaseTest, DiscoveryWithNestedCDBs) {
167182
const char *const CDBOuter =
168183
R"cdb(
@@ -421,6 +436,45 @@ TEST_F(OverlayCDBTest, GetProjectInfo) {
421436
EXPECT_EQ(DB.getProjectInfo(File)->SourceRoot, testRoot());
422437
EXPECT_EQ(DB.getProjectInfo(Header)->SourceRoot, testRoot());
423438
}
439+
440+
TEST(GlobalCompilationDatabaseTest, InferenceWithResponseFile) {
441+
MockFS FS;
442+
auto Command = [&](llvm::StringRef Relative) {
443+
DirectoryBasedGlobalCompilationDatabase::Options Opts(FS);
444+
return DirectoryBasedGlobalCompilationDatabase(Opts)
445+
.getCompileCommand(testPath(Relative))
446+
.value_or(tooling::CompileCommand())
447+
.CommandLine;
448+
};
449+
EXPECT_THAT(Command("foo.cc"), IsEmpty());
450+
451+
// Have to use real FS for response file.
452+
SmallString<1024> Path;
453+
int FD;
454+
ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("args", "", FD, Path));
455+
llvm::raw_fd_ostream OutStream(FD, true);
456+
OutStream << "-DXYZZY";
457+
OutStream.close();
458+
459+
const char *const CDB =
460+
R"cdb(
461+
[
462+
{
463+
"file": "{0}/foo.cc",
464+
"command": "clang @{1} {0}/foo.cc",
465+
"directory": "{0}",
466+
}
467+
]
468+
)cdb";
469+
FS.Files[testPath("compile_commands.json")] =
470+
llvm::formatv(CDB, llvm::sys::path::convert_to_slash(testRoot()),
471+
llvm::sys::path::convert_to_slash(Path));
472+
473+
// File from CDB.
474+
EXPECT_THAT(Command("foo.cc"), Contains("-DXYZZY"));
475+
// File not in CDB, use inference.
476+
EXPECT_THAT(Command("foo.h"), Contains("-DXYZZY"));
477+
}
424478
} // namespace
425479

426480
// Friend test has access to internals.

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ C Language Changes
199199
- ``structs``, ``unions``, and ``arrays`` that are const may now be used as
200200
constant expressions. This change is more consistent with the behavior of
201201
GCC.
202-
- Clang now supports the C-only attribute ``counted_by``. When applied to a
203-
struct's flexible array member, it points to the struct field that holds the
204-
number of elements in the flexible array member. This information can improve
205-
the results of the array bound sanitizer and the
206-
``__builtin_dynamic_object_size`` builtin.
207202
- Enums will now be represented in TBAA metadata using their actual underlying
208203
integer type. Previously they were treated as chars, which meant they could
209204
alias with all other types.
@@ -691,6 +686,9 @@ Bug Fixes in This Version
691686
- Fix an issue where clang doesn't respect detault template arguments that
692687
are added in a later redeclaration for CTAD.
693688
Fixes (#69987 <https://github.com/llvm/llvm-project/issues/69987>`_)
689+
- Fix an issue where CTAD fails for explicit type conversion.
690+
Fixes (#64347 <https://github.com/llvm/llvm-project/issues/64347>`_)
691+
694692

695693
Bug Fixes to Compiler Builtins
696694
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ class NamedDecl : public Decl {
358358
///
359359
/// \param IsKnownNewer \c true if this declaration is known to be newer
360360
/// than \p OldD (for instance, if this declaration is newly-created).
361-
bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
361+
bool declarationReplaces(const NamedDecl *OldD,
362+
bool IsKnownNewer = true) const;
362363

363364
/// Determine whether this declaration has linkage.
364365
bool hasLinkage() const;
@@ -4332,30 +4333,6 @@ class RecordDecl : public TagDecl {
43324333
return field_begin() == field_end();
43334334
}
43344335

4335-
FieldDecl *getLastField() {
4336-
FieldDecl *FD = nullptr;
4337-
for (FieldDecl *Field : fields())
4338-
FD = Field;
4339-
return FD;
4340-
}
4341-
const FieldDecl *getLastField() const {
4342-
return const_cast<RecordDecl *>(this)->getLastField();
4343-
}
4344-
4345-
template <typename Functor>
4346-
const FieldDecl *findFieldIf(Functor &Pred) const {
4347-
for (const Decl *D : decls()) {
4348-
if (const auto *FD = dyn_cast<FieldDecl>(D); FD && Pred(FD))
4349-
return FD;
4350-
4351-
if (const auto *RD = dyn_cast<RecordDecl>(D))
4352-
if (const FieldDecl *FD = RD->findFieldIf(Pred))
4353-
return FD;
4354-
}
4355-
4356-
return nullptr;
4357-
}
4358-
43594336
/// Note that the definition of this type is now complete.
43604337
virtual void completeDefinition();
43614338

clang/include/clang/AST/DeclBase.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "clang/AST/SelectorLocationsKind.h"
2020
#include "clang/Basic/IdentifierTable.h"
2121
#include "clang/Basic/LLVM.h"
22-
#include "clang/Basic/LangOptions.h"
2322
#include "clang/Basic/SourceLocation.h"
2423
#include "clang/Basic/Specifiers.h"
2524
#include "llvm/ADT/ArrayRef.h"
@@ -489,15 +488,6 @@ class alignas(8) Decl {
489488
// Return true if this is a FileContext Decl.
490489
bool isFileContextDecl() const;
491490

492-
/// Whether it resembles a flexible array member. This is a static member
493-
/// because we want to be able to call it with a nullptr. That allows us to
494-
/// perform non-Decl specific checks based on the object's type and strict
495-
/// flex array level.
496-
static bool isFlexibleArrayMemberLike(
497-
ASTContext &Context, const Decl *D, QualType Ty,
498-
LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
499-
bool IgnoreTemplateOrMacroSubstitution);
500-
501491
ASTContext &getASTContext() const LLVM_READONLY;
502492

503493
/// Helper to get the language options from the ASTContext.

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,24 +4331,6 @@ def AvailableOnlyInDefaultEvalMethod : InheritableAttr {
43314331
let Documentation = [Undocumented];
43324332
}
43334333

4334-
def CountedBy : InheritableAttr {
4335-
let Spellings = [Clang<"counted_by">];
4336-
let Subjects = SubjectList<[Field]>;
4337-
let Args = [IdentifierArgument<"CountedByField">];
4338-
let Documentation = [CountedByDocs];
4339-
let LangOpts = [COnly];
4340-
// FIXME: This is ugly. Let using a DeclArgument would be nice, but a Decl
4341-
// isn't yet available due to the fact that we're still parsing the
4342-
// structure. Maybe that code could be changed sometime in the future.
4343-
code AdditionalMembers = [{
4344-
private:
4345-
SourceRange CountedByFieldLoc;
4346-
public:
4347-
SourceRange getCountedByFieldLoc() const { return CountedByFieldLoc; }
4348-
void setCountedByFieldLoc(SourceRange Loc) { CountedByFieldLoc = Loc; }
4349-
}];
4350-
}
4351-
43524334
def PreferredType: InheritableAttr {
43534335
let Spellings = [Clang<"preferred_type">];
43544336
let Subjects = SubjectList<[BitField], ErrorDiag>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7500,72 +7500,6 @@ attribute, they default to the value ``65535``.
75007500
}];
75017501
}
75027502

7503-
def CountedByDocs : Documentation {
7504-
let Category = DocCatField;
7505-
let Content = [{
7506-
Clang supports the ``counted_by`` attribute on the flexible array member of a
7507-
structure in C. The argument for the attribute is the name of a field member in
7508-
the same structure holding the count of elements in the flexible array. This
7509-
information can be used to improve the results of the array bound sanitizer and
7510-
the ``__builtin_dynamic_object_size`` builtin.
7511-
7512-
For example, the following code:
7513-
7514-
.. code-block:: c
7515-
7516-
struct bar;
7517-
7518-
struct foo {
7519-
size_t count;
7520-
char other;
7521-
struct bar *array[] __attribute__((counted_by(count)));
7522-
};
7523-
7524-
specifies that the flexible array member ``array`` has the number of elements
7525-
allocated for it stored in ``count``. This establishes a relationship between
7526-
``array`` and ``count``. Specifically, ``p->array`` must have at least
7527-
``p->count`` number of elements available. It's the user's responsibility to
7528-
ensure that this relationship is maintained through changes to the structure.
7529-
7530-
In the following example, the allocated array erroneously has fewer elements
7531-
than what's specified by ``p->count``. This would result in an out-of-bounds
7532-
access not being detected.
7533-
7534-
.. code-block:: c
7535-
7536-
#define SIZE_INCR 42
7537-
7538-
struct foo *p;
7539-
7540-
void foo_alloc(size_t count) {
7541-
p = malloc(MAX(sizeof(struct foo),
7542-
offsetof(struct foo, array[0]) + count * sizeof(struct bar *)));
7543-
p->count = count + SIZE_INCR;
7544-
}
7545-
7546-
The next example updates ``p->count``, breaking the relationship requirement
7547-
that ``p->array`` must have at least ``p->count`` number of elements available:
7548-
7549-
.. code-block:: c
7550-
7551-
#define SIZE_INCR 42
7552-
7553-
struct foo *p;
7554-
7555-
void foo_alloc(size_t count) {
7556-
p = malloc(MAX(sizeof(struct foo),
7557-
offsetof(struct foo, array[0]) + count * sizeof(struct bar *)));
7558-
p->count = count;
7559-
}
7560-
7561-
void use_foo(int index) {
7562-
p->count += SIZE_INCR + 1; /* 'count' is now larger than the number of elements of 'array'. */
7563-
p->array[index] = 0; /* the sanitizer can't properly check if this is an out-of-bounds access. */
7564-
}
7565-
7566-
}];
7567-
}
7568-
75697503
def CoroOnlyDestroyWhenCompleteDocs : Documentation {
75707504
let Category = DocCatDecl;
75717505
let Content = [{

0 commit comments

Comments
 (0)