llvm::cast<Instruction>(m_entry_instruction_finder.GetValue(function)));
});
- if (!UnfoldConstant(ns_str, CFSCWB_Caller, m_entry_instruction_finder))
+ if (!UnfoldConstant(ns_str, nullptr, CFSCWB_Caller, m_entry_instruction_finder, nullptr))
{
if (log)
log->PutCString("Couldn't replace the NSString with the result of the call");
// This function does not report errors; its callers are responsible.
bool
IRForTarget::UnfoldConstant(Constant *old_constant,
+ llvm::Function *llvm_function,
FunctionValueCache &value_maker,
- FunctionValueCache &entry_instruction_finder)
+ FunctionValueCache &entry_instruction_finder,
+ lldb_private::Stream *error_stream)
{
lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
llvm::cast<Instruction>(entry_instruction_finder.GetValue(function)));
});
- if (!UnfoldConstant(constant_expr, bit_cast_maker, entry_instruction_finder))
+ if (!UnfoldConstant(constant_expr, llvm_function, bit_cast_maker, entry_instruction_finder, error_stream))
return false;
}
break;
return GetElementPtrInst::Create(nullptr, ptr, indices, "", llvm::cast<Instruction>(entry_instruction_finder.GetValue(function)));
});
- if (!UnfoldConstant(constant_expr, get_element_pointer_maker, entry_instruction_finder))
+ if (!UnfoldConstant(constant_expr, llvm_function, get_element_pointer_maker, entry_instruction_finder, error_stream))
return false;
}
break;
{
if (Instruction *inst = llvm::dyn_cast<Instruction>(user))
{
+ if (llvm_function && inst->getParent()->getParent() != llvm_function)
+ {
+ if (error_stream)
+ {
+ error_stream->PutCString("error: Capturing non-local variables in expressions is unsupported.\n");
+ }
+ return false;
+ }
inst->replaceUsesOfWith(old_constant, value_maker.GetValue(inst->getParent()->getParent()));
}
else
if (Constant *constant = dyn_cast<Constant>(value))
{
- UnfoldConstant(constant, body_result_maker, m_entry_instruction_finder);
+ if (!UnfoldConstant(constant, &llvm_function, body_result_maker, m_entry_instruction_finder, m_error_stream))
+ {
+ return false;
+ }
}
else if (Instruction *instruction = dyn_cast<Instruction>(value))
{
+ if (instruction->getParent()->getParent() != &llvm_function)
+ {
+ if (m_error_stream)
+ {
+ m_error_stream->PutCString("error: Capturing non-local variables in expressions is unsupported.\n");
+ }
+ return false;
+ }
value->replaceAllUsesWith(body_result_maker.GetValue(instruction->getParent()->getParent()));
}
else
FunctionValueCache m_entry_instruction_finder;
static bool
- UnfoldConstant (llvm::Constant *old_constant,
+ UnfoldConstant (llvm::Constant *old_constant,
+ llvm::Function *llvm_function,
FunctionValueCache &value_maker,
- FunctionValueCache &entry_instruction_finder);
+ FunctionValueCache &entry_instruction_finder,
+ lldb_private::Stream *error_stream);
//------------------------------------------------------------------
/// Construct a reference to m_reloc_placeholder with a given type