@@ -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
@@ -1272,8 +1272,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1272
1272
bool HasConfigFileTail = !ContainsError && CfgOptionsTail;
1273
1273
1274
1274
// All arguments, from both config file and command line.
1275
- InputArgList Args =
1276
- HasConfigFileHead ? std::move (*CfgOptionsHead) : std::move (*CLOptions) ;
1275
+ auto UArgs = std::make_unique<InputArgList>(HasConfigFileHead ? std::move (*CfgOptionsHead) : std::move (*CLOptions));
1276
+ InputArgList &Args = *UArgs ;
1277
1277
1278
1278
if (HasConfigFileHead)
1279
1279
for (auto *Opt : *CLOptions)
@@ -1301,52 +1301,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1301
1301
}
1302
1302
}
1303
1303
1304
- // Check for working directory option before accessing any files
1305
- if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1306
- if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1307
- Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1308
-
1309
- // Check for missing include directories.
1310
- if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1311
- for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1312
- if (!VFS->exists (IncludeDir))
1313
- Diag (diag::warn_missing_include_dirs) << IncludeDir;
1314
- }
1315
- }
1316
-
1317
- // FIXME: This stuff needs to go into the Compilation, not the driver.
1318
- bool CCCPrintPhases;
1319
-
1320
- // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1321
- Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1322
- Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1323
-
1324
- // f(no-)integated-cc1 is also used very early in main.
1325
- Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1326
- Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1327
-
1328
- // Ignore -pipe.
1329
- Args.ClaimAllArgs (options::OPT_pipe);
1330
-
1331
- // Extract -ccc args.
1332
- //
1333
- // FIXME: We need to figure out where this behavior should live. Most of it
1334
- // should be outside in the client; the parts that aren't should have proper
1335
- // options, either by introducing new ones or by overloading gcc ones like -V
1336
- // or -b.
1337
- CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1338
- CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1339
- if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1340
- CCCGenericGCCName = A->getValue ();
1341
-
1342
- // Process -fproc-stat-report options.
1343
- if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1344
- CCPrintProcessStats = true ;
1345
- CCPrintStatReportFilename = A->getValue ();
1346
- }
1347
- if (Args.hasArg (options::OPT_fproc_stat_report))
1348
- CCPrintProcessStats = true ;
1349
-
1350
1304
// FIXME: TargetTriple is used by the target-prefixed calls to as/ld
1351
1305
// and getToolChain is const.
1352
1306
if (IsCLMode ()) {
@@ -1399,6 +1353,79 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1399
1353
TargetTriple = A->getValue ();
1400
1354
if (const Arg *A = Args.getLastArg (options::OPT_ccc_install_dir))
1401
1355
Dir = Dir = A->getValue ();
1356
+ if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1357
+ SysRoot = A->getValue ();
1358
+ if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1359
+ ResourceDir = A->getValue ();
1360
+ if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1361
+ DyldPrefix = A->getValue ();
1362
+
1363
+ setLTOMode (Args);
1364
+
1365
+ // Owned by the host.
1366
+ const ToolChain &TC =
1367
+ getToolChain (Args, computeTargetTriple (*this , TargetTriple, Args));
1368
+
1369
+ SmallVector<std::string> MultilibDriverArgsStr =
1370
+ TC.getMultilibDriverArgsStr (Args);
1371
+ SmallVector<const char *> MLArgsChar (
1372
+ llvm::map_range (MultilibDriverArgsStr, [&Args](const auto &S) {
1373
+ return Args.MakeArgString (S);
1374
+ }));
1375
+ bool MLContainsError;
1376
+ auto MultilibDriverArgList = std::make_unique<InputArgList>(
1377
+ ParseArgStrings (MLArgsChar, /* UseDriverMode=*/ false , MLContainsError));
1378
+ if (!MLContainsError)
1379
+ for (auto *Opt : *MultilibDriverArgList) {
1380
+ appendOneArg (Args, Opt, nullptr );
1381
+ }
1382
+
1383
+ // Check for working directory option before accessing any files
1384
+ if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1385
+ if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1386
+ Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1387
+
1388
+ // Check for missing include directories.
1389
+ if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1390
+ for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1391
+ if (!VFS->exists (IncludeDir))
1392
+ Diag (diag::warn_missing_include_dirs) << IncludeDir;
1393
+ }
1394
+ }
1395
+
1396
+ // FIXME: This stuff needs to go into the Compilation, not the driver.
1397
+ bool CCCPrintPhases;
1398
+
1399
+ // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1400
+ Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1401
+ Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1402
+
1403
+ // f(no-)integated-cc1 is also used very early in main.
1404
+ Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1405
+ Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1406
+
1407
+ // Ignore -pipe.
1408
+ Args.ClaimAllArgs (options::OPT_pipe);
1409
+
1410
+ // Extract -ccc args.
1411
+ //
1412
+ // FIXME: We need to figure out where this behavior should live. Most of it
1413
+ // should be outside in the client; the parts that aren't should have proper
1414
+ // options, either by introducing new ones or by overloading gcc ones like -V
1415
+ // or -b.
1416
+ CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1417
+ CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1418
+ if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1419
+ CCCGenericGCCName = A->getValue ();
1420
+
1421
+ // Process -fproc-stat-report options.
1422
+ if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1423
+ CCPrintProcessStats = true ;
1424
+ CCPrintStatReportFilename = A->getValue ();
1425
+ }
1426
+ if (Args.hasArg (options::OPT_fproc_stat_report))
1427
+ CCPrintProcessStats = true ;
1428
+
1402
1429
for (const Arg *A : Args.filtered (options::OPT_B)) {
1403
1430
A->claim ();
1404
1431
PrefixDirs.push_back (A->getValue (0 ));
@@ -1413,13 +1440,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1413
1440
CompilerPath = Split.second ;
1414
1441
}
1415
1442
}
1416
- if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1417
- SysRoot = A->getValue ();
1418
- if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1419
- DyldPrefix = A->getValue ();
1420
-
1421
- if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1422
- ResourceDir = A->getValue ();
1423
1443
1424
1444
if (const Arg *A = Args.getLastArg (options::OPT_save_temps_EQ)) {
1425
1445
SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue ())
@@ -1439,8 +1459,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1439
1459
Offload = OffloadHostDevice;
1440
1460
}
1441
1461
1442
- setLTOMode (Args);
1443
-
1444
1462
// Process -fembed-bitcode= flags.
1445
1463
if (Arg *A = Args.getLastArg (options::OPT_fembed_bitcode_EQ)) {
1446
1464
StringRef Name = A->getValue ();
@@ -1494,16 +1512,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
1494
1512
}
1495
1513
}
1496
1514
1497
- std::unique_ptr<llvm::opt::InputArgList> UArgs =
1498
- std::make_unique<InputArgList>(std::move (Args));
1499
-
1500
1515
// Perform the default argument translations.
1501
1516
DerivedArgList *TranslatedArgs = TranslateInputArgs (*UArgs);
1502
1517
1503
- // Owned by the host.
1504
- const ToolChain &TC = getToolChain (
1505
- *UArgs, computeTargetTriple (*this , TargetTriple, *UArgs));
1506
-
1507
1518
// Check if the environment version is valid except wasm case.
1508
1519
llvm::Triple Triple = TC.getTriple ();
1509
1520
if (!Triple.isWasm ()) {
0 commit comments