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

1

2

3

4

5

6

7

8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

60#include "llvm/Support/VirtualOutputBackends.h"

61#include "llvm/Support/VirtualOutputError.h"

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

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

64#include

65#include <time.h>

66#include

67

68using namespace clang;

69

70CompilerInstance::CompilerInstance(

71 std::shared_ptr Invocation,

72 std::shared_ptr PCHContainerOps,

75 Invocation(std::move(Invocation)),

77 ThePCHContainerOperations(std::move(PCHContainerOps)) {

78 assert(this->Invocation && "Invocation must not be null");

79}

80

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

83}

84

86 return (BuildGlobalModuleIndex ||

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

89 !DisableGeneratingGlobalModuleIndex;

90}

91

94 Diagnostics = std::move(Value);

95}

96

98 OwnedVerboseOutputStream.reset();

99 VerboseOutputStream = &Value;

100}

101

103 OwnedVerboseOutputStream.swap(Value);

104 VerboseOutputStream = OwnedVerboseOutputStream.get();

105}

106

109

111

115 return false;

116

117

118

122 auto &TO = AuxTargetOpts = std::make_unique();

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

163 assert(Value == nullptr ||

165 FileMgr = std::move(Value);

166}

167

170 SourceMgr = std::move(Value);

171}

172

174 PP = std::move(Value);

175}

176

179 Context = std::move(Value);

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(ModCache.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

239 auto PCHDir = FileMgr.getOptionalDirectoryRef(PCHInclude);

240 if (!PCHDir) {

241 MDC->addFile(PCHInclude);

242 return;

243 }

244

245 std::error_code EC;

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

248 llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();

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) {

266

269 if (auto *RedirectingVFS = dyn_castllvm::vfs::RedirectingFileSystem(&VFS))

270 llvm::vfs::collectVFSEntries(*RedirectingVFS, VFSEntries);

271 });

272

273 for (auto &E : VFSEntries)

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

275}

276

281 false);

282

284 std::move(BaseFS));

285

287 VFS =

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

289}

290

291

295 std::error_code EC;

296 std::unique_ptr<raw_ostream> StreamOwner;

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

299

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

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

303 if (EC) {

304 Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)

306 } else {

307 FileOS->SetUnbuffered();

308 OS = FileOS.get();

309 StreamOwner = std::move(FileOS);

310 }

311 }

312

313

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

315 std::move(StreamOwner));

316 if (CodeGenOpts)

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

321 } else {

324 }

325}

326

329 StringRef OutputFile) {

330 auto SerializedConsumer =

332

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

336 } else {

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

339 }

340}

341

343 bool ShouldOwnClient) {

346}

347

352 auto Diags = llvm::makeIntrusiveRefCnt(

354

355

356

357 if (Client) {

358 Diags->setClient(Client, ShouldOwnClient);

361 } else

363

364

365 if (Opts.VerifyDiagnostics)

367

368

371

374

375

377

378 return Diags;

379}

380

381

382

384 assert(VFS && "CompilerInstance needs a VFS for creating FileManager");

385 FileMgr = llvm::makeIntrusiveRefCnt(getFileSystemOpts(), VFS);

386}

387

388

389

391 assert(Diagnostics && "DiagnosticsEngine needed for creating SourceManager");

392 assert(FileMgr && "FileManager needed for creating SourceManager");

393 SourceMgr = llvm::makeIntrusiveRefCnt(getDiagnostics(),

395}

396

397

398

403

405

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

408

409

410

411

412

414 SourceMgr.overrideFileContents(FromFile, RB.second->getMemBufferRef());

415 else

416 SourceMgr.overrideFileContents(

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

418 }

419

420

422

424 if (!ToFile) {

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

426 continue;

427 }

428

429

431 FileMgr.getVirtualFileRef(RF.first, ToFile->getSize(), 0);

432

433

434

435 SourceMgr.overrideFileContents(FromFile, *ToFile);

436 }

437

438 SourceMgr.setOverridenFilesKeepOriginalName(

440}

441

442

443

446

447

448 TheASTReader.reset();

449

450

454 PP = std::make_shared(Invocation->getPreprocessorOpts(),

457 nullptr,

458 true, TUKind);

461

463 PP->createPreprocessingRecord();

464

465

467 PP->getFileManager(), PPOpts);

468

469

472

473

474

475

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

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

478 PP->getAuxTargetInfo())

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

480

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

483

485

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

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

489 PP->getHeaderSearchInfo().setModuleCachePath(

491 }

492

493

500

501

502

504 ModuleDepCollector = std::make_shared(

506 }

507

508

509

510 if (ModuleDepCollector) {

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

515 }

516

517

520

521 for (auto &Listener : DependencyCollectors)

522 Listener->attachToPreprocessor(*PP);

523

524

529 if (OutputPath == "-")

530 OutputPath = "";

532 true, OutputPath,

533 false);

534 }

535

538 true, "",

539 true, true);

540 }

541

542 if (GetDependencyDirectives)

543 PP->setDependencyDirectivesGetter(*GetDependencyDirectives);

544}

545

547 assert(FileMgr && "Specific module cache path requires a FileManager");

548

549

552 SpecificModuleCache);

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

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

555 return std::string(SpecificModuleCache);

556}

557

558

559

562 auto Context = llvm::makeIntrusiveRefCnt(

563 getLangOpts(), PP.getSourceManager(), PP.getIdentifierTable(),

564 PP.getSelectorTable(), PP.getBuiltinInfo(), PP.TUKind);

567}

568

569

570

571namespace {

572

573

574

578

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

580

581 void ReadModuleName(StringRef ModuleName) override {

582

583

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

585 }

586

587 void registerAll() {

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

592 LoadedModules.clear();

593 }

594

595 void markAllUnavailable() {

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

598 LoadedModule)) {

599 M->HasIncompatibleModuleFile = true;

600

601

602

603 SmallVector<Module *, 2> Stack;

604 Stack.push_back(M);

605 while (!Stack.empty()) {

606 Module *Current = Stack.pop_back_val();

609 auto SubmodulesRange = Current->submodules();

610 llvm::append_range(Stack, SubmodulesRange);

611 }

612 }

613 }

614 LoadedModules.clear();

615 }

616};

617}

618

621 bool AllowPCHWithCompilerErrors, void *DeserializationListener,

622 bool OwnDeserializationListener) {

628 getFrontendOpts().ModuleFileExtensions, DependencyCollectors,

629 DeserializationListener, OwnDeserializationListener, Preamble,

631}

632

634 StringRef Path, StringRef Sysroot,

639 ArrayRef<std::shared_ptr> Extensions,

640 ArrayRef<std::shared_ptr> DependencyCollectors,

641 void *DeserializationListener, bool OwnDeserializationListener,

642 bool Preamble, bool UseGlobalModuleIndex) {

644 PP.getHeaderSearchInfo().getHeaderSearchOpts();

645

646 auto Reader = llvm::makeIntrusiveRefCnt(

647 PP, ModCache, &Context, PCHContainerRdr, CodeGenOpts, Extensions,

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

649 AllowPCHWithCompilerErrors, false,

653

654

655

656 Context.setExternalSource(Reader);

657

658 Reader->setDeserializationListener(

660 OwnDeserializationListener);

661

662 for (auto &Listener : DependencyCollectors)

663 Listener->attachToASTReader(*Reader);

664

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

666 auto &ListenerRef = *Listener;

668 std::move(Listener));

669

670 switch (Reader->ReadAST(Path,

676

677

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

679 ListenerRef.registerAll();

680 return Reader;

681

683

684 break;

685

691

692 break;

693 }

694

695 ListenerRef.markAllUnavailable();

696 Context.setExternalSource(nullptr);

697 return nullptr;

698}

699

700

701

703 StringRef Filename,

704 unsigned Line,

706

707

709 if (!Entry) {

711 << Filename;

712 return true;

713 }

714

715

717 return false;

718}

719

722 if (!CompletionConsumer) {

726 return;

730 return;

731 }

732}

733

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

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

737}

738

741 StringRef Filename,

742 unsigned Line,

745 raw_ostream &OS) {

747 return nullptr;

748

749

751}

752

756 TUKind, CompletionConsumer));

757

758

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

760

761

762 if (ExternalSemaSrc) {

763 TheSema->addExternalSource(ExternalSemaSrc);

764 ExternalSemaSrc->InitializeSema(*TheSema);

765 }

766

767

768

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

770 (void)TheSema->APINotes.loadCurrentModuleAPINotes(

771 currentModule, getLangOpts().APINotesModules,

773 }

774}

775

776

777

779

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

781 if (!EraseFiles) {

782 for (auto &O : OutputFiles)

783 llvm::handleAllErrors(

784 O.keep(),

785 [&](const llvm::vfs::TempFileOutputError &E) {

786 getDiagnostics().Report(diag::err_unable_to_rename_temp)

787 << E.getTempPath() << E.getOutputPath()

788 << E.convertToErrorCode().message();

789 },

790 [&](const llvm::vfs::OutputError &E) {

791 getDiagnostics().Report(diag::err_fe_unable_to_open_output)

792 << E.getOutputPath() << E.convertToErrorCode().message();

793 },

794 [&](const llvm::ErrorInfoBase &EIB) {

795 getDiagnostics().Report(diag::err_fe_unable_to_open_output)

796 << O.getPath() << EIB.message();

797 });

798 }

799 OutputFiles.clear();

800 if (DeleteBuiltModules) {

801 for (auto &Module : BuiltModules)

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

803 BuiltModules.clear();

804 }

805}

806

808 bool Binary, StringRef InFile, StringRef Extension, bool RemoveFileOnSignal,

809 bool CreateMissingDirectories, bool ForceUseTemporary) {

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

812 if (OutputPath.empty()) {

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

814 OutputPath = "-";

815 } else {

816 PathStorage.emplace(InFile);

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

818 OutputPath = *PathStorage;

819 }

820 }

821

824 CreateMissingDirectories);

825}

826

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

829}

830

831

832

835 assert(!OutputMgr && "Already has an output manager");

836 OutputMgr = std::move(NewOutputs);

837}

838

840 assert(!OutputMgr && "Already has an output manager");

841 OutputMgr = llvm::makeIntrusiveRefCntllvm::vfs::OnDiskOutputBackend();

842}

843

845 assert(OutputMgr);

846 return *OutputMgr;

847}

848

854

855std::unique_ptr<raw_pwrite_stream>

857 bool RemoveFileOnSignal, bool UseTemporary,

858 bool CreateMissingDirectories) {

860 createOutputFileImpl(OutputPath, Binary, RemoveFileOnSignal, UseTemporary,

861 CreateMissingDirectories);

862 if (OS)

863 return std::move(*OS);

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

866 return nullptr;

867}

868

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

871 bool RemoveFileOnSignal,

872 bool UseTemporary,

873 bool CreateMissingDirectories) {

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

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

876

877

878

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

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

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

883

884 AbsPath.emplace(OutputPath);

886 OutputPath = *AbsPath;

887 }

888

891 OutputPath,

892 OutputConfig()

893 .setTextWithCRLF(Binary)

894 .setDiscardOnSignal(RemoveFileOnSignal)

895 .setAtomicWrite(UseTemporary)

896 .setImplyCreateDirectories(UseTemporary && CreateMissingDirectories));

897 if (!O)

