clang: lib/Frontend/CompilerInstance.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

22#include "clang/Config/config.h"

42#include "llvm/ADT/IntrusiveRefCntPtr.h"

43#include "llvm/ADT/STLExtras.h"

44#include "llvm/ADT/ScopeExit.h"

45#include "llvm/ADT/Statistic.h"

46#include "llvm/Config/llvm-config.h"

47#include "llvm/Support/BuryPointer.h"

48#include "llvm/Support/CrashRecoveryContext.h"

49#include "llvm/Support/Errc.h"

50#include "llvm/Support/FileSystem.h"

51#include "llvm/Support/LockFileManager.h"

52#include "llvm/Support/MemoryBuffer.h"

53#include "llvm/Support/Path.h"

54#include "llvm/Support/Program.h"

55#include "llvm/Support/Signals.h"

56#include "llvm/Support/TimeProfiler.h"

57#include "llvm/Support/Timer.h"

58#include "llvm/Support/VirtualFileSystem.h"

59#include "llvm/Support/raw_ostream.h"

60#include "llvm/TargetParser/Host.h"

61#include

62#include <time.h>

63#include

64

65using namespace clang;

66

67CompilerInstance::CompilerInstance(

68 std::shared_ptr PCHContainerOps,

70 : ModuleLoader( SharedModuleCache),

72 ModuleCache(SharedModuleCache ? SharedModuleCache

74 ThePCHContainerOperations(std::move(PCHContainerOps)) {}

75

77 assert(OutputFiles.empty() && "Still output files in flight?");

78}

79

81 std::shared_ptr Value) {

82 Invocation = std::move(Value);

83}

84

86 return (BuildGlobalModuleIndex ||

87 (TheASTReader && TheASTReader->isGlobalIndexUnavailable() &&

89 !DisableGeneratingGlobalModuleIndex;

90}

91

93 Diagnostics = Value;

94}

95

97 OwnedVerboseOutputStream.reset();

98 VerboseOutputStream = &Value;

99}

100

102 OwnedVerboseOutputStream.swap(Value);

103 VerboseOutputStream = OwnedVerboseOutputStream.get();

104}

105

108

110

114 return false;

115

116

117

122 auto TO = std::make_shared();

123 TO->Triple = llvm::Triple::normalize(getFrontendOpts().AuxTriple);

130 }

131

136 }

137 auto FPExc = getLangOpts().getFPExceptionMode();

141 }

142

143 }

144

145

146

149 return false;

150

151

152

153

155

158

159 return true;

160}

161

164}

165

168}

169

171 SourceMgr = Value;

172}

173

175 PP = std::move(Value);

176}

177

180

181 if (Context && Consumer)

183}

184

186 TheSema.reset(S);

187}

188

190 Consumer = std::move(Value);

191

192 if (Context && Consumer)

194}

195

197 CompletionConsumer.reset(Value);

198}

199

201 return std::move(TheSema);

202}

203

205 return TheASTReader;

206}

208 assert(ModuleCache.get() == &Reader->getModuleManager().getModuleCache() &&

209 "Expected ASTReader to use the same PCM cache");

210 TheASTReader = std::move(Reader);

211}

212

213std::shared_ptr

215 return ModuleDepCollector;

216}

217

219 std::shared_ptr Collector) {

220 ModuleDepCollector = std::move(Collector);

221}

222

224 std::shared_ptr MDC) {

227 for (auto &Name : HeaderMapFileNames)

228 MDC->addFile(Name);

229}

230

232 std::shared_ptr MDC) {

235 return;

236

240 if (!PCHDir) {

241 MDC->addFile(PCHInclude);

242 return;

243 }

244

245 std::error_code EC;

247 llvm::sys::path::native(PCHDir->getName(), DirNative);

250 for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;

251 Dir != DirEnd && !EC; Dir.increment(EC)) {

252

253

254

258 false, Validator,

259 false))

260 MDC->addFile(Dir->path());

261 }

262}

263

265 std::shared_ptr MDC) {

267 return;

268

269

272 llvm::ErrorOr<std::unique_ptrllvm::MemoryBuffer> Buffer =

273 llvm::MemoryBuffer::getFile(VFSFile);

274 if (!Buffer)

275 return;

276 llvm::vfs::collectVFSFromYAML(std::move(Buffer.get()),

277 nullptr, VFSFile, VFSEntries);

278 }

279

280 for (auto &E : VFSEntries)

281 MDC->addFile(E.VPath, E.RPath);

282}

283

284

288 std::error_code EC;

289 std::unique_ptr<raw_ostream> StreamOwner;

290 raw_ostream *OS = &llvm::errs();

292

293 auto FileOS = std::make_uniquellvm::raw\_fd\_ostream(

295 llvm::sys::fs::OF_Append | llvm::sys::fs::OF_TextWithCRLF);

296 if (EC) {

297 Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)

299 } else {

300 FileOS->SetUnbuffered();

301 OS = FileOS.get();

302 StreamOwner = std::move(FileOS);

303 }

304 }

305

306

307 auto Logger = std::make_unique(*OS, DiagOpts,

308 std::move(StreamOwner));

309 if (CodeGenOpts)

310 Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags);

314 } else {

317 }

318}

319

322 StringRef OutputFile) {

323 auto SerializedConsumer =

325

328 Diags.takeClient(), std::move(SerializedConsumer)));

329 } else {

331 Diags.getClient(), std::move(SerializedConsumer)));

332 }

333}

334

337 bool ShouldOwnClient) {

340}

341

349

350

351

352 if (Client) {

353 Diags->setClient(Client, ShouldOwnClient);

356 } else

358

359

360 if (Opts->VerifyDiagnostics)

362

363

366

370

371

373

374 return Diags;

375}

376

377

378

381 if (!VFS)

382 VFS = FileMgr ? &FileMgr->getVirtualFileSystem()

385 assert(VFS && "FileManager has no VFS?");

387 VFS =

388 llvm::makeIntrusiveRefCntllvm::vfs::TracingFileSystem(std::move(VFS));

390 return FileMgr.get();

391}

392

393

394

397}

398

399

400

405

407

409 FileMgr.getVirtualFileRef(RB.first, RB.second->getBufferSize(), 0);

410

411

412

413

414

417 else

419 FromFile, std::unique_ptrllvm::MemoryBuffer(RB.second));

420 }

421

422

424

426 if (!ToFile) {

427 Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second;

428 continue;

429 }

430

431

434

435

436

438 }

439

442}

443

444

445

448

449

450 TheASTReader.reset();

451

452

456 PP = std::make_shared(Invocation->getPreprocessorOptsPtr(),

459 nullptr,

460 true, TUKind);

463

465 PP->createPreprocessingRecord();

466

467

469 PP->getFileManager(), PPOpts);

470

471

474

475

476

477

478 const llvm::Triple *HeaderSearchTriple = &PP->getTargetInfo().getTriple();

479 if (PP->getTargetInfo().getTriple().getOS() == llvm::Triple::CUDA &&

480 PP->getAuxTargetInfo())

481 HeaderSearchTriple = &PP->getAuxTargetInfo()->getTriple();

482

484 PP->getLangOpts(), *HeaderSearchTriple);

485

487

488 if (PP->getLangOpts().Modules && PP->getLangOpts().ImplicitModules) {

490 PP->getHeaderSearchInfo().setModuleHash(ModuleHash);

491 PP->getHeaderSearchInfo().setModuleCachePath(

493 }

494

495

502

503

504

506 ModuleDepCollector = std::make_shared(

508 }

509

510

511

512 if (ModuleDepCollector) {

514 collectHeaderMaps(PP->getHeaderSearchInfo(), ModuleDepCollector);

517 }

518

519 for (auto &Listener : DependencyCollectors)

520 Listener->attachToPreprocessor(*PP);

521

522

527 if (OutputPath == "-")

528 OutputPath = "";

530 true, OutputPath,

531 false);

532 }

533

536 true, "",

537 true, true);

538 }

539}

540

542

544 if (!SpecificModuleCache.empty() && getHeaderSearchOpts().DisableModuleHash)

545 llvm::sys::path::append(SpecificModuleCache, ModuleHash);

546 return std::string(SpecificModuleCache);

547}

548

549

550

558}

559

560

561

562namespace {

563

564

565

569

570 ReadModuleNames(Preprocessor &PP) : PP(PP) {}

571

572 void ReadModuleName(StringRef ModuleName) override {

573

574

575 LoadedModules.push_back(ModuleName.str());

576 }

577

578 void registerAll() {

580 for (const std::string &LoadedModule : LoadedModules)

583 LoadedModules.clear();

584 }

585

586 void markAllUnavailable() {

587 for (const std::string &LoadedModule : LoadedModules) {

589 LoadedModule)) {

590 M->HasIncompatibleModuleFile = true;

591

592

593

595 Stack.push_back(M);

596 while (!Stack.empty()) {

597 Module *Current = Stack.pop_back_val();

598 if (Current->IsUnimportable) continue;

599 Current->IsAvailable = true;

600 auto SubmodulesRange = Current->submodules();

601 Stack.insert(Stack.end(), SubmodulesRange.begin(),

602 SubmodulesRange.end());

603 }

604 }

605 }

