Skip to content

Commit b6109e2

Browse files
committed
Merge from 'main' to 'sycl-web' (2 commits)
2 parents 33f8f54 + 152a216 commit b6109e2

File tree

18 files changed

+265
-699
lines changed

18 files changed

+265
-699
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,8 @@ It should be used via an editor plugin rather than invoked directly. For more in
775775
clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment variable.
776776
)";
777777
llvm::cl::HideUnrelatedOptions(ClangdCategories);
778-
llvm::cl::ParseCommandLineOptions(argc, argv, Overview,
779-
/*Errs=*/nullptr, FlagsEnvVar);
778+
llvm::cl::ParseCommandLineOptions(argc, argv, Overview, /*Errs=*/nullptr,
779+
/*VFS=*/nullptr, FlagsEnvVar);
780780
if (Test) {
781781
if (!Sync.getNumOccurrences())
782782
Sync = true;

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
604604
return Options;
605605
}
606606

607-
static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
607+
static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts,
608+
vfs::FileSystem &VFS) {
608609
SmallVector<const char *, 16> BackendArgs;
609610
BackendArgs.push_back("clang"); // Fake program name.
610611
if (!CodeGenOpts.DebugPass.empty()) {
@@ -624,8 +625,9 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
624625
// FIXME: The command line parser below is not thread-safe and shares a global
625626
// state, so this call might crash or overwrite the options of another Clang
626627
// instance in the same process.
627-
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
628-
BackendArgs.data());
628+
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1, BackendArgs.data(),
629+
/*Overview=*/"", /*Errs=*/nullptr,
630+
/*VFS=*/&VFS);
629631
}
630632

631633
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
@@ -1393,7 +1395,7 @@ void EmitAssemblyHelper::RunCodegenPipeline(
13931395
void EmitAssemblyHelper::emitAssembly(BackendAction Action,
13941396
std::unique_ptr<raw_pwrite_stream> OS,
13951397
BackendConsumer *BC) {
1396-
setCommandLineOpts(CodeGenOpts);
1398+
setCommandLineOpts(CodeGenOpts, CI.getVirtualFileSystem());
13971399

13981400
bool RequiresCodeGen = actionRequiresCodeGen(Action);
13991401
CreateTargetMachine(RequiresCodeGen);
@@ -1428,7 +1430,7 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex,
14281430
ModuleToDefinedGVSummaries;
14291431
CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
14301432

1431-
setCommandLineOpts(CGOpts);
1433+
setCommandLineOpts(CGOpts, CI.getVirtualFileSystem());
14321434

14331435
// We can simply import the values mentioned in the combined index, since
14341436
// we should only invoke this using the individual indexes written out

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
244244
for (unsigned i = 0; i != NumArgs; ++i)
245245
Args[i + 1] = Clang->getFrontendOpts().LLVMArgs[i].c_str();
246246
Args[NumArgs + 1] = nullptr;
247-
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
247+
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
248+
/*Errs=*/nullptr,
249+
/*VFS=*/&Clang->getVirtualFileSystem());
248250
}
249251

250252
#if CLANG_ENABLE_STATIC_ANALYZER

clang/tools/clang-offload-extract/ClangOffloadExtract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int main(int argc, const char **argv) {
105105
A utility to extract all the target images from a
106106
linked fat binary, and store them in separate files.
107107
)",
108-
nullptr, nullptr, true);
108+
nullptr, nullptr, nullptr, true);
109109

110110
// Read input file. It should have one of the supported object file
111111
// formats:

clang/tools/driver/cc1as_main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
669669
DiagClient->setPrefix("clang -cc1as");
670670
DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DiagClient);
671671

672+
auto VFS = vfs::getRealFileSystem();
673+
672674
// Set an error handler, so that any LLVM backend diagnostics go through our
673675
// error handler.
674676
ScopedFatalErrorHandler FatalErrorHandler
@@ -707,7 +709,8 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
707709
for (unsigned i = 0; i != NumArgs; ++i)
708710
Args[i + 1] = Asm.LLVMArgs[i].c_str();
709711
Args[NumArgs + 1] = nullptr;
710-
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
712+
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"",
713+
/*Errs=*/nullptr, /*VFS=*/VFS.get());
711714
}
712715