898 return O.takeError();

899

900 O->discardOnDestroy([](llvm::Error E) { consumeError(std::move(E)); });

901 OutputFiles.push_back(std::move(*O));

902 return OutputFiles.back().createProxy();

903}

904

905

906

911

912

922

924 SourceMgr.setMainFileID(SourceMgr.createFileID(Input.getBuffer(), Kind));

925 assert(SourceMgr.getMainFileID().isValid() &&

926 "Couldn't establish MainFileID!");

927 return true;

928 }

929

930 StringRef InputFile = Input.getFile();

931

932

933 auto FileOrErr = InputFile == "-"

934 ? FileMgr.getSTDIN()

935 : FileMgr.getFileRef(InputFile, true);

936 if (!FileOrErr) {

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

938 if (InputFile != "-")

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

940 else

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

942 return false;

943 }

944

945 SourceMgr.setMainFileID(

946 SourceMgr.createFileID(*FileOrErr, SourceLocation(), Kind));

947

948 assert(SourceMgr.getMainFileID().isValid() &&

949 "Couldn't establish MainFileID!");

950 return true;

951}

952

953

954

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

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

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

959

960

961

962

964

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

966

968 });

969

971

973 return false;

974

976 return false;

977

978

981

982

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

985 << LLVM_VERSION_STRING << " default target "

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

987

989 llvm::EnableStatistics(false);

990

991

992

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

995

997

998

1001

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

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

1005 }

1007 }

1008 }

1009

1011

1015 OS << '\n';

1016 }

1017 llvm::PrintStatistics(OS);

1018 }

1020 if (!StatsFile.empty()) {

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

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

1024 std::error_code EC;

1025 auto StatS =

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

1027 if (EC) {

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

1030 } else {

1031 llvm::PrintStatisticsJSON(*StatS);

1032 }

1033 }

1034

1036}

1037

1040 return;

1041

1043

1044

1045

1048

1049 if (NumWarnings)

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

1051 if (NumWarnings && NumErrors)

1052 OS << " and ";

1053 if (NumErrors)

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

1055 if (NumWarnings || NumErrors) {

1056 OS << " generated";

1059 OS << " when compiling for host";

1060 } else {

1061 OS << " when compiling for "

1064 }

1065 }

1066 OS << ".\n";

1067 }

1068}

1069

1071

1072 for (const std::string &Path : getFrontendOpts().Plugins) {

1073 std::string Error;

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

1076 << Path << Error;

1077 }

1078

1079

1080 for (const FrontendPluginRegistry::entry &Plugin :

1081 FrontendPluginRegistry::entries()) {

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

1086 break;

1087 }

1088 }

1089}

1090

1091

1092

1094 if (LangOpts.OpenCL)

1096 if (LangOpts.CUDA)

1098 if (LangOpts.ObjC)

1101}

1102

1103std::unique_ptr CompilerInstance::cloneForModuleCompileImpl(

1105 StringRef OriginalModuleMapFile, StringRef ModuleFileName,

1106 std::optional ThreadSafeConfig) {

1107

1108 auto Invocation = std::make_shared(getInvocation());

1109

1110 PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();

1111

1112

1113

1114 Invocation->resetNonModularOptions();

1115

1116

1117

1118 HeaderSearchOptions &HSOpts = Invocation->getHeaderSearchOpts();

1119 llvm::erase_if(PPOpts.Macros,

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

1121 StringRef MacroDef = def.first;

1122 return HSOpts.ModulesIgnoreMacros.contains(

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

1124 });

1125

1126

1127 Invocation->getLangOpts().ModuleName =

1129

1130

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

1132

1133

1134

1135

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

1137 FrontendOpts.OutputFile = ModuleFileName.str();

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

1142

1144 FrontendOpts.Inputs = {std::move(Input)};

1145

1146

1148

1149 DiagnosticOptions &DiagOpts = Invocation->getDiagnosticOpts();

1150

1151 DiagOpts.VerifyDiagnostics = 0;

1153 "Module hash mismatch!");

1154

1155

1156

1157

1158

1159 auto InstancePtr = std::make_unique(

1161 auto &Instance = *InstancePtr;

1162

1163 auto &Inv = Instance.getInvocation();

1164

1165 if (ThreadSafeConfig) {

1166 Instance.setVirtualFileSystem(ThreadSafeConfig->getVFS());

1167 Instance.createFileManager();

1171 } else {

1173 Instance.createFileManager();

1174 }

1175

1176 if (ThreadSafeConfig) {

1177 Instance.createDiagnostics(&ThreadSafeConfig->getDiagConsumer(),

1178 false);

1179 } else {

1180 Instance.createDiagnostics(

1182 true);

1183 }

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

1186

1187 Instance.createSourceManager();

1188 SourceManager &SourceMgr = Instance.getSourceManager();

1189

1190 if (ThreadSafeConfig) {

1191

1192 } else {

1193

1194

1195 SourceMgr.setModuleBuildStack(getSourceManager().getModuleBuildStack());

1196 SourceMgr.pushModuleBuildStack(

1198 }

1199

1200

1201 Instance.FailedModules = FailedModules;

1202

1203 if (GetDependencyDirectives)

1204 Instance.GetDependencyDirectives =

1205 GetDependencyDirectives->cloneFor(Instance.getFileManager());

1206

1207 if (ThreadSafeConfig) {

1208 Instance.setModuleDepCollector(ThreadSafeConfig->getModuleDepCollector());

1209 } else {

1210

1211

1212

1214 }

1215 Inv.getDependencyOutputOpts() = DependencyOutputOptions();

1216

1217 return InstancePtr;

1218}

1219

1221 StringRef ModuleName,

1222 StringRef ModuleFileName,

1223 CompilerInstance &Instance) {

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

1225

1226

1227

1228 if (getModuleCache().getInMemoryModuleCache().isPCMFinal(ModuleFileName)) {

1230 << ModuleName;

1231 return false;

1232 }

1233

1235 << ModuleName << ModuleFileName;

1236

1237

1238

1239 bool Crashed = !llvm::CrashRecoveryContext().RunSafelyOnNewStack(

1240 [&]() {

1243 },

1245

1247 << ModuleName;

1248

1249

1252

1253

1254 FailedModules = std::move(Instance.FailedModules);

1255

1256 if (Crashed) {

1257

1258

1259 Instance.setSema(nullptr);

1260 Instance.setASTConsumer(nullptr);

1261

1262

1263 Instance.clearOutputFiles(true);

1264 }

1265

1266

1267

1270 }

1271

1272

1273

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

1275 Instance.getFrontendOpts().AllowPCMWithCompilerErrors;

1276}

