clang  10.0.0svn
CrossTranslationUnit.cpp
Go to the documentation of this file.
1 //===--- CrossTranslationUnit.cpp - -----------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the CrossTranslationUnit interface.
10 //
11 //===----------------------------------------------------------------------===//
13 #include "clang/AST/ASTImporter.h"
14 #include "clang/AST/Decl.h"
15 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Frontend/ASTUnit.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/ADT/Statistic.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Support/Path.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include <fstream>
28 #include <sstream>
29 
30 namespace clang {
31 namespace cross_tu {
32 
33 namespace {
34 
35 #define DEBUG_TYPE "CrossTranslationUnit"
36 STATISTIC(NumGetCTUCalled, "The # of getCTUDefinition function called");
37 STATISTIC(
38  NumNotInOtherTU,
39  "The # of getCTUDefinition called but the function is not in any other TU");
40 STATISTIC(NumGetCTUSuccess,
41  "The # of getCTUDefinition successfully returned the "
42  "requested function's body");
43 STATISTIC(NumUnsupportedNodeFound, "The # of imports when the ASTImporter "
44  "encountered an unsupported AST Node");
45 STATISTIC(NumNameConflicts, "The # of imports when the ASTImporter "
46  "encountered an ODR error");
47 STATISTIC(NumTripleMismatch, "The # of triple mismatches");
48 STATISTIC(NumLangMismatch, "The # of language mismatches");
49 STATISTIC(NumLangDialectMismatch, "The # of language dialect mismatches");
50 STATISTIC(NumASTLoadThresholdReached,
51  "The # of ASTs not loaded because of threshold");
52 
53 // Same as Triple's equality operator, but we check a field only if that is
54 // known in both instances.
55 bool hasEqualKnownFields(const llvm::Triple &Lhs, const llvm::Triple &Rhs) {
56  using llvm::Triple;
57  if (Lhs.getArch() != Triple::UnknownArch &&
58  Rhs.getArch() != Triple::UnknownArch && Lhs.getArch() != Rhs.getArch())
59  return false;
60  if (Lhs.getSubArch() != Triple::NoSubArch &&
61  Rhs.getSubArch() != Triple::NoSubArch &&
62  Lhs.getSubArch() != Rhs.getSubArch())
63  return false;
64  if (Lhs.getVendor() != Triple::UnknownVendor &&
65  Rhs.getVendor() != Triple::UnknownVendor &&
66  Lhs.getVendor() != Rhs.getVendor())
67  return false;
68  if (!Lhs.isOSUnknown() && !Rhs.isOSUnknown() &&
69  Lhs.getOS() != Rhs.getOS())
70  return false;
71  if (Lhs.getEnvironment() != Triple::UnknownEnvironment &&
72  Rhs.getEnvironment() != Triple::UnknownEnvironment &&
73  Lhs.getEnvironment() != Rhs.getEnvironment())
74  return false;
75  if (Lhs.getObjectFormat() != Triple::UnknownObjectFormat &&
76  Rhs.getObjectFormat() != Triple::UnknownObjectFormat &&
77  Lhs.getObjectFormat() != Rhs.getObjectFormat())
78  return false;
79  return true;
80 }
81 
82 // FIXME: This class is will be removed after the transition to llvm::Error.
83 class IndexErrorCategory : public std::error_category {
84 public:
85  const char *name() const noexcept override { return "clang.index"; }
86 
87  std::string message(int Condition) const override {
88  switch (static_cast<index_error_code>(Condition)) {
90  return "An unknown error has occurred.";
92  return "The index file is missing.";
94  return "Invalid index file format.";
96  return "Multiple definitions in the index file.";
98  return "Missing definition from the index file.";
100  return "Failed to import the definition.";
102  return "Failed to load external AST source.";
104  return "Failed to generate USR.";
106  return "Triple mismatch";
108  return "Language mismatch";
110  return "Language dialect mismatch";
112  return "Load threshold reached";
113  }
114  llvm_unreachable("Unrecognized index_error_code.");
115  }
116 };
117 
118 static llvm::ManagedStatic<IndexErrorCategory> Category;
119 } // end anonymous namespace
120 
121 char IndexError::ID;
122 
123 void IndexError::log(raw_ostream &OS) const {
124  OS << Category->message(static_cast<int>(Code)) << '\n';
125 }
126 
127 std::error_code IndexError::convertToErrorCode() const {
128  return std::error_code(static_cast<int>(Code), *Category);
129 }
130 
132 parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir) {
133  std::ifstream ExternalMapFile(IndexPath);
134  if (!ExternalMapFile)
135  return llvm::make_error<IndexError>(index_error_code::missing_index_file,
136  IndexPath.str());
137 
138  llvm::StringMap<std::string> Result;
139  std::string Line;
140  unsigned LineNo = 1;
141  while (std::getline(ExternalMapFile, Line)) {
142  const size_t Pos = Line.find(" ");
143  if (Pos > 0 && Pos != std::string::npos) {
144  StringRef LineRef{Line};
145  StringRef LookupName = LineRef.substr(0, Pos);
146  if (Result.count(LookupName))
147  return llvm::make_error<IndexError>(
148  index_error_code::multiple_definitions, IndexPath.str(), LineNo);
149  StringRef FileName = LineRef.substr(Pos + 1);
150  SmallString<256> FilePath = CrossTUDir;
151  llvm::sys::path::append(FilePath, FileName);
152  Result[LookupName] = FilePath.str().str();
153  } else
154  return llvm::make_error<IndexError>(
155  index_error_code::invalid_index_format, IndexPath.str(), LineNo);
156  LineNo++;
157  }
158  return Result;
159 }
160 
161 std::string
162 createCrossTUIndexString(const llvm::StringMap<std::string> &Index) {
163  std::ostringstream Result;
164  for (const auto &E : Index)
165  Result << E.getKey().str() << " " << E.getValue() << '\n';
166  return Result.str();
167 }
168 
169 bool containsConst(const VarDecl *VD, const ASTContext &ACtx) {
170  CanQualType CT = ACtx.getCanonicalType(VD->getType());
171  if (!CT.isConstQualified()) {
172  const RecordType *RTy = CT->getAs<RecordType>();
173  if (!RTy || !RTy->hasConstFields())
174  return false;
175  }
176  return true;
177 }
178 
179 static bool hasBodyOrInit(const FunctionDecl *D, const FunctionDecl *&DefD) {
180  return D->hasBody(DefD);
181 }
182 static bool hasBodyOrInit(const VarDecl *D, const VarDecl *&DefD) {
183  return D->getAnyInitializer(DefD);
184 }
185 template <typename T> static bool hasBodyOrInit(const T *D) {
186  const T *Unused;
187  return hasBodyOrInit(D, Unused);
188 }
189 
191  : Context(CI.getASTContext()), ASTStorage(CI) {}
192 
194 
197  SmallString<128> DeclUSR;
198  bool Ret = index::generateUSRForDecl(ND, DeclUSR);
199  if (Ret)
200  return {};
201  return std::string(DeclUSR.str());
202 }
203 
204 /// Recursively visits the decls of a DeclContext, and returns one with the
205 /// given USR.
206 template <typename T>
207 const T *
208 CrossTranslationUnitContext::findDefInDeclContext(const DeclContext *DC,
209  StringRef LookupName) {
210  assert(DC && "Declaration Context must not be null");
211  for (const Decl *D : DC->decls()) {
212  const auto *SubDC = dyn_cast<DeclContext>(D);
213  if (SubDC)
214  if (const auto *ND = findDefInDeclContext<T>(SubDC, LookupName))
215  return ND;
216 
217  const auto *ND = dyn_cast<T>(D);
218  const T *ResultDecl;
219  if (!ND || !hasBodyOrInit(ND, ResultDecl))
220  continue;
221  llvm::Optional<std::string> ResultLookupName = getLookupName(ResultDecl);
222  if (!ResultLookupName || *ResultLookupName != LookupName)
223  continue;
224  return ResultDecl;
225  }
226  return nullptr;
227 }
228 
229 template <typename T>
230 llvm::Expected<const T *> CrossTranslationUnitContext::getCrossTUDefinitionImpl(
231  const T *D, StringRef CrossTUDir, StringRef IndexName,
232  bool DisplayCTUProgress) {
233  assert(D && "D is missing, bad call to this function!");
234  assert(!hasBodyOrInit(D) &&
235  "D has a body or init in current translation unit!");
236  ++NumGetCTUCalled;
237  const llvm::Optional<std::string> LookupName = getLookupName(D);
238  if (!LookupName)
239  return llvm::make_error<IndexError>(
241  llvm::Expected<ASTUnit *> ASTUnitOrError =
242  loadExternalAST(*LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
243  if (!ASTUnitOrError)
244  return ASTUnitOrError.takeError();
245  ASTUnit *Unit = *ASTUnitOrError;
246  assert(&Unit->getFileManager() ==
248 
249  const llvm::Triple &TripleTo = Context.getTargetInfo().getTriple();
250  const llvm::Triple &TripleFrom =
252  // The imported AST had been generated for a different target.
253  // Some parts of the triple in the loaded ASTContext can be unknown while the
254  // very same parts in the target ASTContext are known. Thus we check for the
255  // known parts only.
256  if (!hasEqualKnownFields(TripleTo, TripleFrom)) {
257  // TODO: Pass the SourceLocation of the CallExpression for more precise
258  // diagnostics.
259  ++NumTripleMismatch;
260  return llvm::make_error<IndexError>(index_error_code::triple_mismatch,
261  Unit->getMainFileName(), TripleTo.str(),
262  TripleFrom.str());
263  }
264 
265  const auto &LangTo = Context.getLangOpts();
266  const auto &LangFrom = Unit->getASTContext().getLangOpts();
267 
268  // FIXME: Currenty we do not support CTU across C++ and C and across
269  // different dialects of C++.
270  if (LangTo.CPlusPlus != LangFrom.CPlusPlus) {
271  ++NumLangMismatch;
272  return llvm::make_error<IndexError>(index_error_code::lang_mismatch);
273  }
274 
275  // If CPP dialects are different then return with error.
276  //
277  // Consider this STL code:
278  // template<typename _Alloc>
279  // struct __alloc_traits
280  // #if __cplusplus >= 201103L
281  // : std::allocator_traits<_Alloc>
282  // #endif
283  // { // ...
284  // };
285  // This class template would create ODR errors during merging the two units,
286  // since in one translation unit the class template has a base class, however
287  // in the other unit it has none.
288  if (LangTo.CPlusPlus11 != LangFrom.CPlusPlus11 ||
289  LangTo.CPlusPlus14 != LangFrom.CPlusPlus14 ||
290  LangTo.CPlusPlus17 != LangFrom.CPlusPlus17 ||
291  LangTo.CPlusPlus2a != LangFrom.CPlusPlus2a) {
292  ++NumLangDialectMismatch;
293  return llvm::make_error<IndexError>(
295  }
296 
298  if (const T *ResultDecl = findDefInDeclContext<T>(TU, *LookupName))
299  return importDefinition(ResultDecl, Unit);
300  return llvm::make_error<IndexError>(index_error_code::failed_import);
301 }
302 
305  StringRef CrossTUDir,
306  StringRef IndexName,
307  bool DisplayCTUProgress) {
308  return getCrossTUDefinitionImpl(FD, CrossTUDir, IndexName,
309  DisplayCTUProgress);
310 }
311 
314  StringRef CrossTUDir,
315  StringRef IndexName,
316  bool DisplayCTUProgress) {
317  return getCrossTUDefinitionImpl(VD, CrossTUDir, IndexName,
318  DisplayCTUProgress);
319 }
320 
322  switch (IE.getCode()) {
324  Context.getDiagnostics().Report(diag::err_ctu_error_opening)
325  << IE.getFileName();
326  break;
328  Context.getDiagnostics().Report(diag::err_extdefmap_parsing)
329  << IE.getFileName() << IE.getLineNum();
330  break;
332  Context.getDiagnostics().Report(diag::err_multiple_def_index)
333  << IE.getLineNum();
334  break;
336  Context.getDiagnostics().Report(diag::warn_ctu_incompat_triple)
337  << IE.getFileName() << IE.getTripleToName() << IE.getTripleFromName();
338  break;
339  default:
340  break;
341  }
342 }
343 
344 CrossTranslationUnitContext::ASTFileLoader::ASTFileLoader(
345  const CompilerInstance &CI)
346  : CI(CI) {}
347 
348 std::unique_ptr<ASTUnit>
349 CrossTranslationUnitContext::ASTFileLoader::operator()(StringRef ASTFilePath) {
350  // Load AST from ast-dump.
352  TextDiagnosticPrinter *DiagClient =
353  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
356  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
357 
359  ASTFilePath, CI.getPCHContainerOperations()->getRawReader(),
361 }
362 
363 CrossTranslationUnitContext::ASTUnitStorage::ASTUnitStorage(
364  const CompilerInstance &CI)
365  : FileAccessor(CI), LoadGuard(const_cast<CompilerInstance &>(CI)
366  .getAnalyzerOpts()
367  ->CTUImportThreshold) {}
368 
370 CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFile(
371  StringRef FileName, bool DisplayCTUProgress) {
372  // Try the cache first.
373  auto ASTCacheEntry = FileASTUnitMap.find(FileName);
374  if (ASTCacheEntry == FileASTUnitMap.end()) {
375 
376  // Do not load if the limit is reached.
377  if (!LoadGuard) {
378  ++NumASTLoadThresholdReached;
379  return llvm::make_error<IndexError>(
381  }
382 
383  // Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
384  std::unique_ptr<ASTUnit> LoadedUnit = FileAccessor(FileName);
385 
386  // Need the raw pointer and the unique_ptr as well.
387  ASTUnit *Unit = LoadedUnit.get();
388 
389  // Update the cache.
390  FileASTUnitMap[FileName] = std::move(LoadedUnit);
391 
392  LoadGuard.indicateLoadSuccess();
393 
394  if (DisplayCTUProgress)
395  llvm::errs() << "CTU loaded AST file: " << FileName << "\n";
396 
397  return Unit;
398 
399  } else {
400  // Found in the cache.
401  return ASTCacheEntry->second.get();
402  }
403 }
404 
406 CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
407  StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName,
408  bool DisplayCTUProgress) {
409  // Try the cache first.
410  auto ASTCacheEntry = NameASTUnitMap.find(FunctionName);
411  if (ASTCacheEntry == NameASTUnitMap.end()) {
412  // Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
413 
414  // Ensure that the Index is loaded, as we need to search in it.
415  if (llvm::Error IndexLoadError =
416  ensureCTUIndexLoaded(CrossTUDir, IndexName))
417  return std::move(IndexLoadError);
418 
419  // Check if there is and entry in the index for the function.
420  if (!NameFileMap.count(FunctionName)) {
421  ++NumNotInOtherTU;
422  return llvm::make_error<IndexError>(index_error_code::missing_definition);
423  }
424 
425  // Search in the index for the filename where the definition of FuncitonName
426  // resides.
427  if (llvm::Expected<ASTUnit *> FoundForFile =
428  getASTUnitForFile(NameFileMap[FunctionName], DisplayCTUProgress)) {
429 
430  // Update the cache.
431  NameASTUnitMap[FunctionName] = *FoundForFile;
432  return *FoundForFile;
433 
434  } else {
435  return FoundForFile.takeError();
436  }
437  } else {
438  // Found in the cache.
439  return ASTCacheEntry->second;
440  }
441 }
442 
444 CrossTranslationUnitContext::ASTUnitStorage::getFileForFunction(
445  StringRef FunctionName, StringRef CrossTUDir, StringRef IndexName) {
446  if (llvm::Error IndexLoadError = ensureCTUIndexLoaded(CrossTUDir, IndexName))
447  return std::move(IndexLoadError);
448  return NameFileMap[FunctionName];
449 }
450 
451 llvm::Error CrossTranslationUnitContext::ASTUnitStorage::ensureCTUIndexLoaded(
452  StringRef CrossTUDir, StringRef IndexName) {
453  // Dont initialize if the map is filled.
454  if (!NameFileMap.empty())
455  return llvm::Error::success();
456 
457  // Get the absolute path to the index file.
458  SmallString<256> IndexFile = CrossTUDir;
459  if (llvm::sys::path::is_absolute(IndexName))
460  IndexFile = IndexName;
461  else
462  llvm::sys::path::append(IndexFile, IndexName);
463 
464  if (auto IndexMapping = parseCrossTUIndex(IndexFile, CrossTUDir)) {
465  // Initialize member map.
466  NameFileMap = *IndexMapping;
467  return llvm::Error::success();
468  } else {
469  // Error while parsing CrossTU index file.
470  return IndexMapping.takeError();
471  };
472 }
473 
475  StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
476  bool DisplayCTUProgress) {
477  // FIXME: The current implementation only supports loading decls with
478  // a lookup name from a single translation unit. If multiple
479  // translation units contains decls with the same lookup name an
480  // error will be returned.
481 
482  // Try to get the value from the heavily cached storage.
483  llvm::Expected<ASTUnit *> Unit = ASTStorage.getASTUnitForFunction(
484  LookupName, CrossTUDir, IndexName, DisplayCTUProgress);
485 
486  if (!Unit)
487  return Unit.takeError();
488 
489  // Check whether the backing pointer of the Expected is a nullptr.
490  if (!*Unit)
491  return llvm::make_error<IndexError>(
493 
494  return Unit;
495 }
496 
497 template <typename T>
499 CrossTranslationUnitContext::importDefinitionImpl(const T *D, ASTUnit *Unit) {
500  assert(hasBodyOrInit(D) && "Decls to be imported should have body or init.");
501 
502  assert(&D->getASTContext() == &Unit->getASTContext() &&
503  "ASTContext of Decl and the unit should match.");
504  ASTImporter &Importer = getOrCreateASTImporter(Unit);
505 
506  auto ToDeclOrError = Importer.Import(D);
507  if (!ToDeclOrError) {
508  handleAllErrors(ToDeclOrError.takeError(),
509  [&](const ImportError &IE) {
510  switch (IE.Error) {
512  ++NumNameConflicts;
513  break;
515  ++NumUnsupportedNodeFound;
516  break;
518  llvm_unreachable("Unknown import error happened.");
519  break;
520  }
521  });
522  return llvm::make_error<IndexError>(index_error_code::failed_import);
523  }
524  auto *ToDecl = cast<T>(*ToDeclOrError);
525  assert(hasBodyOrInit(ToDecl) && "Imported Decl should have body or init.");
526  ++NumGetCTUSuccess;
527 
528  return ToDecl;
529 }
530 
533  ASTUnit *Unit) {
534  return importDefinitionImpl(FD, Unit);
535 }
536 
539  ASTUnit *Unit) {
540  return importDefinitionImpl(VD, Unit);
541 }
542 
543 void CrossTranslationUnitContext::lazyInitImporterSharedSt(
544  TranslationUnitDecl *ToTU) {
545  if (!ImporterSharedSt)
546  ImporterSharedSt = std::make_shared<ASTImporterSharedState>(*ToTU);
547 }
548 
549 ASTImporter &
550 CrossTranslationUnitContext::getOrCreateASTImporter(ASTUnit *Unit) {
551  ASTContext &From = Unit->getASTContext();
552 
553  auto I = ASTUnitImporterMap.find(From.getTranslationUnitDecl());
554  if (I != ASTUnitImporterMap.end())
555  return *I->second;
556  lazyInitImporterSharedSt(Context.getTranslationUnitDecl());
557  ASTImporter *NewImporter = new ASTImporter(
558  Context, Context.getSourceManager().getFileManager(), From,
559  From.getSourceManager().getFileManager(), false, ImporterSharedSt);
560  NewImporter->setFileIDImportHandler([this, Unit](FileID ToID, FileID FromID) {
561  assert(ImportedFileIDs.find(ToID) == ImportedFileIDs.end() &&
562  "FileID already imported, should not happen.");
563  ImportedFileIDs[ToID] = std::make_pair(FromID, Unit);
564  });
565  ASTUnitImporterMap[From.getTranslationUnitDecl()].reset(NewImporter);
566  return *NewImporter;
567 }
568 
571  const clang::SourceLocation &ToLoc) const {
572  const SourceManager &SM = Context.getSourceManager();
573  auto DecToLoc = SM.getDecomposedLoc(ToLoc);
574 
575  auto I = ImportedFileIDs.find(DecToLoc.first);
576  if (I == ImportedFileIDs.end())
577  return {};
578 
579  FileID FromID = I->second.first;
580  clang::ASTUnit *Unit = I->second.second;
581  SourceLocation FromLoc =
582  Unit->getSourceManager().getComposedLoc(FromID, DecToLoc.second);
583 
584  return std::make_pair(FromLoc, Unit);
585 }
586 
587 } // namespace cross_tu
588 } // namespace clang
Represents a function declaration or definition.
Definition: Decl.h:1784
bool isConstQualified() const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:991
Load everything, including Sema.
Definition: ASTUnit.h:678
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
const FileManager & getFileManager() const
Definition: ASTUnit.h:476
llvm::Expected< ASTUnit * > loadExternalAST(StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false)
This function loads a definition from an external AST file.
void log(raw_ostream &OS) const override
DiagnosticsEngine & getDiagnostics() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1290
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:706
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to...
Definition: Decl.h:1224
Not supported node or case.
Definition: ASTImporter.h:56
Represents a variable declaration or definition.
Definition: Decl.h:827
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2028
FileManager & getFileManager() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
Utility class for loading a ASTContext from an AST file.
Definition: ASTUnit.h:89
int Category
Definition: Format.cpp:1810
StringRef getMainFileName() const
Definition: ASTUnit.cpp:1464
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, ArrayRef< RemappedFile > RemappedFiles=None, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowPCHWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
Definition: ASTUnit.cpp:756
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
static llvm::Optional< std::string > getLookupName(const NamedDecl *ND)
Get a name to identify a named decl.
llvm::Expected< const FunctionDecl * > importDefinition(const FunctionDecl *FD, ASTUnit *Unit)
This function merges a definition from a separate AST Unit into the current one which was created by ...
bool containsConst(const VarDecl *VD, const ASTContext &ACtx)
STATISTIC(NumObjCCallEdges, "Number of Objective-C method call edges")
const AnnotatedLine * Line
std::string createCrossTUIndexString(const llvm::StringMap< std::string > &Index)
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:2811
llvm::Expected< llvm::StringMap< std::string > > parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir)
This function parses an index file that determines which translation unit contains which definition...
const SourceManager & SM
Definition: Format.cpp:1667
FileSystemOptions & getFileSystemOpts()
void setFileIDImportHandler(FileIDImportHandlerType H)
Set a callback function for FileID import handling.
Definition: ASTImporter.h:325
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
Options for controlling the compiler diagnostics engine.
static bool hasBodyOrInit(const FunctionDecl *D, const FunctionDecl *&DefD)
Naming ambiguity (likely ODR violation).
Definition: ASTImporter.h:55
bool hasConstFields() const
Recursively check all fields in the record for const-ness.
Definition: Type.cpp:3301
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
Used for handling and querying diagnostic IDs.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4444
index_error_code getCode() const
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:84
const ASTContext & getASTContext() const
Definition: ASTUnit.h:439
SourceManager & getSourceManager()
Definition: ASTContext.h:678
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2289
llvm::Expected< const FunctionDecl * > getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress=false)
This function loads a function or variable definition from an external AST file and merges it into th...
std::error_code convertToErrorCode() const override
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1008
const SourceManager & getSourceManager() const
Definition: ASTUnit.h:432
Defines the clang::TargetInfo interface.
void emitCrossTUDiagnostics(const IndexError &IE)
Emit diagnostics for the user for potential configuration errors.
llvm::Optional< std::pair< SourceLocation, ASTUnit * > > getImportedFromSourceLocation(const clang::SourceLocation &ToLoc) const
Determine the original source location in the original TU for an imported source location.
The top declaration context.
Definition: Decl.h:107
QualType getType() const
Definition: Decl.h:655
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
This represents a decl that may have a name.
Definition: Decl.h:248
std::string getTripleToName() const
const LangOptions & getLangOpts() const
Definition: ASTContext.h:723
This class handles loading and caching of source files into memory.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
std::string getTripleFromName() const