Skip to content

Commit 25767fc

Browse files
committed
Fix a crash
Created using spr 1.3.5
2 parents 5c84b6f + ccd7795 commit 25767fc

File tree

680 files changed

+12111
-6389
lines changed

Some content is hidden

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

680 files changed

+12111
-6389
lines changed

.github/workflows/build-ci-container.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
container-name-tag: ${{ steps.vars.outputs.container-name-tag }}
2828
container-name-agent-tag: ${{ steps.vars.outputs.container-name-agent-tag }}
2929
container-filename: ${{ steps.vars.outputs.container-filename }}
30+
container-agent-filename: ${{ steps.vars.outputs.container-agent-filename }}
3031
steps:
3132
- name: Checkout LLVM
3233
uses: actions/checkout@v4
@@ -42,6 +43,7 @@ jobs:
4243
echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT
4344
echo "container-name-agent-tag=$container_name-agent:$tag" >> $GITHUB_OUTPUT
4445
echo "container-filename=$(echo $container_name:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
46+
echo "container-agent-filename=$(echo $container_name-agent:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
4547
- name: Build container
4648
working-directory: ./.github/workflows/containers/github-action-ci/
4749
run: |
@@ -53,13 +55,14 @@ jobs:
5355
# maintain minimal permissions while building the container.
5456
- name: Save container image
5557
run: |
56-
podman save ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name-agent-tag }} > ${{ steps.vars.outputs.container-filename }}
58+
podman save ${{ steps.vars.outputs.container-name-tag }} > ${{ steps.vars.outputs.container-filename }}
59+
podman save ${{ steps.vars.outputs.container-name-agent-tag }} > ${{ steps.vars.outputs.container-agent-filename }}
5760
5861
- name: Upload container image
5962
uses: actions/upload-artifact@v4
6063
with:
6164
name: container
62-
path: ${{ steps.vars.outputs.container-filename }}
65+
path: "*.tar"
6366
retention-days: 14
6467

6568
- name: Test Container
@@ -92,6 +95,7 @@ jobs:
9295
podman push ${{ needs.build-ci-container.outputs.container-name-tag }}
9396
podman push ${{ needs.build-ci-container.outputs.container-name }}:latest
9497
98+
podman load -i ${{ needs.build-ci-container.outputs.container-agent-filename }}
9599
podman tag ${{ needs.build-ci-container.outputs.container-name-agent-tag }} ${{ needs.build-ci-container.outputs.container-name-agent }}:latest
96100
podman push ${{ needs.build-ci-container.outputs.container-name-agent-tag }}
97101
podman push ${{ needs.build-ci-container.outputs.container-name-agent }}:latest

.github/workflows/libcxx-restart-preempted-jobs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
})
9494
9595
// For temporary debugging purposes to see the structure of the annotations.
96-
console.print(annotations);
96+
console.log(annotations);
9797
9898
has_failed_job = false;
9999
saved_failure_message = null;

.github/workflows/premerge.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ jobs:
1818
concurrency:
1919
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
2020
cancel-in-progress: true
21-
container:
22-
image: ghcr.io/llvm/ci-ubuntu-22.04:latest
23-
defaults:
24-
run:
25-
shell: bash
2621
steps:
2722
- name: Checkout LLVM
2823
uses: actions/checkout@v4

clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
118118
return Results;
119119
}
120120

121+
/// Returns the start of the leading comments before `Loc`.
122+
static SourceLocation getStartOfLeadingComment(SourceLocation Loc,
123+
const SourceManager &SM,
124+
const LangOptions &LangOpts) {
125+
// We consider any leading comment token that is on the same line or
126+
// indented similarly to the first comment to be part of the leading comment.
127+
const unsigned Line = SM.getPresumedLineNumber(Loc);
128+
const unsigned Column = SM.getPresumedColumnNumber(Loc);
129+
std::optional<Token> Tok =
130+
Lexer::findPreviousToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
131+
while (Tok && Tok->is(tok::comment)) {
132+
const SourceLocation CommentLoc =
133+
Lexer::GetBeginningOfToken(Tok->getLocation(), SM, LangOpts);
134+
if (SM.getPresumedLineNumber(CommentLoc) != Line &&
135+
SM.getPresumedColumnNumber(CommentLoc) != Column) {
136+
break;
137+
}
138+
Loc = CommentLoc;
139+
Tok = Lexer::findPreviousToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
140+
}
141+
return Loc;
142+
}
143+
121144
/// Returns the end of the trailing comments after `Loc`.
122145
static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
123146
const SourceManager &SM,
@@ -159,6 +182,7 @@ static SourceRange getFullFieldSourceRange(const FieldDecl &Field,
159182
if (CurrentToken->is(tok::semi))
160183
break;
161184
}
185+
Begin = getStartOfLeadingComment(Begin, SM, LangOpts);
162186
End = getEndOfTrailingComment(End, SM, LangOpts);
163187
return SourceRange(Begin, End);
164188
}