606 LoadedModules.clear();

607 }

608};

609}

610

613 bool AllowPCHWithCompilerErrors, void *DeserializationListener,

614 bool OwnDeserializationListener) {

620 getFrontendOpts().ModuleFileExtensions, DependencyCollectors,

621 DeserializationListener, OwnDeserializationListener, Preamble,

623}

624

626 StringRef Path, StringRef Sysroot,

628 bool AllowPCHWithCompilerErrors, Preprocessor &PP,

631 ArrayRef<std::shared_ptr> Extensions,

632 ArrayRef<std::shared_ptr> DependencyCollectors,

633 void *DeserializationListener, bool OwnDeserializationListener,

634 bool Preamble, bool UseGlobalModuleIndex) {

636

638 PP, ModuleCache, &Context, PCHContainerRdr, Extensions,

639 Sysroot.empty() ? "" : Sysroot.data(), DisableValidation,

640 AllowPCHWithCompilerErrors, false,

642 UseGlobalModuleIndex));

643

644

645

647

648 Reader->setDeserializationListener(

650 OwnDeserializationListener);

651

652 for (auto &Listener : DependencyCollectors)

653 Listener->attachToASTReader(*Reader);

654

655 auto Listener = std::make_unique(PP);

656 auto &ListenerRef = *Listener;

658 std::move(Listener));

659

660 switch (Reader->ReadAST(Path,

666

667

668 PP.setPredefines(Reader->getSuggestedPredefines());

669 ListenerRef.registerAll();

670 return Reader;

671

673

674 break;

675

681

682 break;

683 }

684

685 ListenerRef.markAllUnavailable();

687 return nullptr;

688}

689

690

691

694 unsigned Line,

696

697

699 if (!Entry) {

702 return true;

703 }

704

705

707 return false;

708}

709

712 if (!CompletionConsumer) {

716 return;

718 Loc.Line, Loc.Column)) {

720 return;

721 }

722}

723

725 timerGroup.reset(new llvm::TimerGroup("clang", "Clang time report"));

726 FrontendTimer.reset(new llvm::Timer("frontend", "Front end", *timerGroup));

727}

728

732 unsigned Line,

735 raw_ostream &OS) {

737 return nullptr;

738

739

741}

742

746 TUKind, CompletionConsumer));

747

748

749 TheSema->APINotes.setSwiftVersion(getAPINotesOpts().SwiftVersion);

750

751

752 if (ExternalSemaSrc) {

753 TheSema->addExternalSource(ExternalSemaSrc.get());

754 ExternalSemaSrc->InitializeSema(*TheSema);

755 }

756

757

758

759 if (auto *currentModule = getPreprocessor().getCurrentModule()) {

760 (void)TheSema->APINotes.loadCurrentModuleAPINotes(

761 currentModule, getLangOpts().APINotesModules,

763 }

764}

765

766

767

769

770 assert(hasASTConsumer() && "ASTConsumer should be reset");

771

772 for (OutputFile &OF : OutputFiles) {

773 if (EraseFiles) {

774 if (OF.File)

775 consumeError(OF.File->discard());

776 if (!OF.Filename.empty())

777 llvm::sys::fs::remove(OF.Filename);

778 continue;

779 }

780

781 if (!OF.File)

782 continue;

783

784 if (OF.File->TmpName.empty()) {

785 consumeError(OF.File->discard());

786 continue;

787 }

788

789 llvm::Error E = OF.File->keep(OF.Filename);

790 if (E)

791 continue;

792

794 << OF.File->TmpName << OF.Filename << std::move(E);

795

796 llvm::sys::fs::remove(OF.File->TmpName);

797 }

798 OutputFiles.clear();

799 if (DeleteBuiltModules) {

800 for (auto &Module : BuiltModules)

801 llvm::sys::fs::remove(Module.second);

802 BuiltModules.clear();

803 }

804}

805

807 bool Binary, StringRef InFile, StringRef Extension, bool RemoveFileOnSignal,

808 bool CreateMissingDirectories, bool ForceUseTemporary) {

810 std::optional<SmallString<128>> PathStorage;

811 if (OutputPath.empty()) {

812 if (InFile == "-" || Extension.empty()) {

813 OutputPath = "-";

814 } else {

815 PathStorage.emplace(InFile);

816 llvm::sys::path::replace_extension(*PathStorage, Extension);

817 OutputPath = *PathStorage;

818 }

819 }

820

821 return createOutputFile(OutputPath, Binary, RemoveFileOnSignal,

823 CreateMissingDirectories);

824}

825

827 return std::make_uniquellvm::raw\_null\_ostream();

828}

829

830std::unique_ptr<raw_pwrite_stream>

832 bool RemoveFileOnSignal, bool UseTemporary,

833 bool CreateMissingDirectories) {

835 createOutputFileImpl(OutputPath, Binary, RemoveFileOnSignal, UseTemporary,

836 CreateMissingDirectories);

837 if (OS)

838 return std::move(*OS);

840 << OutputPath << errorToErrorCode(OS.takeError()).message();

841 return nullptr;

842}

843

845CompilerInstance::createOutputFileImpl(StringRef OutputPath, bool Binary,

846 bool RemoveFileOnSignal,

847 bool UseTemporary,

848 bool CreateMissingDirectories) {

849 assert((!CreateMissingDirectories || UseTemporary) &&

850 "CreateMissingDirectories is only allowed when using temporary files");

851

852

853

854 std::optional<SmallString<128>> AbsPath;

855 if (OutputPath != "-" && !llvm::sys::path::is_absolute(OutputPath)) {

857 "File Manager is required to fix up relative path.\n");

858

859 AbsPath.emplace(OutputPath);

860 FileMgr->FixupRelativePath(*AbsPath);

861 OutputPath = *AbsPath;

862 }

863

864 std::unique_ptrllvm::raw\_fd\_ostream OS;

865 std::optional OSFile;

866

867 if (UseTemporary) {

868 if (OutputPath == "-")

869 UseTemporary = false;

870 else {

871 llvm::sys::fs::file_status Status;

872 llvm::sys::fs::status(OutputPath, Status);

873 if (llvm::sys::fs::exists(Status)) {

874

875 if (!llvm::sys::fs::can_write(OutputPath))

876 return llvm::errorCodeToError(

878

879

880

881 if (!llvm::sys::fs::is_regular_file(Status))

882 UseTemporary = false;

883 }

884 }

885 }

886

887 std::optionalllvm::sys::fs::TempFile Temp;

888 if (UseTemporary) {

889

890

891

892

893 StringRef OutputExtension = llvm::sys::path::extension(OutputPath);

895 StringRef(OutputPath).drop_back(OutputExtension.size());

896 TempPath += "-%%%%%%%%";

897 TempPath += OutputExtension;

898 TempPath += ".tmp";

899 llvm::sys::fs::OpenFlags BinaryFlags =

900 Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text;

902 llvm::sys::fs::TempFile::create(

903 TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,

904 BinaryFlags);

905

906 llvm::Error E = handleErrors(

907 ExpectedFile.takeError(), [&](const llvm::ECError &E) -> llvm::Error {

908 std::error_code EC = E.convertToErrorCode();

909 if (CreateMissingDirectories &&

910 EC == llvm::errc::no_such_file_or_directory) {

911 StringRef Parent = llvm::sys::path::parent_path(OutputPath);

912 EC = llvm::sys::fs::create_directories(Parent);

913 if (!EC) {

914 ExpectedFile = llvm::sys::fs::TempFile::create(

915 TempPath, llvm::sys::fs::all_read | llvm::sys::fs::all_write,

916 BinaryFlags);

917 if (!ExpectedFile)

918 return llvm::errorCodeToError(

919 llvm::errc::no_such_file_or_directory);

920 }

921 }

922 return llvm::errorCodeToError(EC);

923 });

924

925 if (E) {

926 consumeError(std::move(E));

927 } else {

928 Temp = std::move(ExpectedFile.get());

929 OS.reset(new llvm::raw_fd_ostream(Temp->FD, false));

930 OSFile = Temp->TmpName;

931 }

932

933

934

935 }

936

937 if (!OS) {

938 OSFile = OutputPath;

939 std::error_code EC;

940 OS.reset(new llvm::raw_fd_ostream(

941 *OSFile, EC,

942 (Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_TextWithCRLF)));

943 if (EC)

944 return llvm::errorCodeToError(EC);

945 }

946

947

948

949 OutputFiles.emplace_back(((OutputPath != "-") ? OutputPath : "").str(),

950 std::move(Temp));

951

952 if (!Binary || OS->supportsSeeking())

953 return std::move(OS);

954

955 return std::make_uniquellvm::buffer\_unique\_ostream(std::move(OS));

956}

957

958

959

963}

964

965

975

979 "Couldn't establish MainFileID!");

980 return true;

981 }

982

983 StringRef InputFile = Input.getFile();

984

985

986 auto FileOrErr = InputFile == "-"

988 : FileMgr.getFileRef(InputFile, true);

989 if (!FileOrErr) {

990 auto EC = llvm::errorToErrorCode(FileOrErr.takeError());

991 if (InputFile != "-")

992 Diags.Report(diag::err_fe_error_reading) << InputFile << EC.message();

993 else

994 Diags.Report(diag::err_fe_error_reading_stdin) << EC.message();

995 return false;

996 }

997

1000

1002 "Couldn't establish MainFileID!");

1003 return true;

1004}

1005

1006

1007

1009 assert(hasDiagnostics() && "Diagnostics engine is not initialized!");

1010 assert(getFrontendOpts().ShowHelp && "Client must handle '-help'!");

1011 assert(getFrontendOpts().ShowVersion && "Client must handle '-version'!");

1012

1013

1014

1015

1017

1018 auto FinishDiagnosticClient = llvm::make_scope_exit([&]() {

1019

1021 });

1022

1024

1026 return false;

1027

1029 return false;

1030

1031

1034

1035

1037 OS << "clang -cc1 version " CLANG_VERSION_STRING << " based upon LLVM "

1038 << LLVM_VERSION_STRING << " default target "

1039 << llvm::sys::getDefaultTargetTriple() << "\n";

1040

1042 llvm::EnableStatistics(false);

1043

1044

1045

1046 llvm::sort(getCodeGenOpts().TocDataVarsUserSpecified);

1048

1050

1051

1054

1056 if (llvm::Error Err = Act.Execute()) {

1057 consumeError(std::move(Err));

1058 }

1060 }

1061 }

1062

1064

1068 OS << '\n';

1069 }

1070 llvm::PrintStatistics(OS);

1071 }

1073 if (!StatsFile.empty()) {

1074 llvm::sys::fs::OpenFlags FileFlags = llvm::sys::fs::OF_TextWithCRLF;

1076 FileFlags |= llvm::sys::fs::OF_Append;

1077 std::error_code EC;

1078 auto StatS =

1079 std::make_uniquellvm::raw\_fd\_ostream(StatsFile, EC, FileFlags);

1080 if (EC) {

1082 << StatsFile << EC.message();

1083 } else {

1084 llvm::PrintStatisticsJSON(*StatS);

1085 }

1086 }

1087

1089}

1090

1093 return;

1094

1096

1097

1098

1101

1102 if (NumWarnings)

1103 OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s");

1104 if (NumWarnings && NumErrors)

1105 OS << " and ";

1106 if (NumErrors)

1107 OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");

1108 if (NumWarnings || NumErrors) {

1109 OS << " generated";

1112 OS << " when compiling for host";

1113 } else {

1115 }

1116 }

1117 OS << ".\n";

1118 }

1119}

1120

1122

1124 std::string Error;

1125 if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))

1127 << Path << Error;

1128 }

1129

1130

1131 for (const FrontendPluginRegistry::entry &Plugin :

1132 FrontendPluginRegistry::entries()) {

1133 std::unique_ptr P(Plugin.instantiate());

1137 break;

1138 }

1139 }

1140}

1141

1142

1143

1145 if (LangOpts.OpenCL)

1147 if (LangOpts.CUDA)

1149 if (LangOpts.ObjC)

1152}

1153

1154

1155

1156

1157static bool

1160 StringRef OriginalModuleMapFile, StringRef ModuleFileName,

1163 llvm::function_ref<void(CompilerInstance &)> PostBuildStep =

1165 llvm::TimeTraceScope TimeScope("Module Compile", ModuleName);

1166

1167

1168

1171 ImportLoc, diag::err_module_rebuild_finalized)

1172 << ModuleName;

1173 return false;

1174 }

1175

1176

1177 auto Invocation =

1178 std::make_shared(ImportingInstance.getInvocation());

1179

1181

1182

1183

1185

1186

1187

1189 llvm::erase_if(PPOpts.Macros,

1190 [&HSOpts](const std::pair<std::string, bool> &def) {

1191 StringRef MacroDef = def.first;

1192 return HSOpts.ModulesIgnoreMacros.contains(

1193 llvm::CachedHashString(MacroDef.split('=').first));

1194 });

1195

1196

1197 Invocation->getLangOpts().ModuleName =

1199

1200

1201 Invocation->getLangOpts().CurrentModule = std::string(ModuleName);

1202

1203

1204

1205

1206 FrontendOptions &FrontendOpts = Invocation->getFrontendOpts();

1207 FrontendOpts.OutputFile = ModuleFileName.str();

1211 FrontendOpts.OriginalModuleMap = std::string(OriginalModuleMapFile);

1212

1214 FrontendOpts.Inputs = {Input};

1215

1216

1218

1220

1221 DiagOpts.VerifyDiagnostics = 0;

1223 Invocation->getModuleHash() && "Module hash mismatch!");

1224

1225

1226

1227

1228

1231 auto &Inv = *Invocation;

1232 Instance.setInvocation(std::move(Invocation));

1233

1234 Instance.createDiagnostics(

1237 true);

1238

1240 Instance.getDiagnostics().setSuppressSystemWarnings(false);

1241

1243 Instance.setFileManager(&ImportingInstance.getFileManager());

1244 } else {

1246 }

1247 Instance.createSourceManager(Instance.getFileManager());

1248 SourceManager &SourceMgr = Instance.getSourceManager();

1249

1250

1251

1256

1257

1258

1259

1263

1264

1265

1266

1269

1271 diag::remark_module_build)

1272 << ModuleName << ModuleFileName;

1273

1274 PreBuildStep(Instance);

1275

1276

1277

1278 bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnThread(

1279 [&]() {

1281 Instance.ExecuteAction(Action);

1282 },

1284

1285 PostBuildStep(Instance);

1286

1288 diag::remark_module_build_done)

1289 << ModuleName;

1290

1291

1294

1295 if (Crashed) {

1296

1297

1298 Instance.setSema(nullptr);

1299 Instance.setASTConsumer(nullptr);

1300

1301

1302 Instance.clearOutputFiles(true);

1303 }

1304

1305

1306

1307 return !Instance.getDiagnostics().hasErrorOccurred() ||

1308 Instance.getFrontendOpts().AllowPCMWithCompilerErrors;

1309}

1310

1313 StringRef Filename = llvm::sys::path::filename(File.getName());

1315 if (Filename == "module_private.map")

1316 llvm::sys::path::append(PublicFilename, "module.map");

1317 else if (Filename == "module.private.modulemap")

1318 llvm::sys::path::append(PublicFilename, "module.modulemap");

1319 else

1320 return std::nullopt;

1322}

1323

1324

1325

1326

1329 StringRef ModuleFileName) {

1332

1333

1339 ModuleMapFID.isValid()) {

1340

1341

1342

1343

1348 }

1349

1352 assert(ModuleMapFile && "Top-level module map with no FileID");

1353

1354

1355

1356

1358 *ModuleMapFile, ImportingInstance.getFileManager()))

1359 ModuleMapFile = PublicMMFile;

1360

1362

1363

1368 } else {

1369

1370

1371

1372

1374 llvm::sys::path::append(FakeModuleMapFile, "__inferred_module.map");

1375

1376 std::string InferredModuleMapContent;

1377 llvm::raw_string_ostream OS(InferredModuleMapContent);

1379

1384 ModuleFileName,

1386 std::unique_ptrllvm::MemoryBuffer ModuleMapBuffer =

1387 llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent);

1388 FileEntryRef ModuleMapFile = Instance.getFileManager().getVirtualFileRef(

1389 FakeModuleMapFile, InferredModuleMapContent.size(), 0);

1390 Instance.getSourceManager().overrideFileContents(

1391 ModuleMapFile, std::move(ModuleMapBuffer));

1392 });

1393 }

1394

1395

1396

1399 }

1400

1402}

1403

1404

1409 bool *OutOfDate) {

1411

1413 if (OutOfDate)

1415

1416

1420 ModuleLoadCapabilities);

1422 return true;

1423

1424

1426 *OutOfDate = true;

1427 return false;

1428 }

1429

1430

1432 Diags.Report(ModuleNameLoc, diag::err_module_not_built)

1434

1435 return false;

1436}

1437

1438

1439

1444 StringRef ModuleFileName) {

1446 ModuleFileName)) {

1448 diag::err_module_not_built)

1450 return false;

1451 }

1452

1454 Module, ModuleFileName,

1455 nullptr);

1456}

1457

1458

1459

1460

1461

1462

1463

1464

1465

1470

1471 Diags.Report(ModuleNameLoc, diag::remark_module_lock)

1473

1474

1475

1476 StringRef Dir = llvm::sys::path::parent_path(ModuleFileName);

1477 llvm::sys::fs::create_directories(Dir);

