[syntax tree] fixed bug in pointer arithmetic

This commit is contained in:
Philippe Tillet
2019-01-08 18:04:19 -05:00
parent 73db84c8ba
commit 7dfa578c9d
3 changed files with 7 additions and 3 deletions

View File

@@ -56,7 +56,11 @@ void node::implicit_cast(ir::builder &builder, ir::value *&lhs, ir::value *&rhs,
ir::type *left_ty = lhs->get_type()->get_scalar_ty();
ir::type *right_ty = rhs->get_type()->get_scalar_ty();
// One operand is pointer
if(left_ty->is_pointer_ty()){
if(left_ty->is_pointer_ty() || right_ty->is_pointer_ty()){
if(left_ty->is_pointer_ty() && right_ty->is_pointer_ty())
throw std::runtime_error("invalid operands");
if(right_ty->is_pointer_ty())
std::swap(lhs, rhs);
is_ptr = true;
}
// One operand is double