diff options
author | Rafael Stahl <r.stahl@tum.de> | 2019-04-23 11:04:41 +0000 |
---|---|---|
committer | Rafael Stahl <r.stahl@tum.de> | 2019-04-23 11:04:41 +0000 |
commit | 55bbda44b412f57f2bfa3f69c6ccaecc1acf3244 (patch) | |
tree | 48883aeb88c80642bf236b5520f986f472ca4d33 /include | |
parent | eb72871e0572587b9ab80c8abbb2845888f6b651 (diff) |
[analyzer][CrossTU] Extend CTU to VarDecls with initializer
Summary:
The existing CTU mechanism imports `FunctionDecl`s where the definition is available in another TU. This patch extends that to VarDecls, to bind more constants.
- Add VarDecl importing functionality to CrossTranslationUnitContext
- Import Decls while traversing them in AnalysisConsumer
- Add VarDecls to CTU external mappings generator
- Name changes from "external function map" to "external definition map"
Reviewers: NoQ, dcoughlin, xazax.hun, george.karpenkov, martong
Reviewed By: xazax.hun
Subscribers: Charusso, baloghadamsoftware, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, george.karpenkov, mgorny, whisperity, szepet, rnkovacs, a.sidorin, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D46421
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358968 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/CrossTU/CrossTranslationUnit.h | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/include/clang/CrossTU/CrossTranslationUnit.h b/include/clang/CrossTU/CrossTranslationUnit.h index bbbba7ad7b..9270f7fa7a 100644 --- a/include/clang/CrossTU/CrossTranslationUnit.h +++ b/include/clang/CrossTU/CrossTranslationUnit.h @@ -28,6 +28,7 @@ class ASTImporter; class ASTUnit; class DeclContext; class FunctionDecl; +class VarDecl; class NamedDecl; class TranslationUnitDecl; @@ -87,6 +88,9 @@ parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir); std::string createCrossTUIndexString(const llvm::StringMap<std::string> &Index); +// Returns true if the variable or any field of a record variable is const. +bool containsConst(const VarDecl *VD, const ASTContext &ACtx); + /// This class is used for tools that requires cross translation /// unit capability. /// @@ -102,16 +106,16 @@ public: CrossTranslationUnitContext(CompilerInstance &CI); ~CrossTranslationUnitContext(); - /// This function loads a function definition from an external AST - /// file and merge it into the original AST. + /// This function loads a function or variable definition from an + /// external AST file and merges it into the original AST. /// - /// This method should only be used on functions that have no definitions in + /// This method should only be used on functions that have no definitions or + /// variables that have no initializer in /// the current translation unit. A function definition with the same /// declaration will be looked up in the index file which should be in the /// \p CrossTUDir directory, called \p IndexName. In case the declaration is /// found in the index the corresponding AST file will be loaded and the - /// definition of the function will be merged into the original AST using - /// the AST Importer. + /// definition will be merged into the original AST using the AST Importer. /// /// \return The declaration with the definition will be returned. /// If no suitable definition is found in the index file or multiple @@ -121,17 +125,19 @@ public: llvm::Expected<const FunctionDecl *> getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress = false); + llvm::Expected<const VarDecl *> + getCrossTUDefinition(const VarDecl *VD, StringRef CrossTUDir, + StringRef IndexName, bool DisplayCTUProgress = false); - /// This function loads a function definition from an external AST - /// file. + /// This function loads a definition from an external AST file. /// - /// A function definition with the same declaration will be looked up in the + /// A definition with the same declaration will be looked up in the /// index file which should be in the \p CrossTUDir directory, called /// \p IndexName. In case the declaration is found in the index the /// corresponding AST file will be loaded. /// /// \return Returns a pointer to the ASTUnit that contains the definition of - /// the looked up function or an Error. + /// the looked up name or an Error. /// The returned pointer is never a nullptr. /// /// Note that the AST files should also be in the \p CrossTUDir. @@ -146,8 +152,9 @@ public: /// /// \return Returns the resulting definition or an error. llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD); + llvm::Expected<const VarDecl *> importDefinition(const VarDecl *VD); - /// Get a name to identify a function. + /// Get a name to identify a named decl. static std::string getLookupName(const NamedDecl *ND); /// Emit diagnostics for the user for potential configuration errors. @@ -156,12 +163,20 @@ public: private: void lazyInitLookupTable(TranslationUnitDecl *ToTU); ASTImporter &getOrCreateASTImporter(ASTContext &From); - const FunctionDecl *findFunctionInDeclContext(const DeclContext *DC, - StringRef LookupFnName); + template <typename T> + llvm::Expected<const T *> getCrossTUDefinitionImpl(const T *D, + StringRef CrossTUDir, + StringRef IndexName, + bool DisplayCTUProgress); + template <typename T> + const T *findDefInDeclContext(const DeclContext *DC, + StringRef LookupName); + template <typename T> + llvm::Expected<const T *> importDefinitionImpl(const T *D); llvm::StringMap<std::unique_ptr<clang::ASTUnit>> FileASTUnitMap; - llvm::StringMap<clang::ASTUnit *> FunctionASTUnitMap; - llvm::StringMap<std::string> FunctionFileMap; + llvm::StringMap<clang::ASTUnit *> NameASTUnitMap; + llvm::StringMap<std::string> NameFileMap; llvm::DenseMap<TranslationUnitDecl *, std::unique_ptr<ASTImporter>> ASTUnitImporterMap; CompilerInstance &CI; |