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