Author: spyffe Date: Fri Feb 12 15:16:58 2016 New Revision: 260735 URL: http://llvm.org/viewvc/llvm-project?rev=260735&view=rev Log: IRInterpreter now recognizes expressions with constants it doesn't handle.
If an instruction has a constant that IRInterpreter doesn't know how to deal with (say, an array constant, because we can't materialize it to APInt) then we used to ignore that and only fail during expression execution. This is annoying because if IRInterpreter had just returned false from CanInterpret(), the JIT would have been used. Now the IRInterpreter checks constants as part of CanInterpret(), so this should hopefully no longer be an issue. Modified: lldb/trunk/source/Expression/IRInterpreter.cpp Modified: lldb/trunk/source/Expression/IRInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=260735&r1=260734&r2=260735&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRInterpreter.cpp (original) +++ lldb/trunk/source/Expression/IRInterpreter.cpp Fri Feb 12 15:16:58 2016 @@ -465,6 +465,45 @@ static const char *memory_read_error static const char *infinite_loop_error = "Interpreter ran for too many cycles"; //static const char *bad_result_error = "Result of expression is in bad memory"; +static bool +CanResolveConstant (llvm::Constant *constant) +{ + switch (constant->getValueID()) + { + default: + return false; + case Value::ConstantIntVal: + case Value::ConstantFPVal: + return true; + case Value::ConstantExprVal: + if (const ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(constant)) + { + switch (constant_expr->getOpcode()) + { + default: + return false; + case Instruction::IntToPtr: + case Instruction::PtrToInt: + case Instruction::BitCast: + return CanResolveConstant(constant_expr->getOperand(0)); + case Instruction::GetElementPtr: + { + ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin(); + Constant *base = dyn_cast<Constant>(*op_cursor); + if (!base) + return false; + + return CanResolveConstant(base); + } + } + } else { + return false; + } + case Value::ConstantPointerNullVal: + return true; + } +} + bool IRInterpreter::CanInterpret (llvm::Module &module, llvm::Function &function, @@ -610,6 +649,17 @@ IRInterpreter::CanInterpret (llvm::Modul error.SetErrorString(unsupported_operand_error); return false; } + } + + if (Constant *constant = llvm::dyn_cast<Constant>(operand)) + { + if (!CanResolveConstant(constant)) + { + if (log) + log->Printf("Unsupported constant: %s", PrintValue(constant).c_str()); + error.SetErrorString(unsupported_operand_error); + return false; + } } } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits