@@ -1398,9 +1398,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
13981398 bool HasConfigFileTail = !ContainsError && CfgOptionsTail;
13991399
14001400 // All arguments, from both config file and command line.
1401- auto UArgs = std::make_unique<InputArgList>(
1402- HasConfigFileHead ? std::move (*CfgOptionsHead) : std::move (*CLOptions));
1403- InputArgList &Args = *UArgs;
1401+ InputArgList Args = HasConfigFileHead ? std::move (*CfgOptionsHead) : std::move (*CLOptions);
14041402
14051403 if (HasConfigFileHead)
14061404 for (auto *Opt : *CLOptions)
@@ -1428,6 +1426,52 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14281426 }
14291427 }
14301428
1429+ // Check for working directory option before accessing any files
1430+ if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1431+ if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1432+ Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1433+
1434+ // Check for missing include directories.
1435+ if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1436+ for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1437+ if (!VFS->exists (IncludeDir))
1438+ Diag (diag::warn_missing_include_dirs) << IncludeDir;
1439+ }
1440+ }
1441+
1442+ // FIXME: This stuff needs to go into the Compilation, not the driver.
1443+ bool CCCPrintPhases;
1444+
1445+ // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1446+ Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1447+ Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1448+
1449+ // f(no-)integated-cc1 is also used very early in main.
1450+ Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1451+ Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1452+
1453+ // Ignore -pipe.
1454+ Args.ClaimAllArgs (options::OPT_pipe);
1455+
1456+ // Extract -ccc args.
1457+ //
1458+ // FIXME: We need to figure out where this behavior should live. Most of it
1459+ // should be outside in the client; the parts that aren't should have proper
1460+ // options, either by introducing new ones or by overloading gcc ones like -V
1461+ // or -b.
1462+ CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1463+ CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1464+ if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1465+ CCCGenericGCCName = A->getValue ();
1466+
1467+ // Process -fproc-stat-report options.
1468+ if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1469+ CCPrintProcessStats = true ;
1470+ CCPrintStatReportFilename = A->getValue ();
1471+ }
1472+ if (Args.hasArg (options::OPT_fproc_stat_report))
1473+ CCPrintProcessStats = true ;
1474+
14311475 // FIXME: TargetTriple is used by the target-prefixed calls to as/ld
14321476 // and getToolChain is const.
14331477 if (IsCLMode ()) {
@@ -1485,79 +1529,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14851529 TargetTriple = A->getValue ();
14861530 if (const Arg *A = Args.getLastArg (options::OPT_ccc_install_dir))
14871531 Dir = Dir = A->getValue ();
1488- if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1489- SysRoot = A->getValue ();
1490- if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1491- ResourceDir = A->getValue ();
1492- if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1493- DyldPrefix = A->getValue ();
1494-
1495- setLTOMode (Args);
1496-
1497- // Owned by the host.
1498- const ToolChain &TC =
1499- getToolChain (Args, computeTargetTriple (*this , TargetTriple, Args));
1500-
1501- SmallVector<std::string> MultilibDriverArgsStr =
1502- TC.getMultilibDriverArgsStr (Args);
1503- SmallVector<const char *> MLArgsChar (
1504- llvm::map_range (MultilibDriverArgsStr, [&Args](const auto &S) {
1505- return Args.MakeArgString (S);
1506- }));
1507- bool MLContainsError;
1508- auto MultilibDriverArgList = std::make_unique<InputArgList>(
1509- ParseArgStrings (MLArgsChar, /* UseDriverMode=*/ false , MLContainsError));
1510- if (!MLContainsError)
1511- for (auto *Opt : *MultilibDriverArgList) {
1512- appendOneArg (Args, Opt, nullptr );
1513- }
1514-
1515- // Check for working directory option before accessing any files
1516- if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1517- if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1518- Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1519-
1520- // Check for missing include directories.
1521- if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1522- for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1523- if (!VFS->exists (IncludeDir))
1524- Diag (diag::warn_missing_include_dirs) << IncludeDir;
1525- }
1526- }
1527-
1528- // FIXME: This stuff needs to go into the Compilation, not the driver.
1529- bool CCCPrintPhases;
1530-
1531- // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1532- Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1533- Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1534-
1535- // f(no-)integated-cc1 is also used very early in main.
1536- Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1537- Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1538-
1539- // Ignore -pipe.
1540- Args.ClaimAllArgs (options::OPT_pipe);
1541-
1542- // Extract -ccc args.
1543- //
1544- // FIXME: We need to figure out where this behavior should live. Most of it
1545- // should be outside in the client; the parts that aren't should have proper
1546- // options, either by introducing new ones or by overloading gcc ones like -V
1547- // or -b.
1548- CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1549- CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1550- if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1551- CCCGenericGCCName = A->getValue ();
1552-
1553- // Process -fproc-stat-report options.
1554- if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1555- CCPrintProcessStats = true ;
1556- CCPrintStatReportFilename = A->getValue ();
1557- }
1558- if (Args.hasArg (options::OPT_fproc_stat_report))
1559- CCPrintProcessStats = true ;
1560-
15611532 for (const Arg *A : Args.filtered (options::OPT_B)) {
15621533 A->claim ();
15631534 PrefixDirs.push_back (A->getValue (0 ));
@@ -1572,6 +1543,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
15721543 CompilerPath = Split.second ;
15731544 }
15741545 }
1546+ if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1547+ SysRoot = A->getValue ();
1548+ if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1549+ DyldPrefix = A->getValue ();
1550+
1551+ if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1552+ ResourceDir = A->getValue ();
15751553
15761554 if (const Arg *A = Args.getLastArg (options::OPT_save_temps_EQ)) {
15771555 SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue ())
@@ -1591,6 +1569,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
15911569 Offload = OffloadHostDevice;
15921570 }
15931571
1572+ setLTOMode (Args);
1573+
15941574 // Process -fembed-bitcode= flags.
15951575 if (Arg *A = Args.getLastArg (options::OPT_fembed_bitcode_EQ)) {
15961576 StringRef Name = A->getValue ();
@@ -1644,6 +1624,31 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
16441624 }
16451625 }
16461626
1627+ std::unique_ptr<llvm::opt::InputArgList> UArgs =
1628+ std::make_unique<InputArgList>(std::move (Args));
1629+
1630+ // Owned by the host.
1631+ const ToolChain &TC =
1632+ getToolChain (*UArgs, computeTargetTriple (*this , TargetTriple, *UArgs));
1633+
1634+ {
1635+ SmallVector<std::string> MultilibMacroDefinesStr =
1636+ TC.getMultilibMacroDefinesStr (*UArgs);
1637+ SmallVector<const char *> MLMacroDefinesChar (
1638+ llvm::map_range (MultilibMacroDefinesStr, [&UArgs](const auto &S) {
1639+ return UArgs->MakeArgString (Twine (" -D" ) + Twine (S));
1640+ }));
1641+ bool MLContainsError;
1642+ auto MultilibMacroDefineList =
1643+ std::make_unique<InputArgList>(ParseArgStrings (
1644+ MLMacroDefinesChar, /* UseDriverMode=*/ false , MLContainsError));
1645+ if (!MLContainsError) {
1646+ for (auto *Opt : *MultilibMacroDefineList) {
1647+ appendOneArg (*UArgs, Opt);
1648+ }
1649+ }
1650+ }
1651+
16471652 // Perform the default argument translations.
16481653 DerivedArgList *TranslatedArgs = TranslateInputArgs (*UArgs);
16491654
0 commit comments