1478

1479 while (true) {

1480 llvm::LockFileManager Locked(ModuleFileName);

1481 switch (Locked) {

1482 case llvm::LockFileManager::LFS_Error:

1483

1484

1485

1486 Diags.Report(ModuleNameLoc, diag::remark_module_lock_failure)

1487 << Module->Name << Locked.getErrorMessage();

1488

1489 Locked.unsafeRemoveLockFile();

1490 [[fallthrough]];

1491 case llvm::LockFileManager::LFS_Owned:

1492

1494 ModuleNameLoc, Module, ModuleFileName);

1495

1496 case llvm::LockFileManager::LFS_Shared:

1497 break;

1498 }

1499

1500

1501

1502 switch (Locked.waitForUnlock()) {

1503 case llvm::LockFileManager::Res_Success:

1504 break;

1505 case llvm::LockFileManager::Res_OwnerDied:

1506 continue;

1507 case llvm::LockFileManager::Res_Timeout:

1508

1509

1510

1511 Diags.Report(ModuleNameLoc, diag::remark_module_lock_timeout)

1513

1514 Locked.unsafeRemoveLockFile();

1515 continue;

1516 }

1517

1518

1519 bool OutOfDate = false;

1521 Module, ModuleFileName, &OutOfDate))

1522 return true;

1523 if (!OutOfDate)

1524 return false;

1525

1526

1527

1528

1529 }

1530}

1531

1532

1533

1534

1535

1544 ModuleNameLoc, Module,

1545 ModuleFileName)

1547 ModuleNameLoc, Module,

1548 ModuleFileName);

1549}

1550

1551

1552

1557

1558

1559

1560 if (Id->hadMacroDefinition())

1561 return;

1563

1564

1565 MacroInfo *CmdLineDefinition = nullptr;

1566 for (auto *MD = LatestLocalMD; MD; MD = MD->getPrevious()) {

1567

1570 continue;

1571 if (auto *DMD = dyn_cast(MD))

1572 CmdLineDefinition = DMD->getMacroInfo();

1573 break;

1574 }

1575

1577 if (CurrentDefinition == CmdLineDefinition) {

1578

1579 } else if (!CurrentDefinition) {

1580

1581

1582 PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)

1584 auto LatestDef = LatestLocalMD->getDefinition();

1585 assert(LatestDef.isUndefined() &&

1586 "predefined macro went away with no #undef?");

1587 PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here)

1588 << true;

1589 return;

1590 } else if (!CmdLineDefinition) {

1591

1592

1593 PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)

1595 PP.Diag(CurrentDefinition->getDefinitionLoc(),

1596 diag::note_module_def_undef_here)

1597 << false;

1598 } else if (!CurrentDefinition->isIdenticalTo(*CmdLineDefinition, PP,

1599 true)) {

1600

1601 PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)

1603 PP.Diag(CurrentDefinition->getDefinitionLoc(),

1604 diag::note_module_def_undef_here)

1605 << false;

1606 }

1607}

1608

1612 for (const StringRef ConMacro : TopModule->ConfigMacros) {

1614 }

1615}

1616

1617

1619 std::error_code EC;

1620 llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::OF_None);

1621}

1622

1623

1624

1626 llvm::sys::fs::file_status StatBuf;

1629 assert(!TimestampFile.empty());

1630 llvm::sys::path::append(TimestampFile, "modules.timestamp");

1631

1632

1633 if (std::error_code EC = llvm::sys::fs::status(TimestampFile, StatBuf)) {

1634

1635 if (EC == std::errc::no_such_file_or_directory) {

1637 }

1638 return;

1639 }

1640

1641

1642

1643 time_t TimeStampModTime =

1644 llvm::sys::toTimeT(StatBuf.getLastModificationTime());

1645 time_t CurrentTime = time(nullptr);

1647 return;

1648

1649

1650

1651

1653

1654

1655

1656 std::error_code EC;

1657 for (llvm::sys::fs::directory_iterator Dir(HSOpts.ModuleCachePath, EC),

1658 DirEnd;

1659 Dir != DirEnd && !EC; Dir.increment(EC)) {

1660

1661 if (!llvm::sys::fs::is_directory(Dir->path()))

1662 continue;

1663

1664

1665 for (llvm::sys::fs::directory_iterator File(Dir->path(), EC), FileEnd;

1666 File != FileEnd && !EC; File.increment(EC)) {

1667

1668 StringRef Extension = llvm::sys::path::extension(File->path());

1669 if (Extension != ".pcm" && Extension != ".timestamp" &&

1670 llvm::sys::path::filename(File->path()) != "modules.idx")

1671 continue;

1672

1673

1674

1675 if (llvm::sys::fs::status(File->path(), StatBuf))

1676 continue;

1677

1678

1679 time_t FileAccessTime = llvm::sys::toTimeT(StatBuf.getLastAccessedTime());

1680 if (CurrentTime - FileAccessTime <=

1682 continue;

1683 }

1684

1685

1686 llvm::sys::fs::remove(File->path());

1687

1688

1689 std::string TimpestampFilename = File->path() + ".timestamp";

1690 llvm::sys::fs::remove(TimpestampFilename);

1691 }

1692

1693

1694

1695 if (llvm::sys::fs::directory_iterator(Dir->path(), EC) ==

1696 llvm::sys::fs::directory_iterator() && !EC)

1697 llvm::sys::fs::remove(Dir->path());

1698 }

1699}

1700

1702 if (TheASTReader)

1703 return;

1704

1707

1708

1709

1711 getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty() &&

1715 }

1716

1718 std::string Sysroot = HSOpts.Sysroot;

1721 std::unique_ptrllvm::Timer ReadTimer;

1722

1723 if (timerGroup)

1724 ReadTimer = std::make_uniquellvm::Timer("reading_modules",

1725 "Reading modules", *timerGroup);

1729 Sysroot.empty() ? "" : Sysroot.c_str(),

1734 getFrontendOpts().UseGlobalModuleIndex, std::move(ReadTimer));

1736 TheASTReader->setDeserializationListener(

1740 }

1743 TheASTReader->InitializeSema(getSema());

1745 TheASTReader->StartTranslationUnit(&getASTConsumer());

1746

1747 for (auto &Listener : DependencyCollectors)

1748 Listener->attachToASTReader(*TheASTReader);

1749}

1750

1753 llvm::Timer Timer;

1754 if (timerGroup)

1755 Timer.init("preloading." + FileName.str(), "Preloading " + FileName.str(),

1756 *timerGroup);

1757 llvm::TimeRegion TimeLoading(timerGroup ? &Timer : nullptr);

1758

1759

1760 if (!TheASTReader)

1762

1763

1764

1765 bool ConfigMismatchIsRecoverable =

1769

1770 auto Listener = std::make_unique(*PP);

1771 auto &ListenerRef = *Listener;

1773 std::move(Listener));

1774

1775

1776 switch (TheASTReader->ReadAST(

1779 &LoadedModuleFile)) {

1781

1782

1783 ListenerRef.registerAll();

1784 return true;

1785

1787

1790

1791

1792 ListenerRef.markAllUnavailable();

1793 return true;

1794

1795 default:

1796 return false;

1797 }

1798}

1799

1800namespace {

1801enum ModuleSource {

1802 MS_ModuleNotFound,

1803 MS_ModuleCache,

1804 MS_PrebuiltModulePath,

1805 MS_ModuleBuildPragma

1806};

1807}

1808

1809

1810

1812 Module *M, StringRef ModuleName, std::string &ModuleFilename,

1813 const std::map<std::string, std::string, std::less<>> &BuiltModules,

1815 assert(ModuleFilename.empty() && "Already has a module source?");

1816

1817

1818

1819 auto BuiltModuleIt = BuiltModules.find(ModuleName);

1820 if (BuiltModuleIt != BuiltModules.end()) {

1821 ModuleFilename = BuiltModuleIt->second;

1822 return MS_ModuleBuildPragma;

1823 }

1824

1825

1832 if (!ModuleFilename.empty())

1833 return MS_PrebuiltModulePath;

1834 }

1835

1836

1837 if (M) {

1839 return MS_ModuleCache;

1840 }

1841

1842 return MS_ModuleNotFound;

1843}

1844

1845ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(

1847 SourceLocation ModuleNameLoc, bool IsInclusionDirective) {

1848

1851 HS.lookupModule(ModuleName, ImportLoc, true, !IsInclusionDirective);

1852

1853

1854

1855

1856

1857 if (M)

1859

1860

1861 std::string ModuleFilename;

1862 ModuleSource Source =

1863 selectModuleSource(M, ModuleName, ModuleFilename, BuiltModules, HS);

1864 if (Source == MS_ModuleNotFound) {

1865

1867 << ModuleName << SourceRange(ImportLoc, ModuleNameLoc);

1868 return nullptr;

1869 }

1870 if (ModuleFilename.empty()) {

1872

1873

1875 }

1876

1878 << ModuleName;

1879 return nullptr;

1880 }