713716
// Execute the invocation, unless there were parsing errors.

clang/tools/driver/driver.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,17 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
204204
}
205205

206206
static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
207-
const llvm::ToolContext &ToolContext) {
207+
const llvm::ToolContext &ToolContext,
208+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
208209
// If we call the cc1 tool from the clangDriver library (through
209210
// Driver::CC1Main), we need to clean up the options usage count. The options
210211
// are currently global, and they might have been used previously by the
211212
// driver.
212213
llvm::cl::ResetAllOptionOccurrences();
213214

214215
llvm::BumpPtrAllocator A;
215-
llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine);
216+
llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine,
217+
VFS.get());
216218
if (llvm::Error Err = ECtx.expandResponseFiles(ArgV)) {
217219
llvm::errs() << toString(std::move(Err)) << '\n';
218220
return 1;
@@ -254,14 +256,16 @@ int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
254256
bool ClangCLMode =
255257
IsClangCL(getDriverMode(ProgName, llvm::ArrayRef(Args).slice(1)));
256258

257-
if (llvm::Error Err = expandResponseFiles(Args, ClangCLMode, A)) {
259+
auto VFS = llvm::vfs::getRealFileSystem();
260+
261+
if (llvm::Error Err = expandResponseFiles(Args, ClangCLMode, A, VFS.get())) {
258262
llvm::errs() << toString(std::move(Err)) << '\n';
259263
return 1;
260264
}
261265

262266
// Handle -cc1 integrated tools.
263267
if (Args.size() >= 2 && StringRef(Args[1]).starts_with("-cc1"))
264-
return ExecuteCC1Tool(Args, ToolContext);
268+
return ExecuteCC1Tool(Args, ToolContext, VFS);
265269

266270
// Handle options that need handling before the real command line parsing in
267271
// Driver::BuildCompilation()
@@ -341,7 +345,6 @@ int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
341345
Diags.takeClient(), std::move(SerializedConsumer)));
342346
}
343347

344-
auto VFS = llvm::vfs::getRealFileSystem();
345348
ProcessWarningOptions(Diags, *DiagOpts, *VFS, /*ReportDiags=*/false);
346349

347350
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags,
@@ -361,10 +364,10 @@ int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
361364
if (!SetBackdoorDriverOutputsFromEnvVars(TheDriver))
362365
return 1;
363366

364-
auto ExecuteCC1WithContext =
365-
[&ToolContext](SmallVectorImpl<const char *> &ArgV) {
366-
return ExecuteCC1Tool(ArgV, ToolContext);
367-
};
367+
auto ExecuteCC1WithContext = [&ToolContext,
368+
&VFS](SmallVectorImpl<const char *> &ArgV) {
369+
return ExecuteCC1Tool(ArgV, ToolContext, VFS);
370+
};
368371
if (!UseNewCC1Process) {
369372
TheDriver.CC1Main = ExecuteCC1WithContext;
370373
// Ensure the CC1Command actually catches cc1 crashes

llvm/include/llvm/Support/CommandLine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace cl {
6969
LLVM_ABI bool ParseCommandLineOptions(int argc, const char *const *argv,
7070
StringRef Overview = "",
7171
raw_ostream *Errs = nullptr,
72+
vfs::FileSystem *VFS = nullptr,
7273
const char *EnvVar = nullptr,
7374
bool LongOptionsUseDoubleDash = false);
7475

@@ -2192,7 +2193,8 @@ class ExpansionContext {
21922193
SmallVectorImpl<const char *> &NewArgv);
21932194

21942195
public:
2195-
LLVM_ABI ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T);
2196+
LLVM_ABI ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T,
2197+
vfs::FileSystem *FS = nullptr);
21962198

