Skip to content

Commit 6abfabf

Browse files
committed
Modifications to type handling logic. We no longer
perform recursive type lookups, because these are not required for full type fidelity. We also make the SelectorTable last for the full lifetime of the Clang compiler; this was the source of many bugs. llvm-svn: 119835
1 parent 003c6e7 commit 6abfabf

File tree

4 files changed

+66
-43
lines changed

4 files changed

+66
-43
lines changed

lldb/include/lldb/Expression/ClangExpressionDeclMap.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,7 @@ class ClangExpressionDeclMap
385385
ConstString m_result_name; ///< The name of the result variable ($1, for example)
386386
TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if one exists.
387387

388-
llvm::DenseMap <const char*, bool> m_lookedup_types; ///< Contains each type that has been looked up in the current type lookup stack.
389-
///< m_lookedup_types is used to gate the type search in GetDecls(). If a name is
390-
///< not in it, the following procedure occurs:
391-
///< 1 The name is added to m_lookedup_types.
392-
///< 2 The type is looked up and added, potentially causing more type loookups.
393-
///< 3 The name is removed from m_lookedup_types.
394-
///< There must be no non-fatal error path that permits the type search to complete
395-
///< without removing the name from m_lookedup_types at the end.
396-
///< m_lookedup_type assumes single threadedness.
388+
bool m_ignore_lookups; ///< True during an import when we should be ignoring type lookups.
397389

398390
//------------------------------------------------------------------
399391
/// Given a stack frame, find a variable that matches the given name and
@@ -611,6 +603,27 @@ class ClangExpressionDeclMap
611603
TypeFromUser type,
612604
lldb::addr_t addr,
613605
Error &err);
606+
607+
//------------------------------------------------------------------
608+
/// A wrapper for ClangASTContext::CopyType that sets a flag that
609+
/// indicates that we should not respond to queries during import.
610+
///
611+
/// @param[in] dest_context
612+
/// The target AST context, typically the parser's AST context.
613+
///
614+
/// @param[in] source_context
615+
/// The source AST context, typically the AST context of whatever
616+
/// symbol file the type was found in.
617+
///
618+
/// @param[in] clang_type
619+
/// The source type.
620+
///
621+
/// @return
622+
/// The imported type.
623+
//------------------------------------------------------------------
624+
void *GuardedCopyType (clang::ASTContext *dest_context,
625+
clang::ASTContext *source_context,
626+
void *clang_type);
614627
};
615628

616629
} // namespace lldb_private

lldb/include/lldb/Expression/ClangExpressionParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class ClangExpressionParser
177177
std::auto_ptr<clang::FileSystemOptions> m_file_system_options; ///< The Clang file system options object used by the compiler
178178
std::auto_ptr<clang::CompilerInstance> m_compiler; ///< The Clang compiler used to parse expressions into IR
179179
std::auto_ptr<clang::Builtin::Context> m_builtin_context; ///< Context for Clang built-ins
180+
std::auto_ptr<clang::SelectorTable> m_selector_table; ///< Selector table for Objective-C methods
180181
std::auto_ptr<clang::ASTContext> m_ast_context; ///< The AST context used to hold types and names for the parser
181182
std::auto_ptr<clang::CodeGenerator> m_code_generator; ///< [owned by the Execution Engine] The Clang object that generates IR
182183
RecordingMemoryManager *m_jit_mm; ///< The memory manager for the LLVM JIT