1881

1882

1885

1886

1887 llvm::Timer Timer;

1888 if (timerGroup)

1889 Timer.init("loading." + ModuleFilename, "Loading " + ModuleFilename,

1890 *timerGroup);

1891 llvm::TimeRegion TimeLoading(timerGroup ? &Timer : nullptr);

1892 llvm::TimeTraceScope TimeScope("Module Load", ModuleName);

1893

1894

1895

1896 unsigned ARRFlags = Source == MS_ModuleCache

1899 : Source == MS_PrebuiltModulePath

1900 ? 0

1902 switch (getASTReader()->ReadAST(ModuleFilename,

1903 Source == MS_PrebuiltModulePath

1905 : Source == MS_ModuleBuildPragma

1908 ImportLoc, ARRFlags)) {

1910 if (M)

1911 return M;

1912 assert(Source != MS_ModuleCache &&

1913 "missing module, but file loaded from cache");

1914

1915

1916

1917 M = HS.lookupModule(ModuleName, ImportLoc, true, !IsInclusionDirective);

1918

1919

1921 if (auto ModuleFile = FileMgr->getOptionalFileRef(ModuleFilename))

1923 return M;

1924

1926 << ModuleName;

1928 }

1929

1932

1933 break;

1934

1936 if (Source == MS_PrebuiltModulePath)

1937

1938

1940 diag::warn_module_config_mismatch)

1941 << ModuleFilename;

1942

1943 [[fallthrough]];

1947

1948

1950

1954 }

1955

1956

1957 if (Source != MS_ModuleCache) {

1958

1959

1960

1962 }

1963

1964

1965 assert(M && "missing module, but trying to compile for cache");

1966

1967

1969 ModuleBuildStack::iterator Pos = ModPath.begin(), PosEnd = ModPath.end();

1970 for (; Pos != PosEnd; ++Pos) {

1971 if (Pos->first == ModuleName)

1972 break;

1973 }

1974

1975 if (Pos != PosEnd) {

1977 for (; Pos != PosEnd; ++Pos) {

1978 CyclePath += Pos->first;

1979 CyclePath += " -> ";

1980 }

1981 CyclePath += ModuleName;

1982

1984 << ModuleName << CyclePath;

1985 return nullptr;

1986 }

1987

1988

1989 if (FailedModules && FailedModules->hasAlreadyFailed(ModuleName)) {

1991 << ModuleName << SourceRange(ImportLoc, ModuleNameLoc);

1992 return nullptr;

1993 }

1994

1995

1997 ModuleFilename)) {

1999 "undiagnosed error in compileModuleAndReadAST");

2000 if (FailedModules)

2001 FailedModules->addFailed(ModuleName);

2002 return nullptr;

2003 }

2004

2005

2006 return M;

2007}

2008

2013 bool IsInclusionDirective) {

2014

2015 StringRef ModuleName = Path[0].first->getName();

2017

2018

2019

2020

2021 if (ImportLoc.isValid() && LastModuleImportLoc == ImportLoc) {

2022

2023 if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule)

2024 TheASTReader->makeModuleVisible(LastModuleImportResult, Visibility,

2025 ImportLoc);

2026 return LastModuleImportResult;

2027 }

2028

2029

2033

2034 Module = *MaybeModule;

2035

2036

2037

2040 } else if (ModuleName == getLangOpts().CurrentModule) {

2041

2043 ModuleName, ImportLoc, true,

2044 !IsInclusionDirective);

2045

2046

2047

2048

2049

2050

2051

2053 } else {

2055 ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective);

2056 if (Result.isNormal())

2059 DisableGeneratingGlobalModuleIndex = true;

2062 }

2063

2064

2065

2068

2069

2070

2071 bool MapPrivateSubModToTopLevel = false;

2072 for (unsigned I = 1, N = Path.size(); I != N; ++I) {

2073 StringRef Name = Path[I].first->getName();

2075

2076

2077

2078

2079

2082 PrivateModule.append("_Private");

2083

2087 PrivPath.push_back(std::make_pair(&II, Path[0].second));

2088

2090

2092 !IsInclusionDirective) ||

2096 if (Sub) {

2097 MapPrivateSubModToTopLevel = true;

2100 diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {

2102 diag::warn_no_priv_submodule_use_toplevel)

2106 PrivateModule);

2108 diag::note_private_top_level_defined);

2109 }

2110 }

2111 }

2112

2113 if (!Sub) {

2114

2116 unsigned BestEditDistance = (std::numeric_limits::max)();

2117

2119 unsigned ED =

2120 Name.edit_distance(SubModule->Name,

2121 true, BestEditDistance);

2122 if (ED <= BestEditDistance) {

2123 if (ED < BestEditDistance) {

2124 Best.clear();

2125 BestEditDistance = ED;

2126 }

2127

2128 Best.push_back(SubModule->Name);

2129 }

2130 }

2131

2132

2133 if (Best.size() == 1) {

2138 Best[0]);

2139

2141 }

2142 }

2143

2144 if (!Sub) {

2145

2146

2150 break;

2151 }

2152

2154 }

2155

2156

2157

2158 if (ModuleName != getLangOpts().CurrentModule) {

2160

2161

2162

2163

2164

2165

2169

2171 }

2172

2173

2178 LastModuleImportLoc = ImportLoc;

2181 }

2182

2183 TheASTReader->makeModuleVisible(Module, Visibility, ImportLoc);

2184 }

2185

2186

2191

2192 LastModuleImportLoc = ImportLoc;

2194 return LastModuleImportResult;

2195}

2196

2198 StringRef ModuleName,

2199 StringRef Source) {

2200

2202 for (auto &C : CleanModuleName)

2204 C = '_';

2205

2206

2207

2208

2210 if (std::error_code EC = llvm::sys::fs::createTemporaryFile(

2211 CleanModuleName, "pcm", ModuleFileName)) {

2213 << ModuleFileName << EC.message();

2214 return;

2215 }

2216 std::string ModuleMapFileName = (CleanModuleName + ".map").str();

2217

2219 ModuleMapFileName,

2222

2223 std::string NullTerminatedSource(Source.str());

2224

2226

2227

2228 FileEntryRef ModuleMapFile = Other.getFileManager().getVirtualFileRef(

2229 ModuleMapFileName, NullTerminatedSource.size(), 0);

2230 Other.getSourceManager().overrideFileContents(

2231 ModuleMapFile, llvm::MemoryBuffer::getMemBuffer(NullTerminatedSource));

2232

2233 Other.BuiltModules = std::move(BuiltModules);

2234 Other.DeleteBuiltModules = false;

2235 };

2236

2238 BuiltModules = std::move(Other.BuiltModules);

2239 };

2240

2241

2242 if (compileModuleImpl(*this, ImportLoc, ModuleName, Input, StringRef(),

2243 ModuleFileName, PreBuildStep, PostBuildStep)) {

2244 BuiltModules[std::string(ModuleName)] = std::string(ModuleFileName);

2245 llvm::sys::RemoveFileOnSignal(ModuleFileName);

2246 }

2247}

2248

2252 if (!TheASTReader)

2254 if (!TheASTReader)

2255 return;

2256

2257 TheASTReader->makeModuleVisible(Mod, Visibility, ImportLoc);

2258}

2259

2262 if (getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty())

2263 return nullptr;

2264 if (!TheASTReader)

2266

2267 if (!TheASTReader)

2268 return nullptr;

2269

2270

2271 TheASTReader->loadGlobalIndex();

2272 GlobalModuleIndex *GlobalIndex = TheASTReader->getGlobalIndex();

2273

2276 llvm::sys::fs::create_directories(

2277 getPreprocessor().getHeaderSearchInfo().getModuleCachePath());

2280 getPreprocessor().getHeaderSearchInfo().getModuleCachePath())) {

2281

2282

2283

2284

2285 consumeError(std::move(Err));

2286 return nullptr;

2287 }

2288 TheASTReader->resetForReload();

2289 TheASTReader->loadGlobalIndex();

2290 GlobalIndex = TheASTReader->getGlobalIndex();

2291 }

2292

2293

2294 if (!HaveFullGlobalModuleIndex && GlobalIndex && buildingModule()) {

2296 bool RecreateIndex = false;

2299 Module *TheModule = I->second;

2301 if (!Entry) {

2303 Path.push_back(std::make_pair(

2305 std::reverse(Path.begin(), Path.end());

2306

2308 RecreateIndex = true;

2309 }

2310 }

2311 if (RecreateIndex) {

2314 getPreprocessor().getHeaderSearchInfo().getModuleCachePath())) {

2315

2316 consumeError(std::move(Err));

2317 return nullptr;

2318 }

2319 TheASTReader->resetForReload();

2320 TheASTReader->loadGlobalIndex();

2321 GlobalIndex = TheASTReader->getGlobalIndex();

2322 }

2323 HaveFullGlobalModuleIndex = true;

2324 }

2325 return GlobalIndex;