21972199
ExpansionContext &setMarkEOLs(bool X) {
21982200
MarkEOLs = X;

llvm/lib/Support/CommandLine.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class CommandLineParser {
188188

189189
bool ParseCommandLineOptions(int argc, const char *const *argv,
190190
StringRef Overview, raw_ostream *Errs = nullptr,
191+
vfs::FileSystem *VFS = nullptr,
191192
bool LongOptionsUseDoubleDash = false);
192193

193194
void forEachSubCommand(Option &Opt, function_ref<void(SubCommand &)> Action) {
@@ -1401,8 +1402,9 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
14011402
return true;
14021403
}
14031404

1404-
ExpansionContext::ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T)
1405-
: Saver(A), Tokenizer(T), FS(vfs::getRealFileSystem().get()) {}
1405+
ExpansionContext::ExpansionContext(BumpPtrAllocator &A, TokenizerCallback T,
1406+
vfs::FileSystem *FS)
1407+
: Saver(A), Tokenizer(T), FS(FS ? FS : vfs::getRealFileSystem().get()) {}
14061408

14071409
bool ExpansionContext::findConfigFile(StringRef FileName,
14081410
SmallVectorImpl<char> &FilePath) {
@@ -1461,7 +1463,7 @@ Error ExpansionContext::readConfigFile(StringRef CfgFile,
14611463
static void initCommonOptions();
14621464
bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
14631465
StringRef Overview, raw_ostream *Errs,
1464-
const char *EnvVar,
1466+
vfs::FileSystem *VFS, const char *EnvVar,
14651467
bool LongOptionsUseDoubleDash) {
14661468
initCommonOptions();
14671469
SmallVector<const char *, 20> NewArgv;
@@ -1482,8 +1484,8 @@ bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
14821484
int NewArgc = static_cast<int>(NewArgv.size());
14831485

14841486
// Parse all options.
1485-
return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
1486-
Errs, LongOptionsUseDoubleDash);
1487+
return GlobalParser->ParseCommandLineOptions(
1488+
NewArgc, &NewArgv[0], Overview, Errs, VFS, LongOptionsUseDoubleDash);
14871489
}
14881490

14891491
/// Reset all options at least once, so that we can parse different options.
@@ -1503,17 +1505,17 @@ void CommandLineParser::ResetAllOptionOccurrences() {
15031505
}
15041506
}
15051507

1506-
bool CommandLineParser::ParseCommandLineOptions(int argc,
1507-
const char *const *argv,
1508-
StringRef Overview,
1509-
raw_ostream *Errs,
1510-
bool LongOptionsUseDoubleDash) {
1508+
bool CommandLineParser::ParseCommandLineOptions(
1509+
int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs,
1510+
vfs::FileSystem *VFS, bool LongOptionsUseDoubleDash) {
15111511
assert(hasOptions() && "No options specified!");
15121512

15131513
ProgramOverview = Overview;
15141514
bool IgnoreErrors = Errs;
15151515
if (!Errs)
15161516
Errs = &errs();
1517+
if (!VFS)
1518+
VFS = vfs::getRealFileSystem().get();
15171519
bool ErrorParsing = false;
15181520

15191521
// Expand response files.
@@ -1524,7 +1526,7 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
15241526
#else
15251527
auto Tokenize = cl::TokenizeGNUCommandLine;
15261528
#endif
1527-
ExpansionContext ECtx(A, Tokenize);
1529+
ExpansionContext ECtx(A, Tokenize, VFS);
15281530
if (Error Err = ECtx.expandResponseFiles(newArgv)) {
15291531
*Errs << toString(std::move(Err)) << '\n';
15301532
return false;

llvm/tools/obj2yaml/obj2yaml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
104104
cl::HideUnrelatedOptions(Cat);
105105
cl::ParseCommandLineOptions(
106106
argc, argv, "Dump a YAML description from an object file", nullptr,
107-
nullptr, /*LongOptionsUseDoubleDash=*/true);
107+
nullptr, nullptr, /*LongOptionsUseDoubleDash=*/true);
108108

109109
std::error_code EC;
110110
std::unique_ptr<ToolOutputFile> Out(

llvm/tools/yaml2obj/yaml2obj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int main(int argc, char **argv) {
115115
cl::HideUnrelatedOptions(Cat);
116116
cl::ParseCommandLineOptions(
117117
argc, argv, "Create an object file from a YAML description", nullptr,
118-
nullptr, /*LongOptionsUseDoubleDash=*/true);
118+
nullptr, nullptr, /*LongOptionsUseDoubleDash=*/true);
119119

120120
constexpr StringRef ProgName = "yaml2obj";
121121
auto ErrHandler = [&](const Twine &Msg) {

0 commit comments

Comments
 (0)