Skip to content
Snippets Groups Projects
Commit e7714fe7 authored by Raphael Isemann's avatar Raphael Isemann
Browse files

[lldb][clang][modern-type-lookup] Use ASTImporterSharedState in ExternalASTMerger

Summary:
The ExternalASTMerger should use the ASTImporterSharedState. This allows it to
handle std::pair in LLDB (but the rest of libc++ is still work in progress).

Reviewers: martong, shafik, a.sidorin

Subscribers: rnkovacs, christof, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D68140

llvm-svn: 373193
parent e3b4f0ec
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#define LLVM_CLANG_AST_EXTERNALASTMERGER_H #define LLVM_CLANG_AST_EXTERNALASTMERGER_H
#include "clang/AST/ASTImporter.h" #include "clang/AST/ASTImporter.h"
#include "clang/AST/ASTImporterSharedState.h"
#include "clang/AST/ExternalASTSource.h" #include "clang/AST/ExternalASTSource.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
...@@ -88,6 +89,11 @@ public: ...@@ -88,6 +89,11 @@ public:
private: private:
/// The target for this ExtenralASTMerger. /// The target for this ExtenralASTMerger.
ImporterTarget Target; ImporterTarget Target;
/// ExternalASTMerger has multiple ASTImporters that import into the same
/// TU. This is the shared state for all ASTImporters of this
/// ExternalASTMerger.
/// See also the CrossTranslationUnitContext that has a similar setup.
std::shared_ptr<ASTImporterSharedState> SharedState;
public: public:
ExternalASTMerger(const ImporterTarget &Target, ExternalASTMerger(const ImporterTarget &Target,
......
...@@ -107,11 +107,13 @@ public: ...@@ -107,11 +107,13 @@ public:
LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext, LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext,
FileManager &ToFileManager, ASTContext &FromContext, FileManager &ToFileManager, ASTContext &FromContext,
FileManager &FromFileManager, FileManager &FromFileManager,
const ExternalASTMerger::OriginMap &_FromOrigins) const ExternalASTMerger::OriginMap &_FromOrigins,
std::shared_ptr<ASTImporterSharedState> SharedState)
: ASTImporter(ToContext, ToFileManager, FromContext, FromFileManager, : ASTImporter(ToContext, ToFileManager, FromContext, FromFileManager,
/*MinimalImport=*/true), /*MinimalImport=*/true, SharedState),
Parent(_Parent), Reverse(FromContext, FromFileManager, ToContext, Parent(_Parent), Reverse(FromContext, FromFileManager, ToContext,
ToFileManager, /*MinimalImport=*/true), FromOrigins(_FromOrigins) {} ToFileManager, /*MinimalImport=*/true),
FromOrigins(_FromOrigins) {}
/// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin
/// map is kept up to date. Also set the appropriate flags. /// map is kept up to date. Also set the appropriate flags.
...@@ -314,6 +316,8 @@ void ExternalASTMerger::RecordOriginImpl(const DeclContext *ToDC, DCOrigin Origi ...@@ -314,6 +316,8 @@ void ExternalASTMerger::RecordOriginImpl(const DeclContext *ToDC, DCOrigin Origi
ExternalASTMerger::ExternalASTMerger(const ImporterTarget &Target, ExternalASTMerger::ExternalASTMerger(const ImporterTarget &Target,
llvm::ArrayRef<ImporterSource> Sources) : LogStream(&llvm::nulls()), Target(Target) { llvm::ArrayRef<ImporterSource> Sources) : LogStream(&llvm::nulls()), Target(Target) {
SharedState = std::make_shared<ASTImporterSharedState>(
*Target.AST.getTranslationUnitDecl());
AddSources(Sources); AddSources(Sources);
} }
...@@ -321,7 +325,7 @@ void ExternalASTMerger::AddSources(llvm::ArrayRef<ImporterSource> Sources) { ...@@ -321,7 +325,7 @@ void ExternalASTMerger::AddSources(llvm::ArrayRef<ImporterSource> Sources) {
for (const ImporterSource &S : Sources) { for (const ImporterSource &S : Sources) {
assert(&S.AST != &Target.AST); assert(&S.AST != &Target.AST);
Importers.push_back(std::make_unique<LazyASTImporter>( Importers.push_back(std::make_unique<LazyASTImporter>(
*this, Target.AST, Target.FM, S.AST, S.FM, S.OM)); *this, Target.AST, Target.FM, S.AST, S.FM, S.OM, SharedState));
} }
} }
......
CXX_SOURCES := main.cpp
USE_LIBCPP := 1
include Makefile.rules
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class LibcxxModernTypeLookup(TestBase):
mydir = TestBase.compute_mydir(__file__)
@add_test_categories(["libc++"])
def test(self):
self.build()
# Activate modern-type-lookup.
self.runCmd("settings set target.experimental.use-modern-type-lookup true")
lldbutil.run_to_source_breakpoint(self,
"// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
# Test a few simple expressions that should still work with modern-type-lookup.
self.expect("expr pair", substrs=["(std::", "pair<int, long", "= (first = 1, second = 2)"])
#include <utility>
int main(int argc, char **argv) {
std::pair<int, long> pair = std::make_pair<int, float>(1, 2L);
return pair.first; // Set break point at this line.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment