rdar://problem/10501020

ClangASTSource::~ClangASTSource() was calling

    ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext();

which had the side effect of deleting this very ClangASTSource instance.  Not good.
Change it to

    // We are in the process of destruction, don't create clang ast context on demand
    // by passing false to Target::GetScratchClangASTContext(create_on_demand).
    ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false);

The Target::GetScratchClangASTContext(bool create_on_demand=true) has a new signature.

llvm-svn: 145537
This commit is contained in:
Johnny Chen 2011-11-30 23:18:53 +00:00
parent b9e53ed4e2
commit 60e2c6aa43
4 changed files with 7 additions and 5 deletions

View File

@ -799,7 +799,7 @@ public:
GetImageSearchPathList ();
ClangASTContext *
GetScratchClangASTContext();
GetScratchClangASTContext(bool create_on_demand=true);
ClangASTImporter *
GetClangASTImporter();

View File

@ -27,7 +27,9 @@ ClangASTSource::~ClangASTSource()
{
m_ast_importer->ForgetDestination(m_ast_context);
ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext();
// We are in the process of destruction, don't create clang ast context on demand
// by passing false to Target::GetScratchClangASTContext(create_on_demand).
ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false);
if (!scratch_clang_ast_context)
return;

View File

@ -1335,10 +1335,10 @@ Target::ImageSearchPathsChanged
}
ClangASTContext *
Target::GetScratchClangASTContext()
Target::GetScratchClangASTContext(bool create_on_demand)
{
// Now see if we know the target triple, and if so, create our scratch AST context:
if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
{
m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
m_scratch_ast_source_ap.reset (new ClangASTSource(GetSP()));

View File

@ -49,7 +49,7 @@ class LoadUnloadTestCase(TestBase):
# Add teardown hook to clear image-search-paths after the test.
# rdar://problem/10501020
# Uncomment the following to reproduce 10501020.
#self.addTearDownHook(lambda: self.runCmd("target modules search-paths clear"))
self.addTearDownHook(lambda: self.runCmd("target modules search-paths clear"))
self.expect("target modules search-paths list",
substrs = [os.getcwd(), new_dir])