1 //===--- Tooling.cpp - Running clang standalone tools ---------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements functions to run clang tools standalone instead 11 // of running them as a plugin. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "clang/Tooling/Tooling.h" 16 #include "clang/Driver/Compilation.h" 17 #include "clang/Driver/Driver.h" 18 #include "clang/Driver/Options.h" 19 #include "clang/Driver/Tool.h" 20 #include "clang/Driver/ToolChain.h" 21 #include "clang/Frontend/ASTUnit.h" 22 #include "clang/Frontend/CompilerInstance.h" 23 #include "clang/Frontend/FrontendDiagnostic.h" 24 #include "clang/Frontend/TextDiagnosticPrinter.h" 25 #include "clang/Lex/PreprocessorOptions.h" 26 #include "clang/Tooling/ArgumentsAdjusters.h" 27 #include "clang/Tooling/CompilationDatabase.h" 28 #include "llvm/ADT/STLExtras.h" 29 #include "llvm/Config/llvm-config.h" 30 #include "llvm/Option/ArgList.h" 31 #include "llvm/Option/Option.h" 32 #include "llvm/Support/CommandLine.h" 33 #include "llvm/Support/Debug.h" 34 #include "llvm/Support/FileSystem.h" 35 #include "llvm/Support/Host.h" 36 #include "llvm/Support/Path.h" 37 #include "llvm/Support/raw_ostream.h" 38 #include <utility> 39 40 #define DEBUG_TYPE "clang-tooling" 41 42 namespace clang { 43 namespace tooling { 44 45 ToolAction::~ToolAction() {} 46 47 FrontendActionFactory::~FrontendActionFactory() {} 48 49 // FIXME: This file contains structural duplication with other parts of the 50 // code that sets up a compiler to run tools on it, and we should refactor 51 // it to be based on the same framework. 52 53 /// \brief Builds a clang driver initialized for running clang tools. 54 static clang::driver::Driver *newDriver( 55 clang::DiagnosticsEngine *Diagnostics, const char *BinaryName, 56 IntrusiveRefCntPtr<vfs::FileSystem> VFS) { 57 clang::driver::Driver *CompilerDriver = 58 new clang::driver::Driver(BinaryName, llvm::sys::getDefaultTargetTriple(), 59 *Diagnostics, std::move(VFS)); 60 CompilerDriver->setTitle("clang_based_tool"); 61 return CompilerDriver; 62 } 63 64 /// \brief Retrieves the clang CC1 specific flags out of the compilation's jobs. 65 /// 66 /// Returns NULL on error. 67 static const llvm::opt::ArgStringList *getCC1Arguments( 68 clang::DiagnosticsEngine *Diagnostics, 69 clang::driver::Compilation *Compilation) { 70 // We expect to get back exactly one Command job, if we didn't something 71 // failed. Extract that job from the Compilation. 72 const clang::driver::JobList &Jobs = Compilation->getJobs(); 73 if (Jobs.size() != 1 || !isa<clang::driver::Command>(*Jobs.begin())) { 74 SmallString<256> error_msg; 75 llvm::raw_svector_ostream error_stream(error_msg); 76 Jobs.Print(error_stream, "; ", true); 77 Diagnostics->Report(clang::diag::err_fe_expected_compiler_job) 78 << error_stream.str(); 79 return nullptr; 80 } 81 82 // The one job we find should be to invoke clang again. 83 const clang::driver::Command &Cmd = 84 cast<clang::driver::Command>(*Jobs.begin()); 85 if (StringRef(Cmd.getCreator().getName()) != "clang") { 86 Diagnostics->Report(clang::diag::err_fe_expected_clang_command); 87 return nullptr; 88 } 89 90 return &Cmd.getArguments(); 91 } 92 93 /// \brief Returns a clang build invocation initialized from the CC1 flags. 94 clang::CompilerInvocation *newInvocation( 95 clang::DiagnosticsEngine *Diagnostics, 96 const llvm::opt::ArgStringList &CC1Args) { 97 assert(!CC1Args.empty() && "Must at least contain the program name!"); 98 clang::CompilerInvocation *Invocation = new clang::CompilerInvocation; 99 clang::CompilerInvocation::CreateFromArgs( 100 *Invocation, CC1Args.data() + 1, CC1Args.data() + CC1Args.size(), 101 *Diagnostics); 102 Invocation->getFrontendOpts().DisableFree = false; 103 Invocation->getCodeGenOpts().DisableFree = false; 104 return Invocation; 105 } 106 107 bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code, 108 const Twine &FileName, 109 std::shared_ptr<PCHContainerOperations> PCHContainerOps) { 110 return runToolOnCodeWithArgs(ToolAction, Code, std::vector<std::string>(), 111 FileName, "clang-tool", 112 std::move(PCHContainerOps)); 113 } 114 115 static std::vector<std::string> 116 getSyntaxOnlyToolArgs(const Twine &ToolName, 117 const std::vector<std::string> &ExtraArgs, 118 StringRef FileName) { 119 std::vector<std::string> Args; 120 Args.push_back(ToolName.str()); 121 Args.push_back("-fsyntax-only"); 122 Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end()); 123 Args.push_back(FileName.str()); 124 return Args; 125 } 126 127 bool runToolOnCodeWithArgs( 128 clang::FrontendAction *ToolAction, const Twine &Code, 129 const std::vector<std::string> &Args, const Twine &FileName, 130 const Twine &ToolName, 131 std::shared_ptr<PCHContainerOperations> PCHContainerOps, 132 const FileContentMappings &VirtualMappedFiles) { 133 134 SmallString<16> FileNameStorage; 135 StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); 136 llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem( 137 new vfs::OverlayFileSystem(vfs::getRealFileSystem())); 138 llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( 139 new vfs::InMemoryFileSystem); 140 OverlayFileSystem->pushOverlay(InMemoryFileSystem); 141 llvm::IntrusiveRefCntPtr<FileManager> Files( 142 new FileManager(FileSystemOptions(), OverlayFileSystem)); 143 ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(); 144 ToolInvocation Invocation( 145 getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), 146 ToolAction, Files.get(), 147 std::move(PCHContainerOps)); 148 149 SmallString<1024> CodeStorage; 150 InMemoryFileSystem->addFile(FileNameRef, 0, 151 llvm::MemoryBuffer::getMemBuffer( 152 Code.toNullTerminatedStringRef(CodeStorage))); 153 154 for (auto &FilenameWithContent : VirtualMappedFiles) { 155 InMemoryFileSystem->addFile( 156 FilenameWithContent.first, 0, 157 llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second)); 158 } 159 160 return Invocation.run(); 161 } 162 163 std::string getAbsolutePath(StringRef File) { 164 StringRef RelativePath(File); 165 // FIXME: Should '.\\' be accepted on Win32? 166 if (RelativePath.startswith("./")) { 167 RelativePath = RelativePath.substr(strlen("./")); 168 } 169 170 SmallString<1024> AbsolutePath = RelativePath; 171 std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath); 172 assert(!EC); 173 (void)EC; 174 llvm::sys::path::native(AbsolutePath); 175 return AbsolutePath.str(); 176 } 177 178 void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine, 179 StringRef InvokedAs) { 180 if (!CommandLine.empty() && !InvokedAs.empty()) { 181 bool AlreadyHasTarget = false; 182 bool AlreadyHasMode = false; 183 // Skip CommandLine[0]. 184 for (auto Token = ++CommandLine.begin(); Token != CommandLine.end(); 185 ++Token) { 186 StringRef TokenRef(*Token); 187 AlreadyHasTarget |= 188 (TokenRef == "-target" || TokenRef.startswith("-target=")); 189 AlreadyHasMode |= (TokenRef == "--driver-mode" || 190 TokenRef.startswith("--driver-mode=")); 191 } 192 auto TargetMode = 193 clang::driver::ToolChain::getTargetAndModeFromProgramName(InvokedAs); 194 if (!AlreadyHasMode && TargetMode.DriverMode) { 195 CommandLine.insert(++CommandLine.begin(), TargetMode.DriverMode); 196 } 197 if (!AlreadyHasTarget && TargetMode.TargetIsValid) { 198 CommandLine.insert(++CommandLine.begin(), {"-target", 199 TargetMode.TargetPrefix}); 200 } 201 } 202 } 203 204 namespace { 205 206 class SingleFrontendActionFactory : public FrontendActionFactory { 207 FrontendAction *Action; 208 209 public: 210 SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {} 211 212 FrontendAction *create() override { return Action; } 213 }; 214 215 } 216 217 ToolInvocation::ToolInvocation( 218 std::vector<std::string> CommandLine, ToolAction *Action, 219 FileManager *Files, std::shared_ptr<PCHContainerOperations> PCHContainerOps) 220 : CommandLine(std::move(CommandLine)), Action(Action), OwnsAction(false), 221 Files(Files), PCHContainerOps(std::move(PCHContainerOps)), 222 DiagConsumer(nullptr) {} 223 224 ToolInvocation::ToolInvocation( 225 std::vector<std::string> CommandLine, FrontendAction *FAction, 226 FileManager *Files, std::shared_ptr<PCHContainerOperations> PCHContainerOps) 227 : CommandLine(std::move(CommandLine)), 228 Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true), 229 Files(Files), PCHContainerOps(std::move(PCHContainerOps)), 230 DiagConsumer(nullptr) {} 231 232 ToolInvocation::~ToolInvocation() { 233 if (OwnsAction) 234 delete Action; 235 } 236 237 void ToolInvocation::mapVirtualFile(StringRef FilePath, StringRef Content) { 238 SmallString<1024> PathStorage; 239 llvm::sys::path::native(FilePath, PathStorage); 240 MappedFileContents[PathStorage] = Content; 241 } 242 243 bool ToolInvocation::run() { 244 std::vector<const char*> Argv; 245 for (const std::string &Str : CommandLine) 246 Argv.push_back(Str.c_str()); 247 const char *const BinaryName = Argv[0]; 248 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); 249 unsigned MissingArgIndex, MissingArgCount; 250 std::unique_ptr<llvm::opt::OptTable> Opts = driver::createDriverOptTable(); 251 llvm::opt::InputArgList ParsedArgs = Opts->ParseArgs( 252 ArrayRef<const char *>(Argv).slice(1), MissingArgIndex, MissingArgCount); 253 ParseDiagnosticArgs(*DiagOpts, ParsedArgs); 254 TextDiagnosticPrinter DiagnosticPrinter( 255 llvm::errs(), &*DiagOpts); 256 DiagnosticsEngine Diagnostics( 257 IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, 258 DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); 259 260 const std::unique_ptr<clang::driver::Driver> Driver( 261 newDriver(&Diagnostics, BinaryName, Files->getVirtualFileSystem())); 262 // Since the input might only be virtual, don't check whether it exists. 263 Driver->setCheckInputsExist(false); 264 const std::unique_ptr<clang::driver::Compilation> Compilation( 265 Driver->BuildCompilation(llvm::makeArrayRef(Argv))); 266 if (!Compilation) 267 return false; 268 const llvm::opt::ArgStringList *const CC1Args = getCC1Arguments( 269 &Diagnostics, Compilation.get()); 270 if (!CC1Args) { 271 return false; 272 } 273 std::unique_ptr<clang::CompilerInvocation> Invocation( 274 newInvocation(&Diagnostics, *CC1Args)); 275 // FIXME: remove this when all users have migrated! 276 for (const auto &It : MappedFileContents) { 277 // Inject the code as the given file name into the preprocessor options. 278 std::unique_ptr<llvm::MemoryBuffer> Input = 279 llvm::MemoryBuffer::getMemBuffer(It.getValue()); 280 Invocation->getPreprocessorOpts().addRemappedFile(It.getKey(), 281 Input.release()); 282 } 283 return runInvocation(BinaryName, Compilation.get(), std::move(Invocation), 284 std::move(PCHContainerOps)); 285 } 286 287 bool ToolInvocation::runInvocation( 288 const char *BinaryName, clang::driver::Compilation *Compilation, 289 std::shared_ptr<clang::CompilerInvocation> Invocation, 290 std::shared_ptr<PCHContainerOperations> PCHContainerOps) { 291 // Show the invocation, with -v. 292 if (Invocation->getHeaderSearchOpts().Verbose) { 293 llvm::errs() << "clang Invocation:\n"; 294 Compilation->getJobs().Print(llvm::errs(), "\n", true); 295 llvm::errs() << "\n"; 296 } 297 298 return Action->runInvocation(std::move(Invocation), Files, 299 std::move(PCHContainerOps), DiagConsumer); 300 } 301 302 bool FrontendActionFactory::runInvocation( 303 std::shared_ptr<CompilerInvocation> Invocation, FileManager *Files, 304 std::shared_ptr<PCHContainerOperations> PCHContainerOps, 305 DiagnosticConsumer *DiagConsumer) { 306 // Create a compiler instance to handle the actual work. 307 clang::CompilerInstance Compiler(std::move(PCHContainerOps)); 308 Compiler.setInvocation(std::move(Invocation)); 309 Compiler.setFileManager(Files); 310 311 // The FrontendAction can have lifetime requirements for Compiler or its 312 // members, and we need to ensure it's deleted earlier than Compiler. So we 313 // pass it to an std::unique_ptr declared after the Compiler variable. 314 std::unique_ptr<FrontendAction> ScopedToolAction(create()); 315 316 // Create the compiler's actual diagnostics engine. 317 Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); 318 if (!Compiler.hasDiagnostics()) 319 return false; 320 321 Compiler.createSourceManager(*Files); 322 323 const bool Success = Compiler.ExecuteAction(*ScopedToolAction); 324 325 Files->clearStatCaches(); 326 return Success; 327 } 328 329 ClangTool::ClangTool(const CompilationDatabase &Compilations, 330 ArrayRef<std::string> SourcePaths, 331 std::shared_ptr<PCHContainerOperations> PCHContainerOps, 332 IntrusiveRefCntPtr<vfs::FileSystem> BaseFS) 333 : Compilations(Compilations), SourcePaths(SourcePaths), 334 PCHContainerOps(std::move(PCHContainerOps)), 335 OverlayFileSystem(new vfs::OverlayFileSystem(BaseFS)), 336 InMemoryFileSystem(new vfs::InMemoryFileSystem), 337 Files(new FileManager(FileSystemOptions(), OverlayFileSystem)), 338 DiagConsumer(nullptr) { 339 OverlayFileSystem->pushOverlay(InMemoryFileSystem); 340 appendArgumentsAdjuster(getClangStripOutputAdjuster()); 341 appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster()); 342 appendArgumentsAdjuster(getClangStripDependencyFileAdjuster()); 343 } 344 345 ClangTool::~ClangTool() {} 346 347 void ClangTool::mapVirtualFile(StringRef FilePath, StringRef Content) { 348 MappedFileContents.push_back(std::make_pair(FilePath, Content)); 349 } 350 351 void ClangTool::appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) { 352 ArgsAdjuster = combineAdjusters(std::move(ArgsAdjuster), std::move(Adjuster)); 353 } 354 355 void ClangTool::clearArgumentsAdjusters() { 356 ArgsAdjuster = nullptr; 357 } 358 359 static void injectResourceDir(CommandLineArguments &Args, const char *Argv0, 360 void *MainAddr) { 361 // Allow users to override the resource dir. 362 for (StringRef Arg : Args) 363 if (Arg.startswith("-resource-dir")) 364 return; 365 366 // If there's no override in place add our resource dir. 367 Args.push_back("-resource-dir=" + 368 CompilerInvocation::GetResourcesPath(Argv0, MainAddr)); 369 } 370 371 int ClangTool::run(ToolAction *Action) { 372 // Exists solely for the purpose of lookup of the resource path. 373 // This just needs to be some symbol in the binary. 374 static int StaticSymbol; 375 376 llvm::SmallString<128> InitialDirectory; 377 if (std::error_code EC = llvm::sys::fs::current_path(InitialDirectory)) 378 llvm::report_fatal_error("Cannot detect current path: " + 379 Twine(EC.message())); 380 381 // First insert all absolute paths into the in-memory VFS. These are global 382 // for all compile commands. 383 if (SeenWorkingDirectories.insert("/").second) 384 for (const auto &MappedFile : MappedFileContents) 385 if (llvm::sys::path::is_absolute(MappedFile.first)) 386 InMemoryFileSystem->addFile( 387 MappedFile.first, 0, 388 llvm::MemoryBuffer::getMemBuffer(MappedFile.second)); 389 390 bool ProcessingFailed = false; 391 bool FileSkipped = false; 392 for (const auto &SourcePath : SourcePaths) { 393 std::string File(getAbsolutePath(SourcePath)); 394 395 // Currently implementations of CompilationDatabase::getCompileCommands can 396 // change the state of the file system (e.g. prepare generated headers), so 397 // this method needs to run right before we invoke the tool, as the next 398 // file may require a different (incompatible) state of the file system. 399 // 400 // FIXME: Make the compilation database interface more explicit about the 401 // requirements to the order of invocation of its members. 402 std::vector<CompileCommand> CompileCommandsForFile = 403 Compilations.getCompileCommands(File); 404 if (CompileCommandsForFile.empty()) { 405 llvm::errs() << "Skipping " << File << ". Compile command not found.\n"; 406 FileSkipped = true; 407 continue; 408 } 409 for (CompileCommand &CompileCommand : CompileCommandsForFile) { 410 // FIXME: chdir is thread hostile; on the other hand, creating the same 411 // behavior as chdir is complex: chdir resolves the path once, thus 412 // guaranteeing that all subsequent relative path operations work 413 // on the same path the original chdir resulted in. This makes a 414 // difference for example on network filesystems, where symlinks might be 415 // switched during runtime of the tool. Fixing this depends on having a 416 // file system abstraction that allows openat() style interactions. 417 if (OverlayFileSystem->setCurrentWorkingDirectory( 418 CompileCommand.Directory)) 419 llvm::report_fatal_error("Cannot chdir into \"" + 420 Twine(CompileCommand.Directory) + "\n!"); 421 422 // Now fill the in-memory VFS with the relative file mappings so it will 423 // have the correct relative paths. We never remove mappings but that 424 // should be fine. 425 if (SeenWorkingDirectories.insert(CompileCommand.Directory).second) 426 for (const auto &MappedFile : MappedFileContents) 427 if (!llvm::sys::path::is_absolute(MappedFile.first)) 428 InMemoryFileSystem->addFile( 429 MappedFile.first, 0, 430 llvm::MemoryBuffer::getMemBuffer(MappedFile.second)); 431 432 std::vector<std::string> CommandLine = CompileCommand.CommandLine; 433 if (ArgsAdjuster) 434 CommandLine = ArgsAdjuster(CommandLine, CompileCommand.Filename); 435 assert(!CommandLine.empty()); 436 437 // Add the resource dir based on the binary of this tool. argv[0] in the 438 // compilation database may refer to a different compiler and we want to 439 // pick up the very same standard library that compiler is using. The 440 // builtin headers in the resource dir need to match the exact clang 441 // version the tool is using. 442 // FIXME: On linux, GetMainExecutable is independent of the value of the 443 // first argument, thus allowing ClangTool and runToolOnCode to just 444 // pass in made-up names here. Make sure this works on other platforms. 445 injectResourceDir(CommandLine, "clang_tool", &StaticSymbol); 446 447 // FIXME: We need a callback mechanism for the tool writer to output a 448 // customized message for each file. 449 DEBUG({ llvm::dbgs() << "Processing: " << File << ".\n"; }); 450 ToolInvocation Invocation(std::move(CommandLine), Action, Files.get(), 451 PCHContainerOps); 452 Invocation.setDiagnosticConsumer(DiagConsumer); 453 454 if (!Invocation.run()) { 455 // FIXME: Diagnostics should be used instead. 456 llvm::errs() << "Error while processing " << File << ".\n"; 457 ProcessingFailed = true; 458 } 459 // Return to the initial directory to correctly resolve next file by 460 // relative path. 461 if (OverlayFileSystem->setCurrentWorkingDirectory(InitialDirectory.c_str())) 462 llvm::report_fatal_error("Cannot chdir into \"" + 463 Twine(InitialDirectory) + "\n!"); 464 } 465 } 466 return ProcessingFailed ? 1 : (FileSkipped ? 2 : 0); 467 } 468 469 namespace { 470 471 class ASTBuilderAction : public ToolAction { 472 std::vector<std::unique_ptr<ASTUnit>> &ASTs; 473 474 public: 475 ASTBuilderAction(std::vector<std::unique_ptr<ASTUnit>> &ASTs) : ASTs(ASTs) {} 476 477 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation, 478 FileManager *Files, 479 std::shared_ptr<PCHContainerOperations> PCHContainerOps, 480 DiagnosticConsumer *DiagConsumer) override { 481 std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation( 482 Invocation, std::move(PCHContainerOps), 483 CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(), 484 DiagConsumer, 485 /*ShouldOwnClient=*/false), 486 Files); 487 if (!AST) 488 return false; 489 490 ASTs.push_back(std::move(AST)); 491 return true; 492 } 493 }; 494 } 495 496 int ClangTool::buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs) { 497 ASTBuilderAction Action(ASTs); 498 return run(&Action); 499 } 500 501 std::unique_ptr<ASTUnit> 502 buildASTFromCode(const Twine &Code, const Twine &FileName, 503 std::shared_ptr<PCHContainerOperations> PCHContainerOps) { 504 return buildASTFromCodeWithArgs(Code, std::vector<std::string>(), FileName, 505 "clang-tool", std::move(PCHContainerOps)); 506 } 507 508 std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs( 509 const Twine &Code, const std::vector<std::string> &Args, 510 const Twine &FileName, const Twine &ToolName, 511 std::shared_ptr<PCHContainerOperations> PCHContainerOps, 512 ArgumentsAdjuster Adjuster) { 513 SmallString<16> FileNameStorage; 514 StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); 515 516 std::vector<std::unique_ptr<ASTUnit>> ASTs; 517 ASTBuilderAction Action(ASTs); 518 llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem( 519 new vfs::OverlayFileSystem(vfs::getRealFileSystem())); 520 llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( 521 new vfs::InMemoryFileSystem); 522 OverlayFileSystem->pushOverlay(InMemoryFileSystem); 523 llvm::IntrusiveRefCntPtr<FileManager> Files( 524 new FileManager(FileSystemOptions(), OverlayFileSystem)); 525 526 ToolInvocation Invocation( 527 getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef), 528 &Action, Files.get(), std::move(PCHContainerOps)); 529 530 SmallString<1024> CodeStorage; 531 InMemoryFileSystem->addFile(FileNameRef, 0, 532 llvm::MemoryBuffer::getMemBuffer( 533 Code.toNullTerminatedStringRef(CodeStorage))); 534 if (!Invocation.run()) 535 return nullptr; 536 537 assert(ASTs.size() == 1); 538 return std::move(ASTs[0]); 539 } 540 541 } // end namespace tooling 542 } // end namespace clang 543