Skip to content

Commit 6855603

Browse files
committed
Manual merge remote-tracking branch 'llvm-org/main' into amd-gfx
Change-Id: I46e4a0dae3bcb62265e9b53b9927216c0949a196
2 parents 8df7e2c + b8c974f commit 6855603

File tree

510 files changed

+18339
-9434
lines changed

Some content is hidden

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

510 files changed

+18339
-9434
lines changed

.github/workflows/release-binaries-all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ on:
4343
- '.github/workflows/release-binaries.yml'
4444
- '.github/workflows/release-binaries-setup-stage/*'
4545
- '.github/workflows/release-binaries-save-stage/*'
46+
- 'clang/cmake/caches/Release.cmake'
4647

4748
concurrency:
4849
group: ${{ github.workflow }}-${{ github.event.pull_request.number || 'dispatch' }}

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,9 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
14091409
Clang->getPreprocessorOpts().SingleFileParseMode = CompletingInPreamble;
14101410
Clang->setCodeCompletionConsumer(Consumer.release());
14111411

1412+
if (Input.Preamble.RequiredModules)
1413+
Input.Preamble.RequiredModules->adjustHeaderSearchOptions(Clang->getHeaderSearchOpts());
1414+
14121415
SyntaxOnlyAction Action;
14131416
if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) {
14141417
log("BeginSourceFile() failed when running codeComplete for {0}",
@@ -2122,7 +2125,7 @@ clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const {
21222125
// When an is used, Sema is responsible for completing the main file,
21232126
// the index can provide results from the preamble.
21242127
// Tell Sema not to deserialize the preamble to look for results.
2125-
Result.LoadExternal = !Index;
2128+
Result.LoadExternal = ForceLoadPreamble || !Index;
21262129
Result.IncludeFixIts = IncludeFixIts;
21272130

21282131
return Result;

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ struct CodeCompleteOptions {
5252
/// For example, private members are usually inaccessible.
5353
bool IncludeIneligibleResults = false;
5454

55+
/// Force sema to load decls from preamble even if an index is provided.
56+
/// This is helpful for cases the index can't provide symbols, e.g. with
57+
/// experimental c++20 modules
58+
bool ForceLoadPreamble = false;
59+
5560
/// Combine overloads into a single completion item where possible.
5661
/// If none, the implementation may choose an appropriate behavior.
5762
/// (In practice, ClangdLSPServer enables bundling if the client claims

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,9 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
919919
Opts.CodeComplete.EnableFunctionArgSnippets = EnableFunctionArgSnippets;
920920
Opts.CodeComplete.RunParser = CodeCompletionParse;
921921
Opts.CodeComplete.RankingModel = RankingModel;
922+
// FIXME: If we're using C++20 modules, force the lookup process to load
923+
// external decls, since currently the index doesn't support C++20 modules.
924+
Opts.CodeComplete.ForceLoadPreamble = ExperimentalModulesSupport;
922925

923926
RealThreadsafeFS TFS;
924927
std::vector<std::unique_ptr<config::Provider>> ProviderStack;

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,86 @@ import A;
402402
EXPECT_TRUE(D.isFromASTFile());
403403
}
404404

405+
// An end to end test for code complete in modules
406+
TEST_F(PrerequisiteModulesTests, CodeCompleteTest) {
407+
MockDirectoryCompilationDatabase CDB(TestDir, FS);
408+
409+
CDB.addFile("A.cppm", R"cpp(
410+
export module A;
411+
export void printA();
412+
)cpp");
413+
414+
llvm::StringLiteral UserContents = R"cpp(
415+
import A;
416+
void func() {
417+
print^
418+
}
419+
)cpp";
420+
421+
CDB.addFile("Use.cpp", UserContents);
422+
Annotations Test(UserContents);
423+
424+
ModulesBuilder Builder(CDB);
425+
426+
ParseInputs Use = getInputs("Use.cpp", CDB);
427+
Use.ModulesManager = &Builder;
428+
429+
std::unique_ptr<CompilerInvocation> CI =
430+
buildCompilerInvocation(Use, DiagConsumer);
431+
EXPECT_TRUE(CI);
432+
433+
auto Preamble =
434+
buildPreamble(getFullPath("Use.cpp"), *CI, Use, /*InMemory=*/true,
435+
/*Callback=*/nullptr);
436+
EXPECT_TRUE(Preamble);
437+
EXPECT_TRUE(Preamble->RequiredModules);
438+
439+
auto Result = codeComplete(getFullPath("Use.cpp"), Test.point(),
440+
Preamble.get(), Use, {});
441+
EXPECT_FALSE(Result.Completions.empty());
442+
EXPECT_EQ(Result.Completions[0].Name, "printA");
443+
}
444+
445+
TEST_F(PrerequisiteModulesTests, SignatureHelpTest) {
446+
MockDirectoryCompilationDatabase CDB(TestDir, FS);
447+
448+
CDB.addFile("A.cppm", R"cpp(
449+
export module A;
450+
export void printA(int a);
451+
)cpp");
452+
453+
llvm::StringLiteral UserContents = R"cpp(
454+
import A;
455+
void func() {
456+
printA(^);
457+
}
458+
)cpp";
459+
460+
CDB.addFile("Use.cpp", UserContents);
461+
Annotations Test(UserContents);
462+
463+
ModulesBuilder Builder(CDB);
464+
465+
ParseInputs Use = getInputs("Use.cpp", CDB);
466+
Use.ModulesManager = &Builder;
467+
468+
std::unique_ptr<CompilerInvocation> CI =
469+
buildCompilerInvocation(Use, DiagConsumer);
470+
EXPECT_TRUE(CI);
471+
472+
auto Preamble =
473+
buildPreamble(getFullPath("Use.cpp"), *CI, Use, /*InMemory=*/true,
474+
/*Callback=*/nullptr);
475+
EXPECT_TRUE(Preamble);
476+
EXPECT_TRUE(Preamble->RequiredModules);
477+
478+
auto Result = signatureHelp(getFullPath("Use.cpp"), Test.point(),
479+
*Preamble.get(), Use, MarkupKind::PlainText);
480+
EXPECT_FALSE(Result.signatures.empty());
481+
EXPECT_EQ(Result.signatures[0].label, "printA(int a) -> void");
482+
EXPECT_EQ(Result.signatures[0].parameters[0].labelString, "int a");
483+
}
484+
405485
} // namespace
406486
} // namespace clang::clangd
407487

clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/SmallVector.h"
2222
#include "llvm/ADT/StringRef.h"
2323
#include <string>
24+
#include <utility>
2425

2526
namespace clang {
2627
class SourceLocation;
@@ -62,7 +63,8 @@ void walkUsed(llvm::ArrayRef<Decl *> ASTRoots,
6263

6364
struct AnalysisResults {
6465
std::vector<const Include *> Unused;
65-
std::vector<std::string> Missing; // Spellings, like "<vector>"
66+
// Spellings, like "<vector>" paired with the Header that generated it.
67+
std::vector<std::pair<std::string, Header>> Missing;
6668
};
6769

6870
/// Determine which headers should be inserted or removed from the main file.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include "llvm/ADT/STLExtras.h"
2727
#include "llvm/ADT/STLFunctionalExtras.h"
2828
#include "llvm/ADT/SmallVector.h"
29+
#include "llvm/ADT/StringMap.h"
2930
#include "llvm/ADT/StringRef.h"
30-
#include "llvm/ADT/StringSet.h"
3131
#include "llvm/Support/Error.h"
3232
#include "llvm/Support/ErrorHandling.h"
3333
#include <cassert>
@@ -84,7 +84,7 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
8484
auto &SM = PP.getSourceManager();
8585
const auto MainFile = *SM.getFileEntryRefForID(SM.getMainFileID());
8686
llvm::DenseSet<const Include *> Used;
87-
llvm::StringSet<> Missing;
87+
llvm::StringMap<Header> Missing;
8888
if (!HeaderFilter)
8989
HeaderFilter = [](llvm::StringRef) { return false; };
9090
OptionalDirectoryEntryRef ResourceDir =
@@ -119,7 +119,7 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
119119
Satisfied = true;
120120
}
121121
if (!Satisfied)
122-
Missing.insert(std::move(Spelling));
122+
Missing.try_emplace(std::move(Spelling), Providers.front());
123123
});
124124

