forked from OSchip/llvm-project
Fixed handling of explicitly-declared persistent
variables. llvm-svn: 123398
This commit is contained in:
parent
657f227d08
commit
e1175b7c67
|
@ -213,7 +213,7 @@ ClangExpressionDeclMap::AddPersistentVariable
|
||||||
TypeFromUser user_type(ClangASTContext::CopyType(context,
|
TypeFromUser user_type(ClangASTContext::CopyType(context,
|
||||||
parser_type.GetASTContext(),
|
parser_type.GetASTContext(),
|
||||||
parser_type.GetOpaqueQualType()),
|
parser_type.GetOpaqueQualType()),
|
||||||
context);
|
context);
|
||||||
|
|
||||||
if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (name,
|
if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (name,
|
||||||
user_type,
|
user_type,
|
||||||
|
@ -939,7 +939,8 @@ ClangExpressionDeclMap::DoMaterializeOnePersistentVariable
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry)
|
if (var_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry ||
|
||||||
|
var_sp->m_flags & ClangExpressionVariable::EVKeepInTarget)
|
||||||
{
|
{
|
||||||
mem = var_sp->m_live_sp->GetValue().GetScalar().ULongLong();
|
mem = var_sp->m_live_sp->GetValue().GetScalar().ULongLong();
|
||||||
|
|
||||||
|
|
|
@ -816,6 +816,8 @@ bool
|
||||||
IRForTarget::RewritePersistentAlloc (llvm::Instruction *persistent_alloc,
|
IRForTarget::RewritePersistentAlloc (llvm::Instruction *persistent_alloc,
|
||||||
llvm::Module &llvm_module)
|
llvm::Module &llvm_module)
|
||||||
{
|
{
|
||||||
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
||||||
|
|
||||||
AllocaInst *alloc = dyn_cast<AllocaInst>(persistent_alloc);
|
AllocaInst *alloc = dyn_cast<AllocaInst>(persistent_alloc);
|
||||||
|
|
||||||
MDNode *alloc_md = alloc->getMetadata("clang.decl.ptr");
|
MDNode *alloc_md = alloc->getMetadata("clang.decl.ptr");
|
||||||
|
@ -842,8 +844,8 @@ IRForTarget::RewritePersistentAlloc (llvm::Instruction *persistent_alloc,
|
||||||
if (!m_decl_map->AddPersistentVariable(decl, persistent_variable_name, result_decl_type, false, false))
|
if (!m_decl_map->AddPersistentVariable(decl, persistent_variable_name, result_decl_type, false, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
GlobalVariable *persistent_global = new GlobalVariable(llvm_module,
|
GlobalVariable *persistent_global = new GlobalVariable(llvm_module,
|
||||||
alloc->getType()->getElementType(),
|
alloc->getType(),
|
||||||
false, /* not constant */
|
false, /* not constant */
|
||||||
GlobalValue::ExternalLinkage,
|
GlobalValue::ExternalLinkage,
|
||||||
NULL, /* no initializer */
|
NULL, /* no initializer */
|
||||||
|
@ -861,7 +863,17 @@ IRForTarget::RewritePersistentAlloc (llvm::Instruction *persistent_alloc,
|
||||||
MDNode *persistent_global_md = MDNode::get(llvm_module.getContext(), values, 2);
|
MDNode *persistent_global_md = MDNode::get(llvm_module.getContext(), values, 2);
|
||||||
named_metadata->addOperand(persistent_global_md);
|
named_metadata->addOperand(persistent_global_md);
|
||||||
|
|
||||||
alloc->replaceAllUsesWith(persistent_global);
|
// Now, since the variable is a pointer variable, we will drop in a load of that
|
||||||
|
// pointer variable.
|
||||||
|
|
||||||
|
LoadInst *persistent_load = new LoadInst (persistent_global, "", alloc);
|
||||||
|
|
||||||
|
if (log)
|
||||||
|
log->Printf("Replacing \"%s\" with \"%s\"",
|
||||||
|
PrintValue(alloc).c_str(),
|
||||||
|
PrintValue(persistent_load).c_str());
|
||||||
|
|
||||||
|
alloc->replaceAllUsesWith(persistent_load);
|
||||||
alloc->eraseFromParent();
|
alloc->eraseFromParent();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1006,7 +1018,7 @@ IRForTarget::MaybeHandleVariable (Module &llvm_module, Value *llvm_value_ptr)
|
||||||
clang::QualType qual_type;
|
clang::QualType qual_type;
|
||||||
const Type *value_type;
|
const Type *value_type;
|
||||||
|
|
||||||
if (!name.compare("$__lldb_expr_result"))
|
if (name[0] == '$')
|
||||||
{
|
{
|
||||||
// The $__lldb_expr_result name indicates the the return value has allocated as
|
// The $__lldb_expr_result name indicates the the return value has allocated as
|
||||||
// a static variable. Per the comment at ASTResultSynthesizer::SynthesizeBodyResult,
|
// a static variable. Per the comment at ASTResultSynthesizer::SynthesizeBodyResult,
|
||||||
|
@ -1015,6 +1027,8 @@ IRForTarget::MaybeHandleVariable (Module &llvm_module, Value *llvm_value_ptr)
|
||||||
//
|
//
|
||||||
// Consequently, when reporting the size of the type, we report a pointer type pointing
|
// Consequently, when reporting the size of the type, we report a pointer type pointing
|
||||||
// to the type of $__lldb_expr_result, not the type itself.
|
// to the type of $__lldb_expr_result, not the type itself.
|
||||||
|
//
|
||||||
|
// We also do this for any user-declared persistent variables.
|
||||||
|
|
||||||
qual_type = ast_context->getPointerType(clang::QualType::getFromOpaquePtr(opaque_type));
|
qual_type = ast_context->getPointerType(clang::QualType::getFromOpaquePtr(opaque_type));
|
||||||
value_type = PointerType::get(global_variable->getType(), 0);
|
value_type = PointerType::get(global_variable->getType(), 0);
|
||||||
|
@ -1029,7 +1043,7 @@ IRForTarget::MaybeHandleVariable (Module &llvm_module, Value *llvm_value_ptr)
|
||||||
off_t value_alignment = (ast_context->getTypeAlign(qual_type) + 7) / 8;
|
off_t value_alignment = (ast_context->getTypeAlign(qual_type) + 7) / 8;
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
log->Printf("Type of \"%s\" is [clang \"%s\", lldb \"%s\"] [size %d, align %d]",
|
log->Printf("Type of \"%s\" is [clang \"%s\", llvm \"%s\"] [size %d, align %d]",
|
||||||
name.c_str(),
|
name.c_str(),
|
||||||
qual_type.getAsString().c_str(),
|
qual_type.getAsString().c_str(),
|
||||||
PrintType(value_type).c_str(),
|
PrintType(value_type).c_str(),
|
||||||
|
|
Loading…
Reference in New Issue