This change brings in the latest LLVM/Clang, and
completes the support in the LLDB expression parser
for incomplete types. Clang now imports types
lazily, and we complete those types as necessary.
Changes include:
- ClangASTSource now supports three APIs which it
passes to ClangExpressionDeclMap. CompleteType
completes a TagDecl or an ObjCInterfaceDecl when
needed; FindExternalVisibleDecls finds named
entities that are visible in the expression's
scope; and FindExternalLexicalDecls performs a
(potentially restricted) search for entities
inside a lexical scope like a namespace. These
changes mean that entities in namespaces should
work normally.
- The SymbolFileDWARF code for searching a context
for a specific name is now more general, and can
search arbitrary contexts.
- We are continuing to adapt our calls into LLVM
from interfaces that take start and end iterators
when accepting multiple items to interfaces that
use ArrayRef.
- I have cleaned up some code, especially our use
of namespaces.
This change is neutral for our testsuite and greatly
improves correctness for large programs (like Clang)
with complicated type systems. It should also lay
the groundwork for improving the expression parser's
performance as we are lazier and lazier about
providing type information.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@136555 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ASTDumper.cpp b/source/Expression/ASTDumper.cpp
index 76be440..8194233 100644
--- a/source/Expression/ASTDumper.cpp
+++ b/source/Expression/ASTDumper.cpp
@@ -406,7 +406,6 @@
m_stream.Indent(); m_stream.Printf("isCanonicalUnqualified() : %s\n", SfB(type->isCanonicalUnqualified()));
m_stream.Indent(); m_stream.Printf("isIncompleteType() : %s\n", SfB(type->isIncompleteType()));
m_stream.Indent(); m_stream.Printf("isObjectType() : %s\n", SfB(type->isObjectType()));
- m_stream.Indent(); m_stream.Printf("isPODType() : %s\n", SfB(type->isPODType()));
m_stream.Indent(); m_stream.Printf("isLiteralType() : %s\n", SfB(type->isLiteralType()));
m_stream.Indent(); m_stream.Printf("isBuiltinType() : %s\n", SfB(type->isBuiltinType()));
m_stream.Indent(); m_stream.Printf("isPlaceholderType() : %s\n", SfB(type->isPlaceholderType()));
diff --git a/source/Expression/ClangASTSource.cpp b/source/Expression/ClangASTSource.cpp
index a229a4a..a5ac2c3 100644
--- a/source/Expression/ClangASTSource.cpp
+++ b/source/Expression/ClangASTSource.cpp
@@ -114,13 +114,13 @@
void
ClangASTSource::CompleteType (TagDecl *tag_decl)
{
- puts(__PRETTY_FUNCTION__);
+ m_decl_map.CompleteTagDecl (tag_decl);
}
void
ClangASTSource::CompleteType (ObjCInterfaceDecl *objc_decl)
{
- puts(__PRETTY_FUNCTION__);
+ m_decl_map.CompleteObjCInterfaceDecl (objc_decl);
}
void
@@ -131,7 +131,7 @@
// This is used to support iterating through an entire lexical context,
// which isn't something the debugger should ever need to do.
-bool
+clang::ExternalLoadResult
ClangASTSource::FindExternalLexicalDecls
(
const DeclContext *DC,
@@ -139,8 +139,7 @@
llvm::SmallVectorImpl<Decl*> &Decls
)
{
- // true is for error, that's good enough for me
- return true;
+ return m_decl_map.FindExternalLexicalDecls (DC, isKindWeWant, Decls);
}
clang::ASTContext *
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index 97e73bd..4f21fc0 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -134,7 +134,7 @@
{
assert (m_parser_vars.get());
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
- clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
type.GetASTContext(),
@@ -203,7 +203,7 @@
lldb::ClangExpressionVariableSP
ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
- clang::VarDecl *decl,
+ VarDecl *decl,
lldb_private::TypeFromParser type)
{
assert (m_parser_vars.get());
@@ -211,7 +211,7 @@
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
- clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
ClangExpressionVariableSP var_sp (m_found_entities.GetVariable(decl));
@@ -273,7 +273,7 @@
bool
ClangExpressionDeclMap::AddPersistentVariable
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
const ConstString &name,
TypeFromParser parser_type,
bool is_result,
@@ -285,7 +285,7 @@
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
- clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
parser_type.GetASTContext(),
@@ -333,7 +333,7 @@
bool
ClangExpressionDeclMap::AddValueToStruct
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
const ConstString &name,
llvm::Value *value,
size_t size,
@@ -439,7 +439,7 @@
bool
ClangExpressionDeclMap::GetStructElement
(
- const clang::NamedDecl *&decl,
+ const NamedDecl *&decl,
llvm::Value *&value,
off_t &offset,
ConstString &name,
@@ -472,7 +472,7 @@
bool
ClangExpressionDeclMap::GetFunctionInfo
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
llvm::Value**& value,
uint64_t &ptr
)
@@ -915,7 +915,7 @@
if (log)
log->PutCString("Not bothering to allocate a struct because no arguments are needed");
- m_material_vars->m_allocated_area = 0;
+ m_material_vars->m_allocated_area = NULL;
return true;
}
@@ -1674,61 +1674,57 @@
if (isa<TranslationUnitDecl>(context.m_decl_context))
break;
- if (log)
- log->Printf("'%s' is in something other than a translation unit", name.GetCString());
-
- const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
-
- if (!context_decl)
+ if (!isa<NamespaceDecl>(context.m_decl_context))
return;
- if (const NamespaceDecl *namespace_decl = dyn_cast<NamespaceDecl>(context_decl))
+ const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
+
+ if (log)
+ log->Printf("Searching for '%s' in a '%s'", name.GetCString(), context_decl->getDeclKindName());
+
+ Decl *original_decl = NULL;
+ ASTContext *original_ctx = NULL;
+
+ if (!m_parser_vars->GetASTImporter(context.GetASTContext())->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
+ break;
+
+ if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
{
- Decl *original_decl = NULL;
- ASTContext *original_ctx = NULL;
+ ExternalASTSource *external_source = original_ctx->getExternalSource();
- if (log)
- log->Printf("Resolving the containing context's origin...");
-
- if (!m_parser_vars->GetASTImporter(context.GetASTContext())->ResolveDeclOrigin(namespace_decl, &original_decl, &original_ctx))
+ if (!external_source)
break;
-
- if (log)
- log->Printf("Casting it to a DeclContext...");
-
- DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
-
- if (!original_decl_context)
- break;
-
- if (log)
- {
- std::string s;
- llvm::raw_string_ostream os(s);
- original_decl->print(os);
- os.flush();
-
- log->Printf("Containing context:");
- log->Printf("%s", s.c_str());
- }
-
- if (!original_ctx->getExternalSource())
- break;
-
- DeclContextLookupConstResult original_lookup_result = original_ctx->getExternalSource()->FindExternalVisibleDeclsByName(original_decl_context, context.m_decl_name);
- NamedDecl *const *iter = NULL;
+ if (!original_tag_decl)
+ break;
- for (iter = original_lookup_result.first;
- iter != original_lookup_result.second;
- ++iter)
- {
- clang::NamedDecl *copied_result = dyn_cast<NamedDecl>(m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, *iter));
+ external_source->CompleteType (original_tag_decl);
+ }
+
+ DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
+
+ if (!original_decl_context)
+ break;
- if (copied_result)
- context.AddNamedDecl(copied_result);
+ for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+ iter != original_decl_context->decls_end();
+ ++iter)
+ {
+ NamedDecl *named_decl = dyn_cast<NamedDecl>(*iter);
+
+ if (named_decl && named_decl->getName().equals(name.GetCString()))
+ {
+ Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, named_decl);
+ NamedDecl *copied_named_decl = dyn_cast<NamedDecl>(copied_decl);
+
+ if (!copied_named_decl)
+ continue;
+
+ context.AddNamedDecl (copied_named_decl);
}
}
+
+ return;
}
while (0);
@@ -1824,7 +1820,7 @@
log->Printf("%s", s.c_str());
}
- clang::NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl);
+ NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl);
if (clang_namespace_decl)
clang_namespace_decl->setHasExternalLexicalStorage();
}
@@ -1976,44 +1972,103 @@
}
}
-const clang::DeclContext *
-ClangExpressionDeclMap::CompleteDeclContext (clang::ASTContext *ast_context,
- const clang::DeclContext *decl_context)
+clang::ExternalLoadResult
+ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_context,
+ bool (*predicate)(Decl::Kind),
+ llvm::SmallVectorImpl<Decl*> &decls)
{
- lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- const NamedDecl *named_decl = dyn_cast<NamedDecl>(decl_context);
-
- if (named_decl)
- log->Printf("Completing a '%s' DeclContext named '%s'", decl_context->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
- else
- log->Printf("Completing a '%s' DeclContext", decl_context->getDeclKindName());
- }
-
assert (m_parser_vars.get());
- if (!m_parser_vars->GetASTImporter (ast_context)->CompleteDeclContext(decl_context))
- return NULL;
+ lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+
+ const Decl *context_decl = dyn_cast<Decl>(decl_context);
+
+ if (!context_decl)
+ return ELR_Failure;
+
+ ASTContext *ast_context = &context_decl->getASTContext();
+
+ if (log)
+ log->Printf("Finding lexical decls in a '%s' with %s predicate", context_decl->getDeclKindName(), (predicate ? "non-null" : "null"));
+
+ Decl *original_decl = NULL;
+ ASTContext *original_ctx = NULL;
+
+ ClangASTImporter *ast_importer = m_parser_vars->GetASTImporter(ast_context);
+
+ if (!ast_importer)
+ return ELR_Failure;
+
+ if (!ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
+ return ELR_Failure;
if (log)
{
- const Decl *decl = dyn_cast<Decl>(decl_context);
+ std::string decl_print_string;
+ llvm::raw_string_ostream decl_print_stream(decl_print_string);
+ original_decl->print(decl_print_stream);
+ decl_print_stream.flush();
+ log->Printf("Original decl:\n%s", decl_print_string.c_str());
+ }
+
+ if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
+ {
+ ExternalASTSource *external_source = original_ctx->getExternalSource();
- if (decl)
+ if (!external_source)
+ return ELR_Failure;
+
+ if (!original_tag_decl)
+ return ELR_Failure;
+
+ external_source->CompleteType (original_tag_decl);
+ }
+
+ DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
+
+ if (!original_decl_context)
+ return ELR_Failure;
+
+ for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+ iter != original_decl_context->decls_end();
+ ++iter)
+ {
+ Decl *decl = *iter;
+
+ if (!predicate || predicate(decl->getKind()))
{
- std::string s;
- llvm::raw_string_ostream os(s);
- decl->print(os);
- os.flush();
+ if (log)
+ {
+ std::string decl_print_string;
+ llvm::raw_string_ostream decl_print_stream(decl_print_string);
+ decl->print(decl_print_stream);
+ decl_print_stream.flush();
+ log->Printf(" Adding lexical decl %s", decl_print_string.c_str());
+ }
+
+ Decl *copied_decl = ast_importer->CopyDecl(original_ctx, decl);
- log->Printf("After:");
- log->Printf("%s", s.c_str());
+ decls.push_back(copied_decl);
}
}
- return decl_context;
+ return ELR_AlreadyLoaded;
+}
+
+void
+ClangExpressionDeclMap::CompleteTagDecl (TagDecl *tag_decl)
+{
+ assert (m_parser_vars.get());
+
+ m_parser_vars->GetASTImporter(&tag_decl->getASTContext())->CompleteTagDecl (tag_decl);
+}
+
+void
+ClangExpressionDeclMap::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
+{
+ assert (m_parser_vars.get());
+
+ m_parser_vars->GetASTImporter(&interface_decl->getASTContext())->CompleteObjCInterfaceDecl (interface_decl);
}
Value *
@@ -2021,7 +2076,7 @@
(
ExecutionContext &exe_ctx,
VariableSP var,
- clang::ASTContext *parser_ast_context,
+ ASTContext *parser_ast_context,
TypeFromUser *user_type,
TypeFromParser *parser_type
)
@@ -2046,7 +2101,7 @@
return NULL;
}
- clang::ASTContext *ast = var_type->GetClangASTContext().getASTContext();
+ ASTContext *ast = var_type->GetClangASTContext().getASTContext();
if (!ast)
{
@@ -2170,12 +2225,12 @@
log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str());
- if (log->GetVerbose())
- {
- StreamString var_decl_dump_string;
- ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
- log->Printf("%s\n", var_decl_dump_string.GetData());
- }
+ //if (log->GetVerbose())
+ //{
+ // StreamString var_decl_dump_string;
+ // ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
+ // log->Printf("%s\n", var_decl_dump_string.GetData());
+ //}
}
}
@@ -2219,7 +2274,7 @@
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- clang::ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
+ ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
TypeFromUser user_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(scratch_ast_context, true)),
scratch_ast_context);
@@ -2265,12 +2320,12 @@
log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str());
- if (log->GetVerbose())
- {
- StreamString var_decl_dump_string;
- ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
- log->Printf("%s\n", var_decl_dump_string.GetData());
- }
+ //if (log->GetVerbose())
+ //{
+ // StreamString var_decl_dump_string;
+ // ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
+ // log->Printf("%s\n", var_decl_dump_string.GetData());
+ //}
}
}
@@ -2279,7 +2334,7 @@
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- clang::ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
+ ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
for (size_t index = 0, num_entities = m_found_entities.GetSize();
index < num_entities;
@@ -2374,17 +2429,17 @@
}
}
-clang::NamespaceDecl *
+NamespaceDecl *
ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, const ClangNamespaceDecl &namespace_decl)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
assert (m_parser_vars.get());
- clang::Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
+ Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
namespace_decl.GetNamespaceDecl());
- return dyn_cast<clang::NamespaceDecl>(copied_decl);
+ return dyn_cast<NamespaceDecl>(copied_decl);
}
void
@@ -2402,7 +2457,7 @@
// only valid for Functions, not for Symbols
void *fun_opaque_type = NULL;
- clang::ASTContext *fun_ast_context = NULL;
+ ASTContext *fun_ast_context = NULL;
if (fun)
{
@@ -2478,8 +2533,8 @@
TypeFromUser &ut,
bool add_method)
{
- clang::ASTContext *parser_ast_context = context.GetASTContext();
- clang::ASTContext *user_ast_context = ut.GetASTContext();
+ ASTContext *parser_ast_context = context.GetASTContext();
+ ASTContext *user_ast_context = ut.GetASTContext();
void *copied_type = GuardedCopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType());
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index 01095b5..c8385c2 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -123,7 +123,6 @@
case ASTPrint: return new ASTPrintAction();
case ASTDumpXML: return new ASTDumpXMLAction();
case ASTView: return new ASTViewAction();
- case BoostCon: return new BoostConAction();
case DumpRawTokens: return new DumpRawTokensAction();
case DumpTokens: return new DumpTokensAction();
case EmitAssembly: return new EmitAssemblyAction();
@@ -199,6 +198,7 @@
InitializeLLVM() {
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
+ llvm::InitializeAllTargetMCs();
}
} InitializeLLVM;
@@ -557,9 +557,7 @@
RecordingMemoryManager *jit_memory_manager = new RecordingMemoryManager();
std::string error_string;
-
- llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_);
-
+
#if defined (USE_STANDARD_JIT)
m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module,
&error_string,
@@ -571,11 +569,12 @@
EngineBuilder builder(module);
builder.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_string)
+ .setRelocationModel(llvm::Reloc::PIC_)
.setJITMemoryManager(jit_memory_manager)
.setOptLevel(CodeGenOpt::Less)
.setAllocateGVsWithCode(true)
.setCodeModel(CodeModel::Small)
- .setUseMCJIT(true);
+ .setUseMCJIT(true);
m_execution_engine.reset(builder.create());
#endif
diff --git a/source/Expression/IRDynamicChecks.cpp b/source/Expression/IRDynamicChecks.cpp
index dd09b12..22624ea 100644
--- a/source/Expression/IRDynamicChecks.cpp
+++ b/source/Expression/IRDynamicChecks.cpp
@@ -258,12 +258,14 @@
//------------------------------------------------------------------
llvm::Value *BuildPointerValidatorFunc(lldb::addr_t start_address)
{
- std::vector<const llvm::Type*> params;
-
- const IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
+ IntegerType *intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
(m_module.getPointerSize() == llvm::Module::Pointer64) ? 64 : 32);
- params.push_back(GetI8PtrTy());
+ llvm::Type *param_array[1];
+
+ param_array[0] = const_cast<llvm::PointerType*>(GetI8PtrTy());
+
+ ArrayRef<llvm::Type*> params(param_array, 1);
FunctionType *fun_ty = FunctionType::get(llvm::Type::getVoidTy(m_module.getContext()), params, true);
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
@@ -271,7 +273,7 @@
return ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
}
- const PointerType *GetI8PtrTy()
+ PointerType *GetI8PtrTy()
{
if (!m_i8ptr_ty)
m_i8ptr_ty = llvm::Type::getInt8PtrTy(m_module.getContext());
@@ -286,7 +288,7 @@
llvm::Module &m_module; ///< The module which is being instrumented
DynamicCheckerFunctions &m_checker_functions; ///< The dynamic checker functions for the process
private:
- const PointerType *m_i8ptr_ty;
+ PointerType *m_i8ptr_ty;
};
class ValidPointerChecker : public Instrumenter
@@ -332,12 +334,14 @@
// Insert an instruction to call the helper with the result
- SmallVector <llvm::Value*, 1> args;
- args.push_back(bit_cast);
+ llvm::Value *arg_array[1];
+
+ arg_array[0] = bit_cast;
+
+ llvm::ArrayRef<llvm::Value *> args(arg_array, 1);
CallInst::Create(m_valid_pointer_check_func,
- args.begin(),
- args.end(),
+ args,
"",
inst);
@@ -397,12 +401,14 @@
// Insert an instruction to call the helper with the result
- SmallVector <llvm::Value*, 1> args;
- args.push_back(bit_cast);
+ llvm::Value *arg_array[1];
+
+ arg_array[0] = bit_cast;
+
+ ArrayRef<llvm::Value*> args(arg_array, 1);
CallInst::Create(m_objc_object_check_func,
- args.begin(),
- args.end(),
+ args,
"",
inst);
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index 6037cd0..dd73c51 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -310,24 +310,28 @@
ValueSymbolTable& value_symbol_table = m_module->getValueSymbolTable();
+ std::string result_name_str;
const char *result_name = NULL;
for (ValueSymbolTable::iterator vi = value_symbol_table.begin(), ve = value_symbol_table.end();
vi != ve;
++vi)
{
- if (strstr(vi->first(), "$__lldb_expr_result_ptr") &&
- !strstr(vi->first(), "GV"))
+ result_name_str = vi->first().str();
+ const char *value_name = result_name_str.c_str();
+
+ if (strstr(value_name, "$__lldb_expr_result_ptr") &&
+ !strstr(value_name, "GV"))
{
- result_name = vi->first();
+ result_name = value_name;
m_result_is_pointer = true;
break;
}
- if (strstr(vi->first(), "$__lldb_expr_result") &&
- !strstr(vi->first(), "GV"))
+ if (strstr(value_name, "$__lldb_expr_result") &&
+ !strstr(value_name, "GV"))
{
- result_name = vi->first();
+ result_name = value_name;
m_result_is_pointer = false;
break;
}
@@ -580,13 +584,13 @@
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- const Type *ns_str_ty = ns_str->getType();
+ Type *ns_str_ty = ns_str->getType();
- const Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
- const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
+ Type *i8_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
+ IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
(m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
- const Type *i32_ty = Type::getInt32Ty(m_module->getContext());
- const Type *i8_ty = Type::getInt8Ty(m_module->getContext());
+ Type *i32_ty = Type::getInt32Ty(m_module->getContext());
+ Type *i8_ty = Type::getInt8Ty(m_module->getContext());
if (!m_CFStringCreateWithBytes)
{
@@ -627,12 +631,16 @@
// CFStringEncoding -> i32
// Boolean -> i8
- std::vector <const Type *> CFSCWB_arg_types;
- CFSCWB_arg_types.push_back(i8_ptr_ty);
- CFSCWB_arg_types.push_back(i8_ptr_ty);
- CFSCWB_arg_types.push_back(intptr_ty);
- CFSCWB_arg_types.push_back(i32_ty);
- CFSCWB_arg_types.push_back(i8_ty);
+ Type *arg_type_array[5];
+
+ arg_type_array[0] = i8_ptr_ty;
+ arg_type_array[1] = i8_ptr_ty;
+ arg_type_array[2] = intptr_ty;
+ arg_type_array[3] = i32_ty;
+ arg_type_array[4] = i8_ty;
+
+ ArrayRef<Type *> CFSCWB_arg_types(arg_type_array, 5);
+
llvm::Type *CFSCWB_ty = FunctionType::get(ns_str_ty, CFSCWB_arg_types, false);
// Build the constant containing the pointer to the function
@@ -645,24 +653,25 @@
if (cstr)
string_array = dyn_cast<ConstantArray>(cstr->getInitializer());
-
- SmallVector <Value*, 5> CFSCWB_arguments;
-
+
Constant *alloc_arg = Constant::getNullValue(i8_ptr_ty);
Constant *bytes_arg = cstr ? ConstantExpr::getBitCast(cstr, i8_ptr_ty) : Constant::getNullValue(i8_ptr_ty);
Constant *numBytes_arg = ConstantInt::get(intptr_ty, cstr ? string_array->getType()->getNumElements() - 1 : 0, false);
Constant *encoding_arg = ConstantInt::get(i32_ty, 0x0600, false); /* 0x0600 is kCFStringEncodingASCII */
Constant *isExternal_arg = ConstantInt::get(i8_ty, 0x0, false); /* 0x0 is false */
- CFSCWB_arguments.push_back(alloc_arg);
- CFSCWB_arguments.push_back(bytes_arg);
- CFSCWB_arguments.push_back(numBytes_arg);
- CFSCWB_arguments.push_back(encoding_arg);
- CFSCWB_arguments.push_back(isExternal_arg);
+ Value *argument_array[5];
+
+ argument_array[0] = alloc_arg;
+ argument_array[1] = bytes_arg;
+ argument_array[2] = numBytes_arg;
+ argument_array[3] = encoding_arg;
+ argument_array[4] = isExternal_arg;
+
+ ArrayRef <Value *> CFSCWB_arguments(argument_array, 5);
CallInst *CFSCWB_call = CallInst::Create(m_CFStringCreateWithBytes,
- CFSCWB_arguments.begin(),
- CFSCWB_arguments.end(),
+ CFSCWB_arguments,
"CFStringCreateWithBytes",
FirstEntryInstruction);
@@ -707,7 +716,10 @@
vi != ve;
++vi)
{
- if (strstr(vi->first(), "_unnamed_cfstring_"))
+ std::string value_name = vi->first().str();
+ const char *value_name_cstr = value_name.c_str();
+
+ if (strstr(value_name_cstr, "_unnamed_cfstring_"))
{
Value *nsstring_value = vi->second;
@@ -860,9 +872,9 @@
if (log)
{
if (cstr_array)
- log->Printf("Found NSString constant %s, which contains \"%s\"", vi->first(), cstr_array->getAsString().c_str());
+ log->Printf("Found NSString constant %s, which contains \"%s\"", value_name_cstr, cstr_array->getAsString().c_str());
else
- log->Printf("Found NSString constant %s, which contains \"\"", vi->first());
+ log->Printf("Found NSString constant %s, which contains \"\"", value_name_cstr);
}
if (!cstr_array)
@@ -884,7 +896,10 @@
vi != ve;
++vi)
{
- if (!strcmp(vi->first(), "__CFConstantStringClassReference"))
+ std::string value_name = vi->first().str();
+ const char *value_name_cstr = value_name.c_str();
+
+ if (!strcmp(value_name_cstr, "__CFConstantStringClassReference"))
{
GlobalVariable *gv = dyn_cast<GlobalVariable>(vi->second);
@@ -995,29 +1010,34 @@
// The below code would be "more correct," but in actuality what's required is uint8_t*
//Type *sel_type = StructType::get(m_module->getContext());
//Type *sel_ptr_type = PointerType::getUnqual(sel_type);
- const Type *sel_ptr_type = Type::getInt8PtrTy(m_module->getContext());
+ Type *sel_ptr_type = Type::getInt8PtrTy(m_module->getContext());
- std::vector <const Type *> srN_arg_types;
- srN_arg_types.push_back(Type::getInt8PtrTy(m_module->getContext()));
+ Type *type_array[1];
+
+ type_array[0] = llvm::Type::getInt8PtrTy(m_module->getContext());
+
+ ArrayRef<Type *> srN_arg_types(type_array, 1);
+
llvm::Type *srN_type = FunctionType::get(sel_ptr_type, srN_arg_types, false);
// Build the constant containing the pointer to the function
- const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
+ IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
+ (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type);
Constant *srN_addr_int = ConstantInt::get(intptr_ty, sel_registerName_addr, false);
m_sel_registerName = ConstantExpr::getIntToPtr(srN_addr_int, srN_ptr_ty);
}
- SmallVector <Value*, 1> srN_arguments;
-
+ Value *argument_array[1];
+
Constant *omvn_pointer = ConstantExpr::getBitCast(_objc_meth_var_name_, Type::getInt8PtrTy(m_module->getContext()));
- srN_arguments.push_back(omvn_pointer);
+ argument_array[0] = omvn_pointer;
+ ArrayRef<Value *> srN_arguments(argument_array, 1);
+
CallInst *srN_call = CallInst::Create(m_sel_registerName,
- srN_arguments.begin(),
- srN_arguments.end(),
+ srN_arguments,
"sel_registerName",
selector_load);
@@ -1338,10 +1358,10 @@
if (log)
log->Printf("Found \"%s\" at 0x%llx", name.GetCString(), symbol_addr);
- const Type *symbol_type = symbol->getType();
+ Type *symbol_type = symbol->getType();
- const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
+ IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
+ (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false);
@@ -1398,7 +1418,7 @@
if (!fun)
{
if (m_error_stream)
- m_error_stream->Printf("Internal error [IRForTarget]: Called entity is a cast of something not a function\n");
+ m_error_stream->Printf("Internal error [IRForTaget]: Called entity is a cast of something not a function\n");
return false;
}
@@ -1495,9 +1515,9 @@
if (!fun_value_ptr || !*fun_value_ptr)
{
- const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
- const FunctionType *fun_ty = fun->getFunctionType();
+ IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
+ (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
+ FunctionType *fun_ty = fun->getFunctionType();
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
Constant *fun_addr_int = ConstantInt::get(intptr_ty, fun_addr, false);
fun_addr_ptr = ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty);
@@ -1636,7 +1656,7 @@
m_data_allocator->GetStream().Write(str.c_str(), str.length() + 1);
}
- const Type *char_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
+ Type *char_ptr_ty = Type::getInt8PtrTy(m_module->getContext());
for (OffsetsTy::iterator oi = offsets.begin(), oe = offsets.end();
oi != oe;
@@ -1789,7 +1809,7 @@
m_data_allocator->GetStream().Write(data.GetBytes(), operand_data_size);
- const llvm::Type *fp_ptr_ty = operand_constant_fp->getType()->getPointerTo();
+ llvm::Type *fp_ptr_ty = operand_constant_fp->getType()->getPointerTo();
Constant *new_pointer = BuildRelocation(fp_ptr_ty, offset);
@@ -1961,8 +1981,8 @@
if (ptr == old_constant)
ptr = new_constant;
-
- SmallVector<Value*, 16> indices;
+
+ std::vector<Value*> index_vector;
unsigned operand_index;
unsigned num_operands = constant_expr->getNumOperands();
@@ -1976,10 +1996,12 @@
if (operand == old_constant)
operand = new_constant;
- indices.push_back(operand);
+ index_vector.push_back(operand);
}
- GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices.begin(), indices.end(), "", first_entry_inst));
+ ArrayRef <Value*> indices(index_vector);
+
+ GetElementPtrInst *get_element_ptr(GetElementPtrInst::Create(ptr, indices, "", first_entry_inst));
UnfoldConstant(constant_expr, get_element_ptr, first_entry_inst);
}
@@ -2107,7 +2129,7 @@
}
LLVMContext &context(m_module->getContext());
- const IntegerType *offset_type(Type::getInt32Ty(context));
+ IntegerType *offset_type(Type::getInt32Ty(context));
if (!offset_type)
{
@@ -2139,7 +2161,7 @@
PrintValue(value, true).c_str(),
offset);
- ConstantInt *offset_int(ConstantInt::getSigned(offset_type, offset));
+ ConstantInt *offset_int(ConstantInt::get(offset_type, offset, true));
GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(argument, offset_int, "", FirstEntryInstruction);
Value *replacement = NULL;
@@ -2178,16 +2200,23 @@
}
llvm::Constant *
-IRForTarget::BuildRelocation(const llvm::Type *type,
+IRForTarget::BuildRelocation(llvm::Type *type,
uint64_t offset)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
+ IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
+ (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
llvm::Constant *offset_int = ConstantInt::get(intptr_ty, offset);
- llvm::Constant *reloc_getelementptr = ConstantExpr::getGetElementPtr(m_reloc_placeholder, &offset_int, 1);
+
+ llvm::Constant *offset_array[1];
+
+ offset_array[0] = offset_int;
+
+ llvm::ArrayRef<llvm::Constant *> offsets(offset_array, 1);
+
+ llvm::Constant *reloc_getelementptr = ConstantExpr::getGetElementPtr(m_reloc_placeholder, offsets);
llvm::Constant *reloc_getbitcast = ConstantExpr::getBitCast(reloc_getelementptr, type);
return reloc_getbitcast;
@@ -2214,8 +2243,8 @@
if (!allocation)
return false;
- const IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
- (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
+ IntegerType *intptr_ty = Type::getIntNTy(m_module->getContext(),
+ (m_module->getPointerSize() == Module::Pointer64) ? 64 : 32);
Constant *relocated_addr = ConstantInt::get(intptr_ty, (uint64_t)allocation);
Constant *relocated_bitcast = ConstantExpr::getIntToPtr(relocated_addr, llvm::Type::getInt8PtrTy(m_module->getContext()));
@@ -2255,7 +2284,7 @@
return false;
}
- const llvm::Type *intptr_ty = Type::getInt8Ty(m_module->getContext());
+ llvm::Type *intptr_ty = Type::getInt8Ty(m_module->getContext());
m_reloc_placeholder = new llvm::GlobalVariable((*m_module),
intptr_ty,