@@ -3046,50 +3046,6 @@ static void GenerateFrontendArgs(const FrontendOptions &Opts,
30463046 Consumer (Input.getFile ());
30473047}
30483048
3049- static void determineInputFromIncludeTree (
3050- StringRef IncludeTreeID, CASOptions &CASOpts, DiagnosticsEngine &Diags,
3051- std::optional<cas::IncludeTreeRoot> &IncludeTree,
3052- std::optional<llvm::MemoryBufferRef> &Buffer, StringRef &InputFilename) {
3053- assert (!IncludeTreeID.empty ());
3054- auto reportError = [&](llvm::Error &&E) {
3055- Diags.Report (diag::err_fe_unable_to_load_include_tree)
3056- << IncludeTreeID << llvm::toString (std::move (E));
3057- };
3058- auto CAS = CASOpts.getOrCreateDatabases (Diags).first ;
3059- if (!CAS)
3060- return ;
3061- auto ID = CAS->parseID (IncludeTreeID);
3062- if (!ID)
3063- return reportError (ID.takeError ());
3064- auto Object = CAS->getReference (*ID);
3065- if (!Object)
3066- return reportError (llvm::cas::ObjectStore::createUnknownObjectError (*ID));
3067- auto Root = cas::IncludeTreeRoot::get (*CAS, *Object);
3068- if (!Root)
3069- return reportError (Root.takeError ());
3070- auto MainTree = Root->getMainFileTree ();
3071- if (!MainTree)
3072- return reportError (MainTree.takeError ());
3073- auto BaseFile = MainTree->getBaseFile ();
3074- if (!BaseFile)
3075- return reportError (BaseFile.takeError ());
3076- auto FilenameBlob = BaseFile->getFilename ();
3077- if (!FilenameBlob)
3078- return reportError (FilenameBlob.takeError ());
3079-
3080- InputFilename = FilenameBlob->getData ();
3081- IncludeTree = *Root;
3082-
3083- if (InputFilename != Module::getModuleInputBufferName ())
3084- return ;
3085-
3086- // Handle <module-include> buffer
3087- auto Contents = BaseFile->getContents ();
3088- if (!Contents)
3089- return reportError (Contents.takeError ());
3090- Buffer = llvm::MemoryBufferRef (Contents->getData (), InputFilename);
3091- }
3092-
30933049static bool ParseFrontendArgs (FrontendOptions &Opts, ArgList &Args,
30943050 CASOptions &CASOpts, DiagnosticsEngine &Diags,
30953051 bool &IsHeaderFile) {
@@ -3308,17 +3264,18 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
33083264 std::vector<std::string> Inputs = Args.getAllArgValues (OPT_INPUT);
33093265 Opts.Inputs .clear ();
33103266
3311- std::optional<cas::IncludeTreeRoot> Tree;
3312- std::optional<llvm::MemoryBufferRef> TreeInputBuffer;
33133267 if (!Opts.CASIncludeTreeID .empty ()) {
3314- if (!Inputs.empty ()) {
3268+ if (!Inputs.empty ())
33153269 Diags.Report (diag::err_drv_inputs_and_include_tree);
3270+
3271+ if (DashX.isUnknown ()) {
3272+ Diags.Report (diag::err_drv_include_tree_miss_input_kind);
3273+ DashX = Language::C; // set to default C to avoid crashing.
33163274 }
3317- StringRef InputFilename;
3318- determineInputFromIncludeTree (Opts.CASIncludeTreeID , CASOpts, Diags, Tree,
3319- TreeInputBuffer, InputFilename);
3320- if (!InputFilename.empty ())
3321- Inputs.push_back (InputFilename.str ());
3275+
3276+ // Quit early as include tree will delay input initialization.
3277+ Opts.DashX = DashX;
3278+ return Diags.getNumErrors () == NumErrorsBefore;
33223279 }
33233280
33243281 if (Inputs.empty ())
@@ -3353,20 +3310,6 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
33533310 Opts.Inputs .emplace_back (std::move (Inputs[i]), IK, IsSystem);
33543311 }
33553312
3356- if (Tree) {
3357- FrontendInputFile &InputFile = Opts.Inputs .back ();
3358- if (TreeInputBuffer) {
3359- // This is automatically set to modulemap when building a module; revert
3360- // to a source file for the module includes buffer.
3361- auto Kind = InputFile.getKind ().withFormat (InputKind::Source);
3362- InputFile = FrontendInputFile (Tree->getRef (), *TreeInputBuffer, Kind,
3363- InputFile.isSystem ());
3364- } else {
3365- InputFile = FrontendInputFile (Tree->getRef (), InputFile.getFile (),
3366- InputFile.getKind (), InputFile.isSystem ());
3367- }
3368- }
3369-
33703313 Opts.DashX = DashX;
33713314
33723315 return Diags.getNumErrors () == NumErrorsBefore;
0 commit comments