clang-tools-extra/clang-tidy/utils/LexerUtils.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@ namespace clang::tidy::utils::lexer {
1717
std::pair<Token, SourceLocation>
1818
getPreviousTokenAndStart(SourceLocation Location, const SourceManager &SM,
1919
const LangOptions &LangOpts, bool SkipComments) {
20-
Token Token;
21-
Token.setKind(tok::unknown);
20+
const std::optional<Token> Tok =
21+
Lexer::findPreviousToken(Location, SM, LangOpts, !SkipComments);
2222

23-
Location = Location.getLocWithOffset(-1);
24-
if (Location.isInvalid())
25-
return {Token, Location};
26-
27-
const auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
28-
while (Location != StartOfFile) {
29-
Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
30-
if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
31-
(!SkipComments || !Token.is(tok::comment))) {
32-
break;
33-
}
34-
if (Location == StartOfFile)
35-
return {Token, Location};
36-
Location = Location.getLocWithOffset(-1);
23+
if (Tok.has_value()) {
24+
return {*Tok, Lexer::GetBeginningOfToken(Tok->getLocation(), SM, LangOpts)};
3725
}
38-
return {Token, Location};
26+
27+
Token Token;
28+
Token.setKind(tok::unknown);
29+
return {Token, SourceLocation()};
3930
}
4031

4132
Token getPreviousToken(SourceLocation Location, const SourceManager &SM,

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,16 @@ bool OverlayCDB::setCompileCommand(PathRef File,
830830
return true;
831831
}
832832

833+
std::unique_ptr<ProjectModules>
834+
OverlayCDB::getProjectModules(PathRef File) const {
835+
auto MDB = DelegatingCDB::getProjectModules(File);
836+
MDB->setCommandMangler([&Mangler = Mangler](tooling::CompileCommand &Command,
837+
PathRef CommandPath) {
838+
Mangler(Command, CommandPath);
839+
});
840+
return std::move(MDB);
841+
}
842+
833843
DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)
834844
: Base(Base) {
835845
if (Base)

clang-tools-extra/clangd/GlobalCompilationDatabase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class OverlayCDB : public DelegatingCDB {
209209
setCompileCommand(PathRef File,
210210
std::optional<tooling::CompileCommand> CompilationCommand);
211211

212+
std::unique_ptr<ProjectModules>
213+
getProjectModules(PathRef File) const override;
214+
212215
private:
213216
mutable std::mutex Mutex;
214217
llvm::StringMap<tooling::CompileCommand> Commands; /* GUARDED_BY(Mut) */

clang-tools-extra/clangd/ProjectModules.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
1111

12+
#include "support/Function.h"
1213
#include "support/Path.h"
1314
#include "support/ThreadsafeFS.h"
15+
#include "clang/Tooling/CompilationDatabase.h"
1416

1517
#include <memory>
1618

@@ -36,11 +38,16 @@ namespace clangd {
3638
/// `<primary-module-name>[:partition-name]`. So module names covers partitions.
3739
class ProjectModules {
3840
public:
41+
using CommandMangler =
42+
llvm::unique_function<void(tooling::CompileCommand &, PathRef) const>;
43+
3944
virtual std::vector<std::string> getRequiredModules(PathRef File) = 0;
4045
virtual PathRef
4146
getSourceForModuleName(llvm::StringRef ModuleName,
4247
PathRef RequiredSrcFile = PathRef()) = 0;
4348

49+
virtual void setCommandMangler(CommandMangler Mangler) {}
50+
4451
virtual ~ProjectModules() = default;
4552
};
4653

clang-tools-extra/clangd/ScanningProjectModules.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class ModuleDependencyScanner {
4848
};
4949

5050
/// Scanning the single file specified by \param FilePath.
51-
std::optional<ModuleDependencyInfo> scan(PathRef FilePath);
51+
std::optional<ModuleDependencyInfo>
52+
scan(PathRef FilePath, const ProjectModules::CommandMangler &Mangler);
5253

5354
/// Scanning every source file in the current project to get the
5455
/// <module-name> to <module-unit-source> map.
@@ -57,7 +58,7 @@ class ModuleDependencyScanner {
5758
/// a global module dependency scanner to monitor every file. Or we
5859
/// can simply require the build systems (or even the end users)
5960
/// to provide the map.
60-
void globalScan();
61+
void globalScan(const ProjectModules::CommandMangler &Mangler);
6162

6263
/// Get the source file from the module name. Note that the language
6364
/// guarantees all the module names are unique in a valid program.
@@ -69,7 +70,9 @@ class ModuleDependencyScanner {
6970

7071
/// Return the direct required modules. Indirect required modules are not
7172
/// included.
72-
std::vector<std::string> getRequiredModules(PathRef File);
73+
std::vector<std::string>
74+
getRequiredModules(PathRef File,
75+
const ProjectModules::CommandMangler &Mangler);
7376

7477
private:
7578
std::shared_ptr<const clang::tooling::CompilationDatabase> CDB;
@@ -87,7 +90,8 @@ class ModuleDependencyScanner {
8790
};
8891

8992
std::optional<ModuleDependencyScanner::ModuleDependencyInfo>
90-
ModuleDependencyScanner::scan(PathRef FilePath) {
93+
ModuleDependencyScanner::scan(PathRef FilePath,
94+
const ProjectModules::CommandMangler &Mangler) {
9195
auto Candidates = CDB->getCompileCommands(FilePath);
9296
if (Candidates.empty())
9397
return std::nullopt;
@@ -97,10 +101,8 @@ ModuleDependencyScanner::scan(PathRef FilePath) {
97101
// DirectoryBasedGlobalCompilationDatabase::getCompileCommand.
98102
tooling::CompileCommand Cmd = std::move(Candidates.front());
99103

100-
static int StaticForMainAddr; // Just an address in this process.
101-
Cmd.CommandLine.push_back("-resource-dir=" +
102-
CompilerInvocation::GetResourcesPath(
103-
"clangd", (void *)&StaticForMainAddr));
104+
if (Mangler)
105+
Mangler(Cmd, FilePath);
104106

105107
using namespace clang::tooling::dependencies;
106108

@@ -130,9 +132,10 @@ ModuleDependencyScanner::scan(PathRef FilePath) {
130132
return Result;
131133
}
132134

133-
void ModuleDependencyScanner::globalScan() {
135+
void ModuleDependencyScanner::globalScan(
136+
const ProjectModules::CommandMangler &Mangler) {
134137
for (auto &File : CDB->getAllFiles())
135-
scan(File);
138+
scan(File, Mangler);
136139

137140
GlobalScanned = true;
138141
}
@@ -150,9 +153,9 @@ PathRef ModuleDependencyScanner::getSourceForModuleName(
150153
return {};
151154
}
152155

153-
std::vector<std::string>
154-
ModuleDependencyScanner::getRequiredModules(PathRef File) {
155-
auto ScanningResult = scan(File);
156+
std::vector<std::string> ModuleDependencyScanner::getRequiredModules(
157+
PathRef File, const ProjectModules::CommandMangler &Mangler) {
158+
auto ScanningResult = scan(File, Mangler);
156159
if (!ScanningResult)
157160
return {};
158161

@@ -177,20 +180,25 @@ class ScanningAllProjectModules : public ProjectModules {
177180
~ScanningAllProjectModules() override = default;
178181

179182
std::vector<std::string> getRequiredModules(PathRef File) override {
180-
return Scanner.getRequiredModules(File);
183+
return Scanner.getRequiredModules(File, Mangler);
184+
}
185+
186+
void setCommandMangler(CommandMangler Mangler) override {
187+
this->Mangler = std::move(Mangler);
181188
}
182189

183190
/// RequiredSourceFile is not used intentionally. See the comments of
184191
/// ModuleDependencyScanner for detail.
185192
PathRef
186193
getSourceForModuleName(llvm::StringRef ModuleName,
187194
PathRef RequiredSourceFile = PathRef()) override {
188-
Scanner.globalScan();
195+
Scanner.globalScan(Mangler);
189196
return Scanner.getSourceForModuleName(ModuleName);
190197
}
191198

192199
private:
193200
ModuleDependencyScanner Scanner;
201+
CommandMangler Mangler;
194202
};
195203

196204
std::unique_ptr<ProjectModules> scanningProjectModules(

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
/// code mode.
1212
#ifndef _WIN32
1313

14-
#include "ModulesBuilder.h"
15-
#include "ScanningProjectModules.h"
1614
#include "Annotations.h"
1715
#include "CodeComplete.h"
1816
#include "Compiler.h"
17+
#include "ModulesBuilder.h"
18+
#include "ScanningProjectModules.h"
1919
#include "TestTU.h"
2020
#include "support/ThreadsafeFS.h"
21+
#include "llvm/ADT/StringRef.h"
2122
#include "llvm/Support/FileSystem.h"
2223
#include "llvm/Support/raw_ostream.h"
2324
#include "gmock/gmock.h"
@@ -191,6 +192,41 @@ export module M;
191192
EXPECT_TRUE(MInfo->canReuse(*Invocation, FS.view(TestDir)));
192193
}
193194

195+
TEST_F(PrerequisiteModulesTests, ModuleWithArgumentPatch) {
196+
MockDirectoryCompilationDatabase CDB(TestDir, FS);
197+
198+
CDB.ExtraClangFlags.push_back("-invalid-unknown-flag");
199+
200+
CDB.addFile("Dep.cppm", R"cpp(
201+
export module Dep;
202+
)cpp");
203+
204+
CDB.addFile("M.cppm", R"cpp(
205+
export module M;
206+
import Dep;
207+
)cpp");
208+
209+
// An invalid flag will break the module compilation and the
210+
// getRequiredModules would return an empty array
211+
auto ProjectModules = CDB.getProjectModules(getFullPath("M.cppm"));
212+
EXPECT_TRUE(
213+
ProjectModules->getRequiredModules(getFullPath("M.cppm")).empty());
214+
215+
// Set the mangler to filter out the invalid flag
216+
ProjectModules->setCommandMangler(
217+
[](tooling::CompileCommand &Command, PathRef) {
218+
auto const It =
219+
std::find(Command.CommandLine.begin(), Command.CommandLine.end(),
220+
"-invalid-unknown-flag");
221+
Command.CommandLine.erase(It);
222+
});
223+
224+
// And now it returns a non-empty list of required modules since the
225+
// compilation succeeded
226+
EXPECT_FALSE(
227+
ProjectModules->getRequiredModules(getFullPath("M.cppm")).empty());
228+
}
229+
194230
TEST_F(PrerequisiteModulesTests, ModuleWithDepTest) {
195231
MockDirectoryCompilationDatabase CDB(TestDir, FS);
196232

@@ -435,7 +471,7 @@ void func() {
435471
/*Callback=*/nullptr);
436472
EXPECT_TRUE(Preamble);
437473
EXPECT_TRUE(Preamble->RequiredModules);
438-
474+
439475
auto Result = codeComplete(getFullPath("Use.cpp"), Test.point(),
440476
Preamble.get(), Use, {});
441477
EXPECT_FALSE(Result.Completions.empty());
@@ -474,7 +510,7 @@ void func() {
474510
/*Callback=*/nullptr);
475511
EXPECT_TRUE(Preamble);
476512
EXPECT_TRUE(Preamble->RequiredModules);
477-
513+
478514
auto Result = signatureHelp(getFullPath("Use.cpp"), Test.point(),
479515
*Preamble.get(), Use, MarkupKind::PlainText);
480516
EXPECT_FALSE(Result.signatures.empty());

0 commit comments

Comments
 (0)