lldb/source/Expression/ClangExpressionDeclMap.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ClangExpressionDeclMap::ClangExpressionDeclMap (ExecutionContext *exe_ctx) :
5757
m_materialized_location (0),
5858
m_result_name (),
5959
m_object_pointer_type (),
60-
m_lookedup_types ()
60+
m_ignore_lookups (false)
6161
{
6262
if (exe_ctx)
6363
{
@@ -990,6 +990,13 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
990990
// Back out in all cases where we're not fully initialized
991991
if (m_exe_ctx.frame == NULL)
992992
return;
993+
994+
if (m_ignore_lookups)
995+
{
996+
if (log)
997+
log->Printf("Ignoring a query during an import");
998+
return;
999+
}
9931000

9941001
SymbolContextList sc_list;
9951002

@@ -1117,36 +1124,22 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
11171124
AddOneVariable(context, pvar);
11181125
}
11191126

1120-
1121-
// See information on gating of this operation next to the definition for
1122-
// m_lookedup_types.
1123-
1124-
if (m_lookedup_types.find(name_unique_cstr) == m_lookedup_types.end())
1125-
{
1126-
// 1 The name is added to m_lookedup_types.
1127-
m_lookedup_types.insert(std::pair<const char*, bool>(name_unique_cstr, true));
1128-
1129-
// 2 The type is looked up and added, potentially causing more type loookups.
1130-
lldb::TypeSP type_sp (m_sym_ctx.FindTypeByName (name));
1127+
lldb::TypeSP type_sp (m_sym_ctx.FindTypeByName (name));
11311128

1132-
if (type_sp)
1129+
if (type_sp)
1130+
{
1131+
if (log)
11331132
{
1134-
if (log)
1135-
{
1136-
log->Printf ("Matching type found for \"%s\": ", name.GetCString());
1137-
StreamString strm;
1138-
type_sp->Dump(&strm, true);
1139-
log->PutCString (strm.GetData());
1140-
}
1133+
log->Printf ("Matching type found for \"%s\": ", name.GetCString());
1134+
StreamString strm;
1135+
type_sp->Dump(&strm, true);
1136+
log->PutCString (strm.GetData());
1137+
}
11411138

1142-
TypeFromUser user_type(type_sp->GetClangType(),
1139+
TypeFromUser user_type(type_sp->GetClangType(),
11431140
type_sp->GetClangAST());
11441141

1145-
AddOneType(context, user_type, false);
1146-
}
1147-
1148-
// 3 The name is removed from m_lookedup_types.
1149-
m_lookedup_types.erase(name_unique_cstr);
1142+
AddOneType(context, user_type, false);
11501143
}
11511144
}
11521145

@@ -1225,7 +1218,7 @@ ClangExpressionDeclMap::GetVariableValue
12251218

12261219
if (parser_ast_context)
12271220
{
1228-
type_to_use = ClangASTContext::CopyType(parser_ast_context, var_ast_context, var_opaque_type);
1221+
type_to_use = GuardedCopyType(parser_ast_context, var_ast_context, var_opaque_type);
12291222

12301223
if (parser_type)
12311224
*parser_type = TypeFromParser(type_to_use, parser_ast_context);
@@ -1310,9 +1303,9 @@ ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
13101303

13111304
TypeFromUser user_type = pvar->m_user_type;
13121305

1313-
TypeFromParser parser_type(ClangASTContext::CopyType(context.GetASTContext(),
1314-
user_type.GetASTContext(),
1315-
user_type.GetOpaqueQualType()),
1306+
TypeFromParser parser_type(GuardedCopyType(context.GetASTContext(),
1307+
user_type.GetASTContext(),
1308+
user_type.GetOpaqueQualType()),
13161309
context.GetASTContext());
13171310

13181311
NamedDecl *var_decl = context.AddVarDecl(parser_type.GetOpaqueQualType());
@@ -1386,7 +1379,7 @@ ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
13861379

13871380
TypeList *type_list = fun_type->GetTypeList();
13881381
fun_ast_context = type_list->GetClangASTContext().getASTContext();
1389-
void *copied_type = ClangASTContext::CopyType(context.GetASTContext(), fun_ast_context, fun_opaque_type);
1382+
void *copied_type = GuardedCopyType(context.GetASTContext(), fun_ast_context, fun_opaque_type);
13901383

13911384
fun_decl = context.AddFunDecl(copied_type);
13921385
}
@@ -1436,7 +1429,7 @@ ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
14361429
clang::ASTContext *parser_ast_context = context.GetASTContext();
14371430
clang::ASTContext *user_ast_context = ut.GetASTContext();
14381431

1439-
void *copied_type = ClangASTContext::CopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType());
1432+
void *copied_type = GuardedCopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType());
14401433

14411434
TypeFromParser parser_type(copied_type, parser_ast_context);
14421435

@@ -1471,3 +1464,19 @@ ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
14711464

14721465
context.AddTypeDecl(copied_type);
14731466
}
1467+
1468+
void *
1469+
ClangExpressionDeclMap::GuardedCopyType (ASTContext *dest_context,
1470+
ASTContext *source_context,
1471+
void *clang_type)
1472+
{
1473+
m_ignore_lookups = true;
1474+
1475+
void *ret = ClangASTContext::CopyType (dest_context,
1476+
source_context,
1477+
clang_type);
1478+
1479+
m_ignore_lookups = false;
1480+
1481+
return ret;
1482+
}

lldb/source/Expression/ClangExpressionParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ ClangExpressionParser::ClangExpressionParser(const char *target_triple,
254254

255255
// 6. Most of this we get from the CompilerInstance, but we
256256
// also want to give the context an ExternalASTSource.
257-
SelectorTable selector_table;
257+
m_selector_table.reset(new SelectorTable());
258258
m_builtin_context.reset(new Builtin::Context(m_compiler->getTarget()));
259259

260260
std::auto_ptr<clang::ASTContext> ast_context(new ASTContext(m_compiler->getLangOpts(),
261261
m_compiler->getSourceManager(),
262262
m_compiler->getTarget(),
263263
m_compiler->getPreprocessor().getIdentifierTable(),
264-
selector_table,
264+
*m_selector_table.get(),
265265
*m_builtin_context.get(),
266266
0));
267267

0 commit comments

Comments
 (0)