2326}

2327

2328

2329bool

2332

2333

2335

2337 TriggerLoc);

2338

2339

2340 if (GlobalIndex) {

2342

2343

2344

2345

2347 return true;

2348 }

2349 }

2350

2351 return false;

2352}

2354

2357 ExternalSemaSrc = std::move(ESS);

2358}

Defines the clang::ASTContext interface.

Defines the Diagnostic-related interfaces.

static void collectVFSEntries(CompilerInstance &CI, std::shared_ptr< ModuleDependencyCollector > MDC)

static bool compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input, StringRef OriginalModuleMapFile, StringRef ModuleFileName, llvm::function_ref< void(CompilerInstance &)> PreBuildStep=[](CompilerInstance &) {}, llvm::function_ref< void(CompilerInstance &)> PostBuildStep=[](CompilerInstance &) {})

Compile a module file for the given module, using the options provided by the importing compiler inst...

static bool EnableCodeCompletion(Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column)

static void pruneModuleCache(const HeaderSearchOptions &HSOpts)

Prune the module cache of modules that haven't been accessed in a long time.

static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName)

Compile a module in a separate compiler instance and read the AST, returning true if the module compi...

static bool compileModuleAndReadASTBehindLock(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName)

Compile a module in a separate compiler instance and read the AST, returning true if the module compi...

static bool readASTAfterCompileModule(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName, bool *OutOfDate)

Read the AST right after compiling the module.

static Language getLanguageFromOptions(const LangOptions &LangOpts)

Determine the appropriate source input kind based on language options.

static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro, Module *Mod, SourceLocation ImportLoc)

Diagnose differences between the current definition of the given configuration macro and the definiti...

static void collectHeaderMaps(const HeaderSearch &HS, std::shared_ptr< ModuleDependencyCollector > MDC)

static ModuleSource selectModuleSource(Module *M, StringRef ModuleName, std::string &ModuleFilename, const std::map< std::string, std::string, std::less<> > &BuiltModules, HeaderSearch &HS)

Select a source for loading the named module and compute the filename to load it from.

static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts, const CodeGenOptions *CodeGenOpts, DiagnosticsEngine &Diags)

static void writeTimestampFile(StringRef TimestampFile)

Write a new timestamp file with the given path.

static void InitializeFileRemapping(DiagnosticsEngine &Diags, SourceManager &SourceMgr, FileManager &FileMgr, const PreprocessorOptions &InitOpts)

static bool compileModule(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName)

Compile a module file for the given module in a separate compiler instance, using the options provide...

static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, DiagnosticsEngine &Diags, StringRef OutputFile)

static void collectIncludePCH(CompilerInstance &CI, std::shared_ptr< ModuleDependencyCollector > MDC)

static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File, FileManager &FileMgr)

static void checkConfigMacros(Preprocessor &PP, Module *M, SourceLocation ImportLoc)

static bool compileModuleAndReadAST(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName)

Compile a module in a separate compiler instance and read the AST, returning true if the module compi...

Defines the clang::FileManager interface and associated types.

Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...

llvm::MachO::Target Target

Defines the clang::Preprocessor interface.

Defines the SourceManager interface.

Defines utilities for dealing with stack allocation and stack space.

Defines version macros and version-related utility functions for Clang.

std::vector< std::string > ModuleSearchPaths

The set of search paths where we API notes can be found for particular modules.

virtual void Initialize(ASTContext &Context)

Initialize - This is called to initialize the consumer, providing the ASTContext.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

void setASTMutationListener(ASTMutationListener *Listener)

Attach an AST mutation listener to the AST context.

void setExternalSource(IntrusiveRefCntPtr< ExternalASTSource > Source)

Attach an external AST source to the AST context.

Abstract interface for callback invocations by the ASTReader.

RAII object to temporarily add an AST callback listener.

Reads an AST files chain containing the contents of a translation unit.

@ ARR_Missing

The client can handle an AST file that cannot load because it is missing.

@ ARR_None

The client can't handle any AST loading failures.

@ ARR_ConfigurationMismatch

The client can handle an AST file that cannot load because it's compiled configuration doesn't match ...

@ ARR_OutOfDate

The client can handle an AST file that cannot load because it is out-of-date relative to its input fi...

@ ARR_TreatModuleWithErrorsAsOutOfDate

If a module file is marked with errors treat it as out-of-date so the caller can rebuild it.

static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const InMemoryModuleCache &ModuleCache, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener, bool ValidateDiagnosticOptions, unsigned ClientLoadCapabilities=ARR_ConfigurationMismatch|ARR_OutOfDate)

Read the control block for the named AST file.

ASTReadResult

The result of reading the control block of an AST file, which can fail for various reasons.

@ Success

The control block was read successfully.

@ ConfigurationMismatch

The AST file was written with a different language/target configuration.

@ OutOfDate

The AST file is out-of-date relative to its input files, and needs to be regenerated.

@ Failure

The AST file itself appears corrupted.

@ VersionMismatch

The AST file was written by a different version of Clang.

@ HadErrors

The AST file has errors.

@ Missing

The AST file was missing.

ChainedDiagnosticConsumer - Chain two diagnostic clients so that diagnostics go to the first client a...

Abstract interface for a consumer of code-completion information.

Options controlling the behavior of code completion.

CodeGenOptions - Track various options which control how the code is optimized and passed to the back...

std::string DwarfDebugFlags

The string to embed in the debug information for the compile unit, if non-empty.

CompilerInstance - Helper class for managing a single instance of the Clang compiler.

void setFileManager(FileManager *Value)

Replace the current file manager and virtual file system.

void setSourceManager(SourceManager *Value)

setSourceManager - Replace the current source manager.

void createPCHExternalASTSource(StringRef Path, DisableValidationForModuleKind DisableValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, bool OwnDeserializationListener)

Create an external AST source to read a PCH file and attach it to the AST context.

DiagnosticConsumer & getDiagnosticClient() const

~CompilerInstance() override

void createPreprocessor(TranslationUnitKind TUKind)

Create the preprocessor, using the invocation, file, and source managers, and replace any existing on...

bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override

Check global module index for missing imports.

void createSourceManager(FileManager &FileMgr)

Create the source manager and replace any existing one with it.

FileManager * createFileManager(IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)

Create the file manager and replace any existing one with it.

DependencyOutputOptions & getDependencyOutputOpts()

bool hasFileManager() const

TargetInfo * getAuxTarget() const

const PCHContainerReader & getPCHContainerReader() const

Return the appropriate PCHContainerReader depending on the current CodeGenOptions.

DiagnosticsEngine & getDiagnostics() const

Get the current diagnostics engine.

GlobalModuleIndex * loadGlobalModuleIndex(SourceLocation TriggerLoc) override

Load, create, or return global module.

raw_ostream & getVerboseOutputStream()

Get the current stream for verbose output.

std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="", bool RemoveFileOnSignal=true, bool CreateMissingDirectories=false, bool ForceUseTemporary=false)

Create the default output file (from the invocation's options) and add it to the list of tracked outp...

void setExternalSemaSource(IntrusiveRefCntPtr< ExternalSemaSource > ESS)

void createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticConsumer *Client=nullptr, bool ShouldOwnClient=true)

Create the diagnostics engine using the invocation's diagnostic options and replace any existing one ...

std::string getSpecificModuleCachePath()

ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) override

Attempt to load the given module.

void setInvocation(std::shared_ptr< CompilerInvocation > Value)

setInvocation - Replace the current invocation.

std::shared_ptr< FailedModulesSet > getFailedModulesSetPtr() const

FileSystemOptions & getFileSystemOpts()

bool InitializeSourceManager(const FrontendInputFile &Input)

InitializeSourceManager - Initialize the source manager to set InputFile as the main file.

FileManager & getFileManager() const

Return the current file manager to the caller.

void setBuildGlobalModuleIndex(bool Build)

Set the flag indicating whether we should (re)build the global module index.

std::unique_ptr< Sema > takeSema()

void printDiagnosticStats()

At the end of a compilation, print the number of warnings/errors.

void setASTConsumer(std::unique_ptr< ASTConsumer > Value)

setASTConsumer - Replace the current AST consumer; the compiler instance takes ownership of Value.

PreprocessorOutputOptions & getPreprocessorOutputOpts()

IntrusiveRefCntPtr< ASTReader > getASTReader() const

void setTarget(TargetInfo *Value)

Replace the current Target.

void setModuleDepCollector(std::shared_ptr< ModuleDependencyCollector > Collector)

InMemoryModuleCache & getModuleCache() const

void addDependencyCollector(std::shared_ptr< DependencyCollector > Listener)

void createASTContext()

Create the AST context.

std::unique_ptr< raw_pwrite_stream > createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, bool UseTemporary, bool CreateMissingDirectories=false)

Create a new output file, optionally deriving the output path name, and add it to the list of tracked...

bool hasASTContext() const