1277

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

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

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

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

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

1286 else

1287 return std::nullopt;

1288 return FileMgr.getOptionalFileRef(PublicFilename);

1289}

1290

1293 std::optional ThreadSafeConfig) {

1295

1297

1298

1301

1303 ModuleMapFID.isValid()) {

1304

1305

1306

1307

1308 SourceLocation Loc = SourceMgr.getIncludeLoc(ModuleMapFID);

1309 while (Loc.isValid() && isModuleMap(SourceMgr.getFileCharacteristic(Loc))) {

1310 ModuleMapFID = SourceMgr.getFileID(Loc);

1311 Loc = SourceMgr.getIncludeLoc(ModuleMapFID);

1312 }

1313

1315 SourceMgr.getFileEntryRefForID(ModuleMapFID);

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

1317

1318

1319

1320

1323 ModuleMapFile = PublicMMFile;

1324

1326

1327

1328

1329

1330

1331 const SrcMgr::SLocEntry &SLoc = SourceMgr.getSLocEntry(ModuleMapFID);

1333

1334

1335 return cloneForModuleCompileImpl(

1336 ImportLoc, ModuleName,

1339 std::move(ThreadSafeConfig));

1340 }

1341

1342

1343

1344

1345

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

1348

1349 std::string InferredModuleMapContent;

1350 llvm::raw_string_ostream OS(InferredModuleMapContent);

1352

1353 auto Instance = cloneForModuleCompileImpl(

1354 ImportLoc, ModuleName,

1357 std::move(ThreadSafeConfig));

1358

1359 std::unique_ptrllvm::MemoryBuffer ModuleMapBuffer =

1360 llvm::MemoryBuffer::getMemBufferCopy(InferredModuleMapContent);

1361 FileEntryRef ModuleMapFile = Instance->getFileManager().getVirtualFileRef(

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

1363 Instance->getSourceManager().overrideFileContents(ModuleMapFile,

1364 std::move(ModuleMapBuffer));

1365

1366 return Instance;

1367}

1368

1369

1374 bool *OutOfDate, bool *Missing) {

1376

1378 if (OutOfDate)

1380

1381

1385 ModuleLoadCapabilities);

1387 return true;

1388

1389

1391 *OutOfDate = true;

1392 return false;

1393 }

1394

1395

1397 *Missing = true;

1398 return false;

1399 }

1400

1401

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

1405

1406 return false;

1407}

1408

1409

1410

1415 StringRef ModuleFileName) {

1416 {

1418 ModuleNameLoc, Module, ModuleFileName);

1419

1420 if (!ImportingInstance.compileModule(ModuleNameLoc,

1422 ModuleFileName, *Instance)) {

1424 diag::err_module_not_built)

1426 return false;

1427 }

1428 }

1429

1430

1436 }

1437

1439 Module, ModuleFileName,

1440 nullptr, nullptr);

1441}

1442

1443

1444

1445

1446

1447

1448

1449

1450

1455

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

1458

1461

1462 while (true) {

1464 bool Owned;

1465 if (llvm::Error Err = Lock->tryLock().moveInto(Owned)) {

1466

1467

1468

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

1472 ModuleNameLoc, Module, ModuleFileName);

1473 }

1474 if (Owned) {

1475

1477 ModuleNameLoc, Module, ModuleFileName);

1478 }

1479

1480

1481

1482 switch (Lock->waitForUnlockFor(std::chrono::seconds(90))) {

1483 case llvm::WaitForUnlockResult::Success:

1484 break;

1485 case llvm::WaitForUnlockResult::OwnerDied:

1486 continue;

1487 case llvm::WaitForUnlockResult::Timeout:

1488

1489

1490

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

1493

1494 Lock->unsafeMaybeUnlock();

1495 continue;

1496 }

1497

1498

1499 bool OutOfDate = false;

1500 bool Missing = false;

1502 Module, ModuleFileName, &OutOfDate, &Missing))

1503 return true;

1504 if (!OutOfDate && !Missing)

1505 return false;

1506

1507

1508

1509

1510

1511 }

1512}

1513

1514

1515

1516

1517

1526 ModuleNameLoc, Module,

1527 ModuleFileName)

1529 ModuleNameLoc, Module,

1530 ModuleFileName);

1531}

1532

1533

1534

1539

1540

1541

1543 return;

1545

1546

1547 MacroInfo *CmdLineDefinition = nullptr;

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

1549

1550 FileID FID = SourceMgr.getFileID(MD->getLocation());

1552 continue;

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

1554 CmdLineDefinition = DMD->getMacroInfo();

1555 break;

1556 }

1557

1558 auto *CurrentDefinition = PP.getMacroInfo(Id);

