@@ -264,7 +264,7 @@ void Driver::setDriverMode(StringRef Value) {
264264}
265265
266266InputArgList Driver::ParseArgStrings (ArrayRef<const char *> ArgStrings,
267- bool UseDriverMode, bool &ContainsError) {
267+ bool UseDriverMode, bool &ContainsError) const {
268268 llvm::PrettyStackTraceString CrashInfo (" Command line argument parsing" );
269269 ContainsError = false ;
270270
@@ -1397,8 +1397,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
13971397 bool HasConfigFileTail = !ContainsError && CfgOptionsTail;
13981398
13991399 // All arguments, from both config file and command line.
1400- InputArgList Args =
1401- HasConfigFileHead ? std::move (*CfgOptionsHead) : std::move (*CLOptions) ;
1400+ auto UArgs = std::make_unique<InputArgList>(HasConfigFileHead ? std::move (*CfgOptionsHead) : std::move (*CLOptions));
1401+ InputArgList &Args = *UArgs ;
14021402
14031403 if (HasConfigFileHead)
14041404 for (auto *Opt : *CLOptions)
@@ -1426,52 +1426,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14261426 }
14271427 }
14281428
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-
14751429 // FIXME: TargetTriple is used by the target-prefixed calls to as/ld
14761430 // and getToolChain is const.
14771431 if (IsCLMode ()) {
@@ -1529,6 +1483,79 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
15291483 TargetTriple = A->getValue ();
15301484 if (const Arg *A = Args.getLastArg (options::OPT_ccc_install_dir))
15311485 Dir = Dir = A->getValue ();
1486+ if (const Arg *A = Args.getLastArg (options::OPT__sysroot_EQ))
1487+ SysRoot = A->getValue ();
1488+ if (const Arg *A = Args.getLastArg (options::OPT_resource_dir))
1489+ ResourceDir = A->getValue ();
1490+ if (const Arg *A = Args.getLastArg (options::OPT__dyld_prefix_EQ))
1491+ DyldPrefix = A->getValue ();
1492+
1493+ setLTOMode (Args);
1494+
1495+ // Owned by the host.
1496+ const ToolChain &TC =
1497+ getToolChain (Args, computeTargetTriple (*this , TargetTriple, Args));
1498+
1499+ SmallVector<std::string> MultilibDriverArgsStr =
1500+ TC.getMultilibDriverArgsStr (Args);
1501+ SmallVector<const char *> MLArgsChar (
1502+ llvm::map_range (MultilibDriverArgsStr, [&Args](const auto &S) {
1503+ return Args.MakeArgString (S);
1504+ }));
1505+ bool MLContainsError;
1506+ auto MultilibDriverArgList = std::make_unique<InputArgList>(
1507+ ParseArgStrings (MLArgsChar, /* UseDriverMode=*/ false , MLContainsError));
1508+ if (!MLContainsError)
1509+ for (auto *Opt : *MultilibDriverArgList) {
1510+ appendOneArg (Args, Opt, nullptr );
1511+ }
1512+
1513+ // Check for working directory option before accessing any files
1514+ if (Arg *WD = Args.getLastArg (options::OPT_working_directory))
1515+ if (VFS->setCurrentWorkingDirectory (WD->getValue ()))
1516+ Diag (diag::err_drv_unable_to_set_working_directory) << WD->getValue ();
1517+
1518+ // Check for missing include directories.
1519+ if (!Diags.isIgnored (diag::warn_missing_include_dirs, SourceLocation ())) {
1520+ for (auto IncludeDir : Args.getAllArgValues (options::OPT_I_Group)) {
1521+ if (!VFS->exists (IncludeDir))
1522+ Diag (diag::warn_missing_include_dirs) << IncludeDir;
1523+ }
1524+ }
1525+
1526+ // FIXME: This stuff needs to go into the Compilation, not the driver.
1527+ bool CCCPrintPhases;
1528+
1529+ // -canonical-prefixes, -no-canonical-prefixes are used very early in main.
1530+ Args.ClaimAllArgs (options::OPT_canonical_prefixes);
1531+ Args.ClaimAllArgs (options::OPT_no_canonical_prefixes);
1532+
1533+ // f(no-)integated-cc1 is also used very early in main.
1534+ Args.ClaimAllArgs (options::OPT_fintegrated_cc1);
1535+ Args.ClaimAllArgs (options::OPT_fno_integrated_cc1);
1536+
1537+ // Ignore -pipe.
1538+ Args.ClaimAllArgs (options::OPT_pipe);
1539+
1540+ // Extract -ccc args.
1541+ //
1542+ // FIXME: We need to figure out where this behavior should live. Most of it
1543+ // should be outside in the client; the parts that aren't should have proper
1544+ // options, either by introducing new ones or by overloading gcc ones like -V
1545+ // or -b.
1546+ CCCPrintPhases = Args.hasArg (options::OPT_ccc_print_phases);
1547+ CCCPrintBindings = Args.hasArg (options::OPT_ccc_print_bindings);
1548+ if (const Arg *A = Args.getLastArg (options::OPT_ccc_gcc_name))
1549+ CCCGenericGCCName = A->getValue ();
1550+
1551+ // Process -fproc-stat-report options.
1552+ if (const Arg *A = Args.getLastArg (options::OPT_fproc_stat_report_EQ)) {
1553+ CCPrintProcessStats = true ;
1554+ CCPrintStatReportFilename = A->getValue ();
1555+ }
1556+ if (Args.hasArg (options::OPT_fproc_stat_report))
1557+ CCPrintProcessStats = true ;
1558+
15321559 for (const Arg *A : Args.filtered (options::OPT_B)) {
15331560 A->claim ();
15341561 PrefixDirs.push_back (A->getValue (0 ));
@@ -1543,13 +1570,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
15431570 CompilerPath = Split.second ;
15441571 }
15451572 }
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 ();
15531573
15541574 if (const Arg *A = Args.getLastArg (options::OPT_save_temps_EQ)) {
15551575 SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue ())
@@ -1569,8 +1589,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
15691589 Offload = OffloadHostDevice;
15701590 }
15711591
1572- setLTOMode (Args);
1573-
15741592 // Process -fembed-bitcode= flags.
15751593 if (Arg *A = Args.getLastArg (options::OPT_fembed_bitcode_EQ)) {
15761594 StringRef Name = A->getValue ();
@@ -1624,16 +1642,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
16241642 }
16251643 }
16261644
1627- std::unique_ptr<llvm::opt::InputArgList> UArgs =
1628- std::make_unique<InputArgList>(std::move (Args));
1629-
16301645 // Perform the default argument translations.
16311646 DerivedArgList *TranslatedArgs = TranslateInputArgs (*UArgs);
16321647
1633- // Owned by the host.
1634- const ToolChain &TC = getToolChain (
1635- *UArgs, computeTargetTriple (*this , TargetTriple, *UArgs));
1636-
16371648 // Check if the environment version is valid except wasm case.
16381649 llvm::Triple Triple = TC.getTriple ();
16391650 if (!Triple.isWasm ()) {
0 commit comments