@@ -262,7 +262,7 @@ void Driver::setDriverMode(StringRef Value) {
262262}
263263
264264InputArgList Driver::ParseArgStrings (ArrayRef<const char *> ArgStrings,
265- bool UseDriverMode, bool &ContainsError) {
265+ bool UseDriverMode, bool &ContainsError) const {
266266 llvm::PrettyStackTraceString CrashInfo (" Command line argument parsing" );
267267 ContainsError = false ;
268268
@@ -1272,8 +1272,8 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
12721272 bool HasConfigFileTail = !ContainsError && CfgOptionsTail;
12731273
12741274 // 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 ;
12771277
12781278 if (HasConfigFileHead)
12791279 for (auto *Opt : *CLOptions)
@@ -1301,52 +1301,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
13011301 }
13021302 }
13031303
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-
13501304 // FIXME: TargetTriple is used by the target-prefixed calls to as/ld
13511305 // and getToolChain is const.
13521306 if (IsCLMode ()) {
@@ -1399,6 +1353,79 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
13991353 TargetTriple = A->getValue ();
14001354 if (const Arg *A = Args.getLastArg (options::OPT_ccc_install_dir))
14011355 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+
14021429 for (const Arg *A : Args.filtered (options::OPT_B)) {
14031430 A->claim ();
14041431 PrefixDirs.push_back (A->getValue (0 ));
@@ -1413,13 +1440,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14131440 CompilerPath = Split.second ;
14141441 }
14151442 }
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 ();
14231443
14241444 if (const Arg *A = Args.getLastArg (options::OPT_save_temps_EQ)) {
14251445 SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue ())
@@ -1439,8 +1459,6 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14391459 Offload = OffloadHostDevice;
14401460 }
14411461
1442- setLTOMode (Args);
1443-
14441462 // Process -fembed-bitcode= flags.
14451463 if (Arg *A = Args.getLastArg (options::OPT_fembed_bitcode_EQ)) {
14461464 StringRef Name = A->getValue ();
@@ -1494,16 +1512,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
14941512 }
14951513 }
14961514
1497- std::unique_ptr<llvm::opt::InputArgList> UArgs =
1498- std::make_unique<InputArgList>(std::move (Args));
1499-
15001515 // Perform the default argument translations.
15011516 DerivedArgList *TranslatedArgs = TranslateInputArgs (*UArgs);
15021517
1503- // Owned by the host.
1504- const ToolChain &TC = getToolChain (
1505- *UArgs, computeTargetTriple (*this , TargetTriple, *UArgs));
1506-
15071518 // Check if the environment version is valid except wasm case.
15081519 llvm::Triple Triple = TC.getTriple ();
15091520 if (!Triple.isWasm ()) {
0 commit comments