void createModuleFromSource(SourceLocation ImportLoc, StringRef ModuleName, StringRef Source) override

Attempt to create the given module from the specified source buffer.

std::shared_ptr< HeaderSearchOptions > getHeaderSearchOptsPtr() const

void setASTContext(ASTContext *Value)

setASTContext - Replace the current AST context.

Preprocessor & getPreprocessor() const

Return the current preprocessor.

ASTContext & getASTContext() const

void LoadRequestedPlugins()

Load the list of plugins requested in the FrontendOptions.

TargetOptions & getTargetOpts()

void setASTReader(IntrusiveRefCntPtr< ASTReader > Reader)

FrontendOptions & getFrontendOpts()

std::shared_ptr< ModuleDependencyCollector > getModuleDepCollector() const

bool hasDiagnostics() const

void setSema(Sema *S)

Replace the current Sema; the compiler instance takes ownership of S.

HeaderSearchOptions & getHeaderSearchOpts()

void createFrontendTimer()

Create the frontend timer and replace any existing one with it.

void setDiagnostics(DiagnosticsEngine *Value)

setDiagnostics - Replace the current diagnostics engine.

bool hasFailedModulesSet() const

CompilerInvocation & getInvocation()

void setVerboseOutputStream(raw_ostream &Value)

Replace the current stream for verbose output.

PreprocessorOptions & getPreprocessorOpts()

ASTConsumer & getASTConsumer() const

TargetInfo & getTarget() const

llvm::vfs::FileSystem & getVirtualFileSystem() const

void createCodeCompletionConsumer()

Create a code completion consumer using the invocation; note that this will cause the source manager ...

void setCodeCompletionConsumer(CodeCompleteConsumer *Value)

setCodeCompletionConsumer - Replace the current code completion consumer; the compiler instance takes...

bool ExecuteAction(FrontendAction &Act)

ExecuteAction - Execute the provided action against the compiler's CompilerInvocation object.

std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const

void clearOutputFiles(bool EraseFiles)

clearOutputFiles - Clear the output file list.

DiagnosticOptions & getDiagnosticOpts()

LangOptions & getLangOpts()

CodeGenOptions & getCodeGenOpts()

SourceManager & getSourceManager() const

Return the current source manager.

bool shouldBuildGlobalModuleIndex() const

Indicates whether we should (re)build the global module index.

bool hasSourceManager() const

bool hasASTConsumer() const

APINotesOptions & getAPINotesOpts()

std::unique_ptr< raw_pwrite_stream > createNullOutputFile()

void setAuxTarget(TargetInfo *Value)

Replace the current AuxTarget.

void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc) override

Make the given module visible.

void createFailedModulesSet()

bool loadModuleFile(StringRef FileName, serialization::ModuleFile *&LoadedModuleFile)

bool hasPreprocessor() const

void setPreprocessor(std::shared_ptr< Preprocessor > Value)

Replace the current preprocessor.

void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)

Create the Sema object to be used for parsing.

Helper class for holding the data necessary to invoke the compiler.

LangOptions & getLangOpts()

Mutable getters.

FrontendOptions & getFrontendOpts()

std::string getModuleHash() const

Retrieve a module hash string that is suitable for uniquely identifying the conditions under which th...

DependencyOutputOptions - Options for controlling the compiler dependency file generation.

ShowIncludesDestination ShowIncludesDest

Destination of cl.exe style /showIncludes info.

std::string DOTOutputFile

The file to write GraphViz-formatted header dependencies to.

std::string ModuleDependencyOutputDir

The directory to copy module dependencies to when collecting them.

std::string OutputFile

The file to write dependency output to.

std::string HeaderIncludeOutputFile

The file to write header include output to.

unsigned ShowHeaderIncludes

Show header inclusions (-H).

Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...

unsigned getNumErrors() const

virtual void finish()

Callback to inform the diagnostic client that processing of all source files has ended.

unsigned getNumWarnings() const

Used for handling and querying diagnostic IDs.

Options for controlling the compiler diagnostics engine.

std::string DiagnosticLogFile

The file to log diagnostic output to.

std::vector< std::string > SystemHeaderWarningsModules

The list of -Wsystem-headers-in-module=... options used to override whether -Wsystem-headers is enabl...

std::string DiagnosticSerializationFile

The file to serialize diagnostics to (non-appending).

Concrete class used by the front-end to report problems and issues.

DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)

Issue the message to the client.

bool hasErrorOccurred() const

void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)

Set the diagnostic client associated with this diagnostic object.

std::unique_ptr< DiagnosticConsumer > takeClient()

Return the current diagnostic client along with ownership of that client.

DiagnosticConsumer * getClient()

Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const

Based on the way the client configured the DiagnosticsEngine object, classify the specified diagnosti...

bool ownsClient() const

Determine whether this DiagnosticsEngine object own its client.

StringRef getName() const

A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...

StringRef getName() const

The name of this FileEntry.

StringRef getNameAsRequested() const

The name of this FileEntry, as originally requested without applying any remappings for VFS 'use-exte...

An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...

Implements support for file system lookup, file system caching, and directory search management.

void AddStats(const FileManager &Other)

Import statistics from a child FileManager and add them to this current FileManager.

llvm::vfs::FileSystem & getVirtualFileSystem() const

OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)

Get a FileEntryRef if it exists, without doing anything on error.

llvm::Expected< FileEntryRef > getSTDIN()

Get the FileEntryRef for stdin, returning an error if stdin cannot be read.

FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size, time_t ModificationTime)

Retrieve a file entry for a "virtual" file that acts as if there were a file with the given name on d...

OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)

Get a DirectoryEntryRef if it exists, without doing anything on error.

LLVM_DEPRECATED("Functions returning DirectoryEntry are deprecated.", "getOptionalDirectoryRef()") llvm LLVM_DEPRECATED("Functions returning FileEntry are deprecated.", "getOptionalFileRef()") llvm llvm::Expected< FileEntryRef > getFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true, bool IsText=true)

Lookup, cache, and verify the specified directory (real or virtual).

static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)

Create a code modification hint that replaces the given source range with the given code string.

Diagnostic consumer that forwards diagnostics along to an existing, already-initialized diagnostic co...

Abstract base class for actions which can be performed by the frontend.

virtual void EndSourceFile()

Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...

bool PrepareToExecute(CompilerInstance &CI)

Prepare the action to execute on the given compiler instance.

llvm::Error Execute()

Set the source manager's main input file, and run the action.

bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)

Prepare the action for processing the input file Input.

virtual bool isModelParsingAction() const

Is this action invoked on a model file?

An input file for the front end.

llvm::MemoryBufferRef getBuffer() const

InputKind getKind() const

StringRef getFile() const

FrontendOptions - Options for controlling the behavior of the frontend.

unsigned BuildingImplicitModule

Whether we are performing an implicit module build.

unsigned AllowPCMWithCompilerErrors

Output (and read) PCM files regardless of compiler errors.

unsigned BuildingImplicitModuleUsesLock

Whether to use a filesystem lock when building implicit modules.

unsigned ModulesShareFileManager

Whether to share the FileManager when building modules.

std::optional< std::string > AuxTargetCPU

Auxiliary target CPU for CUDA/HIP compilation.

std::string StatsFile

Filename to write statistics to.

std::string OutputFile

The output file, if any.

std::string ActionName

The name of the action to run when using a plugin action.

ParsedSourceLocation CodeCompletionAt

If given, enable code completion at the provided location.

std::string OriginalModuleMap

When the input is a module map, the original module map file from which that map was inferred,...

unsigned GenerateGlobalModuleIndex

Whether we can generate the global module index if needed.

unsigned DisableFree

Disable memory freeing on exit.

SmallVector< FrontendInputFile, 0 > Inputs

The input files and their types.

frontend::ActionKind ProgramAction

The frontend action to perform.

std::optional< std::vector< std::string > > AuxTargetFeatures

Auxiliary target features for CUDA/HIP compilation.

A SourceLocation and its associated SourceManager.

A global index for a set of module files, providing information about the identifiers within those mo...

bool lookupIdentifier(llvm::StringRef Name, HitSet &Hits)

Look for all of the module files with information about the given identifier, e.g....

static llvm::Error writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, llvm::StringRef Path)

Write a global index into the given.

One of these records is kept for each identifier that is lexed.

tok::TokenKind getTokenID() const