1559 if (CurrentDefinition == CmdLineDefinition) {

1560

1561 } else if (!CurrentDefinition) {

1562

1563

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

1566 auto LatestDef = LatestLocalMD->getDefinition();

1567 assert(LatestDef.isUndefined() &&

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

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

1570 << true;

1571 return;

1572 } else if (!CmdLineDefinition) {

1573

1574

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

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

1578 diag::note_module_def_undef_here)

1579 << false;

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

1581 true)) {

1582

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

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

1586 diag::note_module_def_undef_here)

1587 << false;

1588 }

1589}

1590

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

1596 }

1597}

1598

1600 if (TheASTReader)

1601 return;

1602

1605

1606

1607

1609 getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty())

1613

1615 std::string Sysroot = HSOpts.Sysroot;

1618 std::unique_ptrllvm::Timer ReadTimer;

1619

1620 if (timerGroup)

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

1622 "Reading modules", *timerGroup);

1623 TheASTReader = llvm::makeIntrusiveRefCnt(

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

1630 false,

1634 +getFrontendOpts().UseGlobalModuleIndex, std::move(ReadTimer));

1636 TheASTReader->setDeserializationListener(

1640 }

1643 TheASTReader->InitializeSema(getSema());

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

1646

1647 for (auto &Listener : DependencyCollectors)

1648 Listener->attachToASTReader(*TheASTReader);

1649}

1650

1653 llvm::Timer Timer;

1654 if (timerGroup)

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

1656 *timerGroup);

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

1658

1659

1660 if (!TheASTReader)

1662

1663

1664

1665 bool ConfigMismatchIsRecoverable =

1669

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

1671 auto &ListenerRef = *Listener;

1673 std::move(Listener));

1674

1675

1676 switch (TheASTReader->ReadAST(

1679 &LoadedModuleFile)) {

1681

1682

1683 ListenerRef.registerAll();

1684 return true;

1685

1687

1690

1691

1692 ListenerRef.markAllUnavailable();

1693 return true;

1694

1695 default:

1696 return false;

1697 }

1698}

1699

1700namespace {

1701enum ModuleSource {

1702 MS_ModuleNotFound,

1703 MS_ModuleCache,

1704 MS_PrebuiltModulePath,

1705 MS_ModuleBuildPragma

1706};

1707}

1708

1709

1710

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

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

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

1716

1717

1718

1719 auto BuiltModuleIt = BuiltModules.find(ModuleName);

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

1721 ModuleFilename = BuiltModuleIt->second;

1722 return MS_ModuleBuildPragma;

1723 }

1724

1725

1732 if (!ModuleFilename.empty())

1733 return MS_PrebuiltModulePath;

1734 }

1735

1736

1737 if (M) {

1739 return MS_ModuleCache;

1740 }

1741

1742 return MS_ModuleNotFound;

1743}

1744

1745ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(

1747 SourceLocation ModuleNameLoc, bool IsInclusionDirective) {

1748

1749 HeaderSearch &HS = PP->getHeaderSearchInfo();

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

1752

1753

1754

1755

1756

1757 if (M)

1759

1760

1761 std::string ModuleFilename;

1762 ModuleSource Source =

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

1764 if (Source == MS_ModuleNotFound) {

1765

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

1768 return nullptr;

1769 }

1770 if (ModuleFilename.empty()) {

1772

1773

1775 }

1776

1778 << ModuleName;

1779 return nullptr;

1780 }

1781

1782

1785

1786

1787 llvm::Timer Timer;

1788 if (timerGroup)

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

1790 *timerGroup);

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

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

1793

1794

1795

1796 unsigned ARRFlags = Source == MS_ModuleCache

1799 : Source == MS_PrebuiltModulePath

1800 ? 0

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

1803 Source == MS_PrebuiltModulePath

1805 : Source == MS_ModuleBuildPragma

1808 ImportLoc, ARRFlags)) {

1810 if (M)

1811 return M;

1812 assert(Source != MS_ModuleCache &&

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

1814

1815

1816

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

1818

1819

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

1823 return M;

1824

1826 << ModuleName;

1827 return ModuleLoadResult();

1828 }

1829

1832

1833 break;

1834

1836 if (Source == MS_PrebuiltModulePath)

1837

1838

1840 diag::warn_module_config_mismatch)

1841 << ModuleFilename;

1842

1843 [[fallthrough]];

1847

1848

1849 return ModuleLoadResult();

1850

1853 return ModuleLoadResult();

1854 }

1855

1856

1857 if (Source != MS_ModuleCache) {

1858

1859

1860

1861 return ModuleLoadResult();

1862 }

1863

1864

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

1866

1867

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

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

1871 if (Pos->first == ModuleName)

1872 break;

1873 }

1874

1875 if (Pos != PosEnd) {

1876 SmallString<256> CyclePath;

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

1878 CyclePath += Pos->first;

1879 CyclePath += " -> ";

1880 }

1881 CyclePath += ModuleName;

1882

1884 << ModuleName << CyclePath;

1885 return nullptr;

1886 }

1887

1888

1889 if (FailedModules.contains(ModuleName)) {

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

1892 return nullptr;

1893 }

1894

1895

1897 ModuleFilename)) {

1899 "undiagnosed error in compileModuleAndReadAST");

1900 FailedModules.insert(ModuleName);

1901 return nullptr;

1902 }

1903

1904

1905 return M;

1906}

1907

1912 bool IsInclusionDirective) {

1913

1914 StringRef ModuleName = Path[0].getIdentifierInfo()->getName();

1916

1917

1918

1919

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

1921

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

1923 TheASTReader->makeModuleVisible(LastModuleImportResult, Visibility,

1924 ImportLoc);

1925 return LastModuleImportResult;

1926 }

1927

1928