125125
AnalysisResults Results;
@@ -144,8 +144,8 @@ analyze(llvm::ArrayRef<Decl *> ASTRoots,
144144
}
145145
Results.Unused.push_back(&I);
146146
}
147-
for (llvm::StringRef S : Missing.keys())
148-
Results.Missing.push_back(S.str());
147+
for (auto &E : Missing)
148+
Results.Missing.emplace_back(E.first().str(), E.second);
149149
llvm::sort(Results.Missing);
150150
return Results;
151151
}
@@ -158,9 +158,9 @@ std::string fixIncludes(const AnalysisResults &Results,
158158
// Encode insertions/deletions in the magic way clang-format understands.
159159
for (const Include *I : Results.Unused)
160160
cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 1, I->quote())));
161-
for (llvm::StringRef Spelled : Results.Missing)
162-
cantFail(R.add(tooling::Replacement(FileName, UINT_MAX, 0,
163-
("#include " + Spelled).str())));
161+
for (auto &[Spelled, _] : Results.Missing)
162+
cantFail(R.add(
163+
tooling::Replacement(FileName, UINT_MAX, 0, "#include " + Spelled)));
164164
// "cleanup" actually turns the UINT_MAX replacements into concrete edits.
165165
auto Positioned = cantFail(format::cleanupAroundReplacements(Code, R, Style));
166166
return cantFail(tooling::applyAllReplacements(Code, Positioned));

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Action : public clang::ASTFrontendAction {
192192
case PrintStyle::Changes:
193193
for (const Include *I : Results.Unused)
194194
llvm::outs() << "- " << I->quote() << " @Line:" << I->Line << "\n";
195-
for (const auto &I : Results.Missing)
195+
for (const auto &[I, _] : Results.Missing)
196196
llvm::outs() << "+ " << I << "\n";
197197
break;
198198
case PrintStyle::Final:

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2626
#include "llvm/ADT/SmallVector.h"
2727
#include "llvm/ADT/StringRef.h"
28+
#include "llvm/Support/Error.h"
2829
#include "llvm/Support/MemoryBuffer.h"
2930
#include "llvm/Support/ScopedPrinter.h"
3031
#include "llvm/Support/VirtualFileSystem.h"
@@ -39,6 +40,7 @@
3940

4041
namespace clang::include_cleaner {
4142
namespace {
43+
using testing::_;
4244
using testing::AllOf;
4345
using testing::Contains;
4446
using testing::ElementsAre;
@@ -262,10 +264,12 @@ int x = a + c;
262264
auto Results =
263265
analyze(std::vector<Decl *>{Decls.begin(), Decls.end()},
264266
PP.MacroReferences, PP.Includes, &PI, AST.preprocessor());
267+
auto CHeader = llvm::cantFail(
268+
AST.context().getSourceManager().getFileManager().getFileRef("c.h"));
265269

266270
const Include *B = PP.Includes.atLine(3);
267271
ASSERT_EQ(B->Spelled, "b.h");
268-
EXPECT_THAT(Results.Missing, ElementsAre("\"c.h\""));
272+
EXPECT_THAT(Results.Missing, ElementsAre(Pair("\"c.h\"", Header(CHeader))));
269273
EXPECT_THAT(Results.Unused, ElementsAre(B));
270274
}
271275

@@ -370,7 +374,7 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
370374
auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, AST.preprocessor());
371375
// Check that we're spelling header using the symlink, and not underlying
372376
// path.
373-
EXPECT_THAT(Results.Missing, testing::ElementsAre("\"inner.h\""));
377+
EXPECT_THAT(Results.Missing, testing::ElementsAre(Pair("\"inner.h\"", _)));
374378
// header.h should be unused.
375379
EXPECT_THAT(Results.Unused, Not(testing::IsEmpty()));
376380

@@ -379,7 +383,7 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
379383
auto HeaderFilter = [](llvm::StringRef Path) { return Path == "inner.h"; };
380384
Results = analyze(DeclsInTU, {}, PP.Includes, &PI, AST.preprocessor(),
381385
HeaderFilter);
382-
EXPECT_THAT(Results.Missing, testing::ElementsAre("\"inner.h\""));
386+
EXPECT_THAT(Results.Missing, testing::ElementsAre(Pair("\"inner.h\"", _)));
383387
// header.h should be unused.
384388
EXPECT_THAT(Results.Unused, Not(testing::IsEmpty()));
385389
}
@@ -389,7 +393,7 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
389393
HeaderFilter);
390394
// header.h should be ignored now.
391395
EXPECT_THAT(Results.Unused, Not(testing::IsEmpty()));
392-
EXPECT_THAT(Results.Missing, testing::ElementsAre("\"inner.h\""));
396+
EXPECT_THAT(Results.Missing, testing::ElementsAre(Pair("\"inner.h\"", _)));
393397
}
394398
}
395399

@@ -414,9 +418,9 @@ TEST(FixIncludes, Basic) {
414418
Inc.add(I);
415419

416420
AnalysisResults Results;
417-
Results.Missing.push_back("\"aa.h\"");
418-
Results.Missing.push_back("\"ab.h\"");
419-
Results.Missing.push_back("<e.h>");
421+
Results.Missing.emplace_back("\"aa.h\"", Header(""));
422+
Results.Missing.emplace_back("\"ab.h\"", Header(""));
423+
Results.Missing.emplace_back("<e.h>", Header(""));
420424
Results.Unused.push_back(Inc.atLine(3));
421425
Results.Unused.push_back(Inc.atLine(4));
422426

@@ -429,7 +433,7 @@ R"cpp(#include "d.h"
429433
)cpp");
430434

431435
Results = {};
432-
Results.Missing.push_back("\"d.h\"");
436+
Results.Missing.emplace_back("\"d.h\"", Header(""));
433437
Code = R"cpp(#include "a.h")cpp";
434438
EXPECT_EQ(fixIncludes(Results, "d.cc", Code, format::getLLVMStyle()),
435439
R"cpp(#include "d.h"

clang/CodeOwners.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ OpenBSD driver
120120
Driver parts not covered by someone else
121121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122122
| Fangrui Song
123-
| maskray\@google.com (email), MaskRay (Phabricator), MaskRay (GitHub)
123+
| i\@maskray.me (email), MaskRay (Phabricator), MaskRay (GitHub)
124124
125125

126126
Tools

0 commit comments

Comments
 (0)