If this is a source-language token (e.g.

IdentifierInfo & get(StringRef Name)

Return the identifier token info for the specified named identifier.

In-memory cache for modules.

bool isPCMFinal(llvm::StringRef Filename) const

Check whether the PCM is final and has been shown to work.

The kind of a file that we've been handed as an input.

@ FPE_Default

Used internally to represent initial unspecified value.

@ FPE_Ignore

Assume that floating-point exceptions are masked.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

std::string ModuleName

The module currently being compiled as specified by -fmodule-name.

Encapsulates the data about a macro definition (e.g.

Describes the result of attempting to load a module.

Abstract interface for a module loader.

bool buildingModule() const

Returns true if this instance is building a module.

llvm::StringMap< Module * >::const_iterator module_iterator

Module * findModule(StringRef Name) const

Retrieve a module with the given name.

module_iterator module_begin() const

OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const

std::optional< Module * > getCachedModuleLoad(const IdentifierInfo &II)

Return a cached module load.

module_iterator module_end() const

FileID getContainingModuleMapFileID(const Module *Module) const

Retrieve the module map file containing the definition of the given module.

void resolveLinkAsDependencies(Module *Mod)

Use PendingLinkAsModule information to mark top level link names that are going to be replaced by exp...

void cacheModuleLoad(const IdentifierInfo &II, Module *M)

Cache a module load. M might be nullptr.

Describes a module or submodule.

StringRef getTopLevelModuleName() const

Retrieve the name of the top-level module.

Module * findSubmodule(StringRef Name) const

Find the submodule with the given name.

std::vector< std::string > ConfigMacros

The set of "configuration macros", which are macros that (intentionally) change how this module is bu...

NameVisibilityKind

Describes the visibility of the various names within a particular module.

@ Hidden

All of the names in this module are hidden.

void print(raw_ostream &OS, unsigned Indent=0, bool Dump=false) const

Print the module map for this module to the given stream.

SourceLocation DefinitionLoc

The location of the module definition.

unsigned IsSystem

Whether this is a "system" module (which assumes that all headers in it are system headers).

std::string Name

The name of this module.

llvm::iterator_range< submodule_iterator > submodules()

OptionalDirectoryEntryRef Directory

The build directory of this module.

unsigned IsFromModuleFile

Whether this module was loaded from a module file.

unsigned HasIncompatibleModuleFile

Whether we tried and failed to load a module file for this module.

std::string getFullModuleName(bool AllowStringLiterals=false) const

Retrieve the full name of this module, including the path from its top-level module.

Module * getTopLevelModule()

Retrieve the top-level module for this (sub)module, which may be this module.

OptionalFileEntryRef getASTFile() const

The serialized AST file for this module, if one was created.

This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...

@ ReplaceAction

Replace the main action.

PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...

std::vector< std::pair< std::string, std::string > > RemappedFiles

The set of file remappings, which take existing files on the system (the first part of each pair) and...

std::pair< unsigned, bool > PrecompiledPreambleBytes

If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...

bool RemappedFilesKeepOriginalName

True if the SourceManager should report the original file name for contents of files that were remapp...

void resetNonModularOptions()

Reset any options that are not considered when building a module.

bool RetainRemappedFileBuffers

Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...

bool DetailedRecord

Whether we should maintain a detailed record of all macro definitions and expansions.

std::string ImplicitPCHInclude

The implicit PCH included at the start of the translation unit, or empty.

DisableValidationForModuleKind DisablePCHOrModuleValidation

Whether to disable most of the normal validation performed on precompiled headers and module files.

std::vector< std::pair< std::string, bool > > Macros

std::vector< std::pair< std::string, llvm::MemoryBuffer * > > RemappedFileBuffers

The set of file-to-buffer remappings, which take existing files on the system (the first part of each...

Engages in a tight little dance with the lexer to efficiently preprocess tokens.

void markClangModuleAsAffecting(Module *M)

Mark the given clang module as affecting the current clang module or translation unit.

const MacroInfo * getMacroInfo(const IdentifierInfo *II) const

MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const

Given an identifier, return the latest non-imported macro directive for that identifier.

bool SetCodeCompletionPoint(FileEntryRef File, unsigned Line, unsigned Column)

Specify the point at which code-completion will be performed.

const TranslationUnitKind TUKind

The kind of translation unit we are processing.

IdentifierInfo * getIdentifierInfo(StringRef Name) const

Return information about the specified preprocessor identifier token.

SourceManager & getSourceManager() const

static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, const Module &M, DiagnosticsEngine &Diags)

Check that the given module is available, producing a diagnostic if not.

FileManager & getFileManager() const

FileID getPredefinesFileID() const

Returns the FileID for the preprocessor predefines.

HeaderSearch & getHeaderSearchInfo() const

void setPredefines(std::string P)

Set the predefines for this Preprocessor.

IdentifierTable & getIdentifierTable()

Builtin::Context & getBuiltinInfo()

DiagnosticsEngine & getDiagnostics() const

SelectorTable & getSelectorTable()

DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const

Forwarding function for diagnostics.

A simple code-completion consumer that prints the results it receives in a simple format.

Sema - This implements semantic analysis and AST building for C.

ASTReaderListenter implementation to set SuggestedPredefines of ASTReader which is required to use a ...

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

This class handles loading and caching of source files into memory.

FileID getFileID(SourceLocation SpellingLoc) const

Return the FileID for a SourceLocation.

OptionalFileEntryRef getFileEntryRefForID(FileID FID) const

Returns the FileEntryRef for the provided FileID.

void setModuleBuildStack(ModuleBuildStack stack)

Set the module build stack.

FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)

Create a new FileID that represents the specified file being #included from the specified IncludePosi...

void setOverridenFilesKeepOriginalName(bool value)

Set true if the SourceManager should report the original file name for contents of files that were ov...

ModuleBuildStack getModuleBuildStack() const

Retrieve the module build stack.

FileID getMainFileID() const

Returns the FileID of the main source file.

void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)

Push an entry to the module build stack.

void overrideFileContents(FileEntryRef SourceFile, const llvm::MemoryBufferRef &Buffer)

Override the contents of the given source file by providing an already-allocated buffer.

SourceLocation getIncludeLoc(FileID FID) const

Returns the include location if FID is a #include'd file otherwise it returns an invalid location.

void setMainFileID(FileID FID)

Set the file ID for the main source file.

SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const

Return the file characteristic of the specified source location, indicating whether this is a normal ...

A trivial tuple used to represent a source range.

Exposes information about the current target.

const llvm::Triple & getTriple() const

Returns the target triple of the primary target.

static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)

Construct a target for the given options.

virtual void setAuxTarget(const TargetInfo *Aux)

void noSignedCharForObjCBool()

virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts)

Set forced language options.

std::string CPU

If given, the name of the target CPU to generate code for.

VerifyDiagnosticConsumer - Create a diagnostic client which will use markers in the input source to c...

Information about a module that has been loaded by the ASTReader.

Defines the clang::TargetInfo interface.

CharacteristicKind

Indicates whether a file or directory holds normal user code, system code, or system code which is im...

@ PluginAction

Run a plugin action,.

@ RewriteObjC

ObjC->C Rewriter.

bool Inv(InterpState &S, CodePtr OpPC)

@ MK_PCH

File is a PCH file treated as such.

@ MK_Preamble

File is a PCH file treated as the preamble.

@ MK_ExplicitModule

File is an explicitly-loaded module.

@ MK_ImplicitModule

File is an implicitly-loaded module.

@ MK_PrebuiltModule

File is from a prebuilt module path.

std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)

Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.

The JSON file list parser is used to communicate input to InstallAPI.

void ApplyHeaderSearchOptions(HeaderSearch &HS, const HeaderSearchOptions &HSOpts, const LangOptions &Lang, const llvm::Triple &triple)

Apply the header search options to get given HeaderSearch object.

void noteBottomOfStack()

Call this once on each thread, as soon after starting the thread as feasible, to note the approximate...

void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts, const CodeGenOptions &CodeGenOpts)

InitializePreprocessor - Initialize the preprocessor getting it and the environment ready to process ...

std::error_code make_error_code(BuildPreambleError Error)

LLVM_READONLY bool isAlphanumeric(unsigned char c)

Return true if this character is an ASCII letter or digit: [a-zA-Z0-9].

Language

The language for the input, used to select and validate the language standard and possible actions.

@ C

Languages that the frontend can parse and compile.

@ Result

The result type of a method or function.

IntrusiveRefCntPtr< llvm::vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)

constexpr size_t DesiredStackSize

The amount of stack space that Clang would like to be provided with.

void ProcessWarningOptions(DiagnosticsEngine &Diags, const DiagnosticOptions &Opts, llvm::vfs::FileSystem &VFS, bool ReportDiags=true)

ProcessWarningOptions - Initialize the diagnostic client and process the warning options specified on...

TranslationUnitKind

Describes the kind of translation unit being processed.

void AttachHeaderIncludeGen(Preprocessor &PP, const DependencyOutputOptions &DepOpts, bool ShowAllHeaders=false, StringRef OutputPath={}, bool ShowDepth=true, bool MSStyle=false)

AttachHeaderIncludeGen - Create a header include list generator, and attach it to the given preproces...

DisableValidationForModuleKind

Whether to disable the normal validation performed on precompiled headers and module files when they ...

@ Other

Other implicit parameter.

Visibility

Describes the different kinds of visibility that a declaration may have.

void AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, StringRef SysRoot)

AttachDependencyGraphGen - Create a dependency graph generator, and attach it to the given preprocess...

A source location that has been parsed on the command line.