1931 if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].getIdentifierInfo())) {

1932

1933 Module = *MaybeModule;

1934

1935

1936

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

1940

1941 Module = PP->getHeaderSearchInfo().lookupModule(

1942 ModuleName, ImportLoc, true,

1943 !IsInclusionDirective);

1944

1945

1946

1947

1948

1949

1950

1952 } else {

1954 ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective);

1955 if (Result.isNormal())

1958 DisableGeneratingGlobalModuleIndex = true;

1961 }

1962

1963

1964

1967

1968

1969

1970 bool MapPrivateSubModToTopLevel = false;

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

1972 StringRef Name = Path[I].getIdentifierInfo()->getName();

1974

1975

1976

1977

1978

1981 PrivateModule.append("_Private");

1982

1984 auto &II = PP->getIdentifierTable().get(

1985 PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());

1986 PrivPath.emplace_back(Path[0].getLoc(), &II);

1987

1989

1990 if (PP->getHeaderSearchInfo().lookupModule(PrivateModule, ImportLoc, true,

1991 !IsInclusionDirective) ||

1993 PP->getHeaderSearchInfo()) != MS_ModuleNotFound)

1995 if (Sub) {

1996 MapPrivateSubModToTopLevel = true;

1997 PP->markClangModuleAsAffecting(Module);

1999 diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {

2001 diag::warn_no_priv_submodule_use_toplevel)

2003 << PrivateModule

2004 << SourceRange(Path[0].getLoc(), Path[I].getLoc())

2006 PrivateModule);

2008 diag::note_private_top_level_defined);

2009 }

2010 }

2011 }

2012

2013 if (!Sub) {

2014

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

2017

2019 unsigned ED =

2020 Name.edit_distance(SubModule->Name,

2021 true, BestEditDistance);

2022 if (ED <= BestEditDistance) {

2023 if (ED < BestEditDistance) {

2024 Best.clear();

2025 BestEditDistance = ED;

2026 }

2027

2028 Best.push_back(SubModule->Name);

2029 }

2030 }

2031

2032

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

2035 diag::err_no_submodule_suggest)

2037 << Best[0] << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc())

2039 Best[0]);

2040

2042 }

2043 }

2044

2045 if (!Sub) {

2046

2047

2050 << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc());

2051 break;

2052 }

2053

2055 }

2056

2057

2058

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

2061

2062

2063

2064

2065

2066

2069 << SourceRange(Path.front().getLoc(), Path.back().getLoc());

2070

2072 }

2073

2074

2078 << SourceRange(Path.front().getLoc(), Path.back().getLoc());

2079 LastModuleImportLoc = ImportLoc;

2082 }

2083

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

2085 }

2086

2087

2092

2093 LastModuleImportLoc = ImportLoc;

2095 return LastModuleImportResult;

2096}

2097

2099 StringRef ModuleName,

2100 StringRef Source) {

2101

2103 for (auto &C : CleanModuleName)

2105 C = '_';

2106

2107

2108

2109

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

2112 CleanModuleName, "pcm", ModuleFileName)) {

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

2115 return;

2116 }

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

2118

2120 ModuleMapFileName,

2123

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

2125

2126 auto Other = cloneForModuleCompileImpl(ImportLoc, ModuleName, Input,

2127 StringRef(), ModuleFileName);

2128

2129

2130

2131 FileEntryRef ModuleMapFile = Other->getFileManager().getVirtualFileRef(

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

2133 Other->getSourceManager().overrideFileContents(

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

2135

2136 Other->BuiltModules = std::move(BuiltModules);

2137 Other->DeleteBuiltModules = false;

2138

2139

2141

2142 BuiltModules = std::move(Other->BuiltModules);

2143

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

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

2147 }

2148}

2149

2153 if (!TheASTReader)

2155 if (!TheASTReader)

2156 return;

2157

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

2159}

2160

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

2164 return nullptr;

2165 if (!TheASTReader)

2167

2168 if (!TheASTReader)

2169 return nullptr;

2170

2171

2172 TheASTReader->loadGlobalIndex();

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

2174

2177 llvm::sys::fs::create_directories(

2178 getPreprocessor().getHeaderSearchInfo().getModuleCachePath());

2181 getPreprocessor().getHeaderSearchInfo().getModuleCachePath())) {

2182

2183

2184

2185

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

2187 return nullptr;

2188 }

2189 TheASTReader->resetForReload();

2190 TheASTReader->loadGlobalIndex();

2191 GlobalIndex = TheASTReader->getGlobalIndex();

2192 }

2193

2194

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

2197 bool RecreateIndex = false;

2199 E = MMap.module_end(); I != E; ++I) {

2200 Module *TheModule = I->second;

2202 if (!Entry) {

2204 Path.emplace_back(TriggerLoc,

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

2207

2209 RecreateIndex = true;

2210 }

2211 }

2212 if (RecreateIndex) {

2215 getPreprocessor().getHeaderSearchInfo().getModuleCachePath())) {

2216

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

2218 return nullptr;

2219 }

2220 TheASTReader->resetForReload();

2221 TheASTReader->loadGlobalIndex();

2222 GlobalIndex = TheASTReader->getGlobalIndex();

2223 }

2224 HaveFullGlobalModuleIndex = true;

2225 }

2226 return GlobalIndex;

2227}

2228

2229

2230bool

2233

2234

2236

2238 TriggerLoc);

2239

2240

2241 if (GlobalIndex) {

2243

2244

2245

2246

2248 return true;

2249 }

2250 }

2251

2252 return false;

2253}

2255

2258 ExternalSemaSrc = std::move(ESS);

2259}

Defines the clang::ASTContext interface.

Defines the Diagnostic-related interfaces.

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

Definition CompilerInstance.cpp:264

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

Definition CompilerInstance.cpp:702

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...

Definition CompilerInstance.cpp:1411

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

Definition CompilerInstance.cpp:327

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...

