@@ -262,7 +262,7 @@ void Driver::setDriverMode(StringRef Value) {
262
262
}
263
263
264
264
InputArgList Driver::ParseArgStrings (ArrayRef<const char *> ArgStrings,
265
- bool UseDriverMode, bool &ContainsError) {
265
+ bool UseDriverMode, bool &ContainsError) const {
266
266
llvm::PrettyStackTraceString CrashInfo (" Command line argument parsing" );
267
267
ContainsError = false ;
268
268
@@ -1252,8 +1252,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1252
1252
bool HasConfigFile = !ContainsError && (CfgOptions.get () != nullptr );
1253
1253
1254
1254
// All arguments, from both config file and command line.
1255
- InputArgList Args = std::move (HasConfigFile ? std::move (*CfgOptions)
1256
- : std::move (*CLOptions));
1255
+ auto UArgs = std::make_unique<InputArgList>(std::move (HasConfigFile ? std::move (*CfgOptions)
1256
+ : std::move (*CLOptions)));
1257
+ InputArgList &Args = *UArgs;
1257
1258
1258
1259
if (HasConfigFile)
1259
1260
for (auto *Opt : *CLOptions) {
@@ -1287,52 +1288,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1287
1288
}
1288
1289
}
1289
1290
1290
- // Check for working directory option before accessing any files
1291
- if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1292
- if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1293
- Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1294
-
1295
- // Check for missing include directories.
1296
- if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1297
- for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1298
- if (!VFS->exists (IncludeDir))
1299
- Diag (diag::warn_missing_include_dirs) << IncludeDir;
1300
- }
1301
- }
1302
-
1303
- // FIXME: This stuff needs to go into the Compilation, not the driver.
1304
- bool CCCPrintPhases;
1305
-
1306
- // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1307
- Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1308
- Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1309
-
1310
- // f(no-)integated-cc1 is also used very early in main.
1311
- Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1312
- Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1313
-
1314
- // Ignore -pipe.
1315
- Args.ClaimAllArgs (options::OPT_pipe);
1316
-
1317
- // Extract -ccc args.
1318
- //
1319
- // FIXME: We need to figure out where this behavior should live. Most of it
1320
- // should be outside in the client; the parts that aren't should have proper
1321
- // options, either by introducing new ones or by overloading gcc ones like -V
1322
- // or -b.
1323
- CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1324
- CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1325
- if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1326
- CCCGenericGCCName = A->getValue ();
1327
-
1328
- // Process -fproc-stat-report options.
1329
- if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1330
- CCPrintProcessStats = true ;
1331
- CCPrintStatReportFilename = A->getValue ();
1332
- }
1333
- if (Args.hasArg (options::OPT_fproc_stat_report))
1334
- CCPrintProcessStats = true ;
1335
-
1336
1291
// FIXME: TargetTriple is used by the target-prefixed calls to as/ld
1337
1292
// and getToolChain is const.
1338
1293
if (IsCLMode ()) {
@@ -1385,6 +1340,79 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1385
1340
TargetTriple = A->getValue ();
1386
1341
if (const Arg *A = Args.getLastArg (options::OPT_ccc_install_dir))
1387
1342
Dir = Dir = A->getValue ();
1343
+ if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1344
+ SysRoot = A->getValue ();
1345
+ if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1346
+ ResourceDir = A->getValue ();
1347
+ if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1348
+ DyldPrefix = A->getValue ();
1349
+
1350
+ setLTOMode (Args);
1351
+
1352
+ // Owned by the host.
1353
+ const ToolChain &TC =
1354
+ getToolChain (Args, computeTargetTriple (*this , TargetTriple, Args));
1355
+
1356
+ SmallVector<std::string> MultilibDriverArgsStr =
1357
+ TC.getMultilibDriverArgsStr (Args);
1358
+ SmallVector<const char *> MLArgsChar (
1359
+ llvm::map_range (MultilibDriverArgsStr, [&Args](const auto &S) {
1360
+ return Args.MakeArgString (S);
1361
+ }));
1362
+ bool MLContainsError;
1363
+ auto MultilibDriverArgList = std::make_unique<InputArgList>(
1364
+ ParseArgStrings (MLArgsChar, /* UseDriverMode=*/ false , MLContainsError));
1365
+ if (!MLContainsError)
1366
+ for (auto *Opt : *MultilibDriverArgList) {
1367
+ appendOneArg (Args, Opt, nullptr );
1368
+ }
1369
+
1370
+ // Check for working directory option before accessing any files
1371
+ if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1372
+ if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1373
+ Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1374
+
1375
+ // Check for missing include directories.
1376
+ if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1377
+ for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1378
+ if (!VFS->exists (IncludeDir))
1379
+ Diag (diag::warn_missing_include_dirs) << IncludeDir;
1380
+ }
1381
+ }
1382
+
1383
+ // FIXME: This stuff needs to go into the Compilation, not the driver.
1384
+ bool CCCPrintPhases;
1385
+
1386
+ // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1387
+ Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1388
+ Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1389
+
1390
+ // f(no-)integated-cc1 is also used very early in main.
1391
+ Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1392
+ Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1393
+
1394
+ // Ignore -pipe.
1395
+ Args.ClaimAllArgs (options::OPT_pipe);
1396
+
1397
+ // Extract -ccc args.
1398
+ //
1399
+ // FIXME: We need to figure out where this behavior should live. Most of it
1400
+ // should be outside in the client; the parts that aren't should have proper
1401
+ // options, either by introducing new ones or by overloading gcc ones like -V
1402
+ // or -b.
1403
+ CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1404
+ CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1405
+ if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1406
+ CCCGenericGCCName = A->getValue ();
1407
+
1408
+ // Process -fproc-stat-report options.
1409
+ if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1410
+ CCPrintProcessStats = true ;
1411
+ CCPrintStatReportFilename = A->getValue ();
1412
+ }
1413
+ if (Args.hasArg (options::OPT_fproc_stat_report))
1414
+ CCPrintProcessStats = true ;
1415
+
1388
1416
for (const Arg *A : Args.filtered (options::OPT_B)) {
1389
1417
A->claim ();
1390
1418
PrefixDirs.push_back (A->getValue (0 ));
@@ -1399,13 +1427,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1399
1427
CompilerPath = Split.second ;
1400
1428
}
1401
1429
}
1402
- if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1403
- SysRoot = A->getValue ();
1404
- if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1405
- DyldPrefix = A->getValue ();
1406
-
1407
- if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1408
- ResourceDir = A->getValue ();
1409
1430
1410
1431
if (const Arg *A = Args.getLastArg (options::OPT_save_temps_EQ)) {
1411
1432
SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue ())
@@ -1425,8 +1446,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1425
1446
Offload = OffloadHostDevice;
1426
1447
}
1427
1448
1428
- setLTOMode (Args);
1429
-
1430
1449
// Process -fembed-bitcode= flags.
1431
1450
if (Arg *A = Args.getLastArg (options::OPT_fembed_bitcode_EQ)) {
1432
1451
StringRef Name = A->getValue ();
@@ -1480,16 +1499,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1480
1499
}
1481
1500
}
1482
1501
1483
- std::unique_ptr<llvm::opt::InputArgList> UArgs =
1484
- std::make_unique<InputArgList>(std::move (Args));
1485
-
1486
1502
// Perform the default argument translations.
1487
1503
DerivedArgList *TranslatedArgs = TranslateInputArgs (*UArgs);
1488
1504
1489
- // Owned by the host.
1490
- const ToolChain &TC = getToolChain (
1491
- *UArgs, computeTargetTriple (*this , TargetTriple, *UArgs));
1492
-
1493
1505
// Check if the environment version is valid except wasm case.
1494
1506
llvm::Triple Triple = TC.getTriple ();
1495
1507
if (!Triple.isWasm ()) {
0 commit comments