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