Definition CompilerInstance.cpp:1451

static Language getLanguageFromOptions(const LangOptions &LangOpts)

Determine the appropriate source input kind based on language options.

Definition CompilerInstance.cpp:1093

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...

Definition CompilerInstance.cpp:1535

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

Definition CompilerInstance.cpp:223

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.

Definition CompilerInstance.cpp:1711

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

Read the AST right after compiling the module.

Definition CompilerInstance.cpp:1370

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

Definition CompilerInstance.cpp:399

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

Definition CompilerInstance.cpp:231

static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File, FileManager &FileMgr)

Definition CompilerInstance.cpp:1278

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

Definition CompilerInstance.cpp:1591

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...

Definition CompilerInstance.cpp:1518

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

Definition CompilerInstance.cpp:292

Defines the clang::FileManager interface and associated types.

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

Defines the clang::Preprocessor interface.

static std::string toString(const clang::SanitizerSet &Sanitizers)

Produce a string containing comma-separated names of sanitizers in Sanitizers set.

Defines the SourceManager interface.

Defines utilities for dealing with stack allocation and stack space.

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

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.

void ExecuteAction() override

Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.

Abstract interface for callback invocations by the ASTReader.

RAII object to temporarily add an AST callback listener.

@ 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 ModuleCache &ModCache, 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.

bool hasOutputManager() const

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.

Definition CompilerInstance.cpp:619

DiagnosticConsumer & getDiagnosticClient() const

~CompilerInstance() override

Definition CompilerInstance.cpp:81

void createPreprocessor(TranslationUnitKind TUKind)

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

Definition CompilerInstance.cpp:444

bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override

Check global module index for missing imports.

Definition CompilerInstance.cpp:2231

void setOutputManager(IntrusiveRefCntPtr< llvm::vfs::OutputBackend > NewOutputs)

Set the output manager.

Definition CompilerInstance.cpp:833

void createDiagnostics(DiagnosticConsumer *Client=nullptr, bool ShouldOwnClient=true)

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

Definition CompilerInstance.cpp:342

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.

Definition CompilerInstance.cpp:2161

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...

Definition CompilerInstance.cpp:807

void setExternalSemaSource(IntrusiveRefCntPtr< ExternalSemaSource > ESS)

Definition CompilerInstance.cpp:2256

bool compileModule(SourceLocation ImportLoc, StringRef ModuleName, StringRef ModuleFileName, CompilerInstance &Instance)

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

Definition CompilerInstance.cpp:1220

std::string getSpecificModuleCachePath()

std::unique_ptr< CompilerInstance > cloneForModuleCompile(SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName, std::optional< ThreadSafeCloneConfig > ThreadSafeConfig=std::nullopt)

Creates a new CompilerInstance for compiling a module.

Definition CompilerInstance.cpp:1291

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

Attempt to load the given module.

Definition CompilerInstance.cpp:1909

FileSystemOptions & getFileSystemOpts()

bool InitializeSourceManager(const FrontendInputFile &Input)

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

Definition CompilerInstance.cpp:907

void createFileManager()

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

Definition CompilerInstance.cpp:383

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.

void createOutputManager()

Create an output manager.

Definition CompilerInstance.cpp:839

std::unique_ptr< Sema > takeSema()

Definition CompilerInstance.cpp:200

void printDiagnosticStats()

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

Definition CompilerInstance.cpp:1038

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

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

Definition CompilerInstance.cpp:189

PreprocessorOutputOptions & getPreprocessorOutputOpts()

IntrusiveRefCntPtr< FileManager > getFileManagerPtr() const

ModuleCache & getModuleCache() const

IntrusiveRefCntPtr< ASTReader > getASTReader() const

Definition CompilerInstance.cpp:204

void setTarget(TargetInfo *Value)

Replace the current Target.

Definition CompilerInstance.cpp:107

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

Definition CompilerInstance.cpp:218

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

void createASTContext()

Create the AST context.

Definition CompilerInstance.cpp:560

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...

Definition CompilerInstance.cpp:856

bool hasASTContext() const

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

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

Definition CompilerInstance.cpp:2098

Preprocessor & getPreprocessor() const

Return the current preprocessor.

ASTContext & getASTContext() const

IntrusiveRefCntPtr< llvm::vfs::FileSystem > getVirtualFileSystemPtr() const

void LoadRequestedPlugins()

Load the list of plugins requested in the FrontendOptions.

Definition CompilerInstance.cpp:1070

TargetOptions & getTargetOpts()

void createVirtualFileSystem(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS=llvm::vfs::getRealFileSystem(), DiagnosticConsumer *DC=nullptr)

Create a virtual file system instance based on the invocation.

Definition CompilerInstance.cpp:277

void setASTReader(IntrusiveRefCntPtr< ASTReader > Reader)

Definition CompilerInstance.cpp:207

FrontendOptions & getFrontendOpts()

std::shared_ptr< ModuleDependencyCollector > getModuleDepCollector() const

Definition CompilerInstance.cpp:214

bool hasDiagnostics() const

void createASTReader()

Definition CompilerInstance.cpp:1599

void setSema(Sema *S)

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

Definition CompilerInstance.cpp:185

void setSourceManager(llvm::IntrusiveRefCntPtr< SourceManager > Value)

setSourceManager - Replace the current source manager.

Definition CompilerInstance.cpp:168

void setASTContext(llvm::IntrusiveRefCntPtr< ASTContext > Value)

setASTContext - Replace the current AST context.

Definition CompilerInstance.cpp:177

HeaderSearchOptions & getHeaderSearchOpts()

void createFrontendTimer()

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

Definition CompilerInstance.cpp:734

void createSourceManager()

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

Definition CompilerInstance.cpp:390

CompilerInvocation & getInvocation()

void setVerboseOutputStream(raw_ostream &Value)

Replace the current stream for verbose output.

Definition CompilerInstance.cpp:97

PreprocessorOptions & getPreprocessorOpts()

ASTConsumer & getASTConsumer() const

void setFileManager(IntrusiveRefCntPtr< FileManager > Value)

Replace the current file manager.

Definition CompilerInstance.cpp:162

TargetInfo & getTarget() const

llvm::vfs::OutputBackend & getOutputManager()

Definition CompilerInstance.cpp:844

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

void createCodeCompletionConsumer()

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

Definition CompilerInstance.cpp:720

void setCodeCompletionConsumer(CodeCompleteConsumer *Value)

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

Definition CompilerInstance.cpp:196

bool ExecuteAction(FrontendAction &Act)

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

Definition CompilerInstance.cpp:955

std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const

void clearOutputFiles(bool EraseFiles)

clearOutputFiles - Clear the output file list.

Definition CompilerInstance.cpp:778

DiagnosticOptions & getDiagnosticOpts()

LangOptions & getLangOpts()

llvm::vfs::OutputBackend & getOrCreateOutputManager()

Definition CompilerInstance.cpp:849

CodeGenOptions & getCodeGenOpts()

SourceManager & getSourceManager() const

Return the current source manager.

void setDiagnostics(llvm::IntrusiveRefCntPtr< DiagnosticsEngine > Value)

setDiagnostics - Replace the current diagnostics engine.

Definition CompilerInstance.cpp:92

bool shouldBuildGlobalModuleIndex() const

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

Definition CompilerInstance.cpp:85

bool hasSourceManager() const

bool hasASTConsumer() const

APINotesOptions & getAPINotesOpts()

std::unique_ptr< raw_pwrite_stream > createNullOutputFile()

Definition CompilerInstance.cpp:827

void setAuxTarget(TargetInfo *Value)

Replace the current AuxTarget.

Definition CompilerInstance.cpp:108

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

Make the given module visible.

Definition CompilerInstance.cpp:2150

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

Definition CompilerInstance.cpp:1651

bool createTarget()

Definition CompilerInstance.cpp:110

bool hasPreprocessor() const

void resetAndLeakSema()

Definition CompilerInstance.cpp:2254

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

Replace the current preprocessor.

Definition CompilerInstance.cpp:173

void createSema(TranslationUnitKind TUKind, CodeCompleteConsumer *CompletionConsumer)

Create the Sema object to be used for parsing.

Definition CompilerInstance.cpp:753

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

static llvm::IntrusiveRefCntPtr< DiagnosticIDs > create()

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.

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

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

static bool fixupRelativePath(const FileSystemOptions &FileSystemOpts, SmallVectorImpl< char > &Path)

static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)

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

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 global index for a set of module files, providing information about the identifiers within those mo...

llvm::SmallPtrSet< ModuleFile *, 4 > HitSet

A set of module files in which we found a result.

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.

bool hadMacroDefinition() const

Returns true if this identifier was #defined to some value at any moment.

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.

The module cache used for compiling modules implicitly.

virtual void prepareForGetLock(StringRef ModuleFilename)=0

May perform any work that only needs to be performed once for multiple calls getLock() with the same ...

virtual void updateModuleTimestamp(StringRef ModuleFilename)=0

Updates the timestamp denoting the last time inputs of the module file were validated.

virtual std::unique_ptr< llvm::AdvisoryLock > getLock(StringRef ModuleFilename)=0

Returns lock for the given module file. The lock is initially unlocked.

Describes the result of attempting to load a module.

bool buildingModule() const

Returns true if this instance is building a module.

ModuleLoader(bool BuildingModule=false)

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

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.

Module * findOrLoadModule(StringRef Name)

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...

unsigned IsUnimportable

Whether this module has declared itself unimportable, either because it's missing a requirement from ...

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.

unsigned IsAvailable

Whether this module is available in the current translation unit.

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...

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.

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.

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

DiagnosticsEngine & getDiagnostics() const

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.

ModuleBuildStack getModuleBuildStack() const

Retrieve the module build stack.

A trivial tuple used to represent a source range.

CharacteristicKind getFileCharacteristic() const

Return whether this is a system header or not.

This is a discriminated union of FileInfo and ExpansionInfo.

const FileInfo & getFile() const

Exposes information about the current target.

static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, TargetOptions &Opts)

Construct a target for the given options.

const llvm::Triple & getTriple() const

Returns the target triple of the primary target.

virtual void setAuxTarget(const TargetInfo *Aux)

void noSignedCharForObjCBool()

virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts, const TargetInfo *Aux)

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...

@ HeaderSearch

Remove unused header search paths including header maps.

@ 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 &DiagOpts, 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.

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

ArrayRef< IdentifierLoc > ModuleIdPath

A sequence of identifier/location pairs used to describe a particular module or submodule,...

ArrayRef< std::pair< std::string, FullSourceLoc > > ModuleBuildStack

The stack used when building modules on demand, which is used to provide a link between the source ma...

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

Apply the header search options to get given HeaderSearch object.

@ Success

Annotation was successful.

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 ...

LLVM_READONLY bool isAlphanumeric(unsigned char c)

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

@ Module

Module linkage, which indicates that the entity can be referred to from other translation units withi...

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)

void normalizeModuleCachePath(FileManager &FileMgr, StringRef Path, SmallVectorImpl< char > &NormalizedPath)

constexpr size_t DesiredStackSize

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

IntrusiveRefCntPtr< ModuleCache > createCrossProcessModuleCache()

Creates new ModuleCache backed by a file system directory that may be operated on by multiple process...

void noteBottomOfStack(bool ForceSet=false)

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

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.