From 26222537170067db5088b8dbdcf8ac9599ff715f Mon Sep 17 00:00:00 2001 From: Peter Goodman Date: Wed, 7 Jul 2021 18:12:47 -0400 Subject: [PATCH] Fixes issues in handling conditional branches (#531) --- lib/Arch/AArch32/Decode.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/Arch/AArch32/Decode.cpp b/lib/Arch/AArch32/Decode.cpp index b10f7b2a3..779deb7a4 100644 --- a/lib/Arch/AArch32/Decode.cpp +++ b/lib/Arch/AArch32/Decode.cpp @@ -920,8 +920,6 @@ static bool DecodeCondition(Instruction &inst, uint32_t cond) { auto _8_type = llvm::Type::getInt8Ty(*inst.arch->context); const auto _1 = llvm::ConstantInt::get(_8_type, 1u, false); - // Use ~0 -> 11111111 with XOR op for negation - const auto negate = llvm::ConstantInt::get(_8_type, ~0u, false); bool negate_conditions = false; bool is_cond = true; @@ -952,7 +950,7 @@ static bool DecodeCondition(Instruction &inst, uint32_t cond) { auto c_expr = inst.EmplaceRegister("C"); auto z_expr = inst.EmplaceRegister("Z"); z_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, z_expr, - inst.EmplaceConstant(negate)); + inst.EmplaceConstant(_1)); op_expr = inst.EmplaceBinaryOp(llvm::Instruction::And, z_expr, c_expr); break; } @@ -962,7 +960,7 @@ static bool DecodeCondition(Instruction &inst, uint32_t cond) { auto v_expr = inst.EmplaceRegister("V"); op_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, n_expr, v_expr); op_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, op_expr, - inst.EmplaceConstant(negate)); + inst.EmplaceConstant(_1)); break; } case 0b1101: negate_conditions = true; [[clang::fallthrough]]; @@ -971,10 +969,10 @@ static bool DecodeCondition(Instruction &inst, uint32_t cond) { auto v_expr = inst.EmplaceRegister("V"); op_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, n_expr, v_expr); op_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, op_expr, - inst.EmplaceConstant(negate)); + inst.EmplaceConstant(_1)); auto z_expr = inst.EmplaceRegister("Z"); z_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, z_expr, - inst.EmplaceConstant(negate)); + inst.EmplaceConstant(_1)); op_expr = inst.EmplaceBinaryOp(llvm::Instruction::And, z_expr, op_expr); break; } @@ -991,7 +989,7 @@ static bool DecodeCondition(Instruction &inst, uint32_t cond) { if (negate_conditions) { op_expr = inst.EmplaceBinaryOp(llvm::Instruction::Xor, op_expr, - inst.EmplaceConstant(negate)); + inst.EmplaceConstant(_1)); } AddExprOp(inst, op_expr, 8u); @@ -3494,7 +3492,7 @@ bool AArch32Arch::DecodeInstruction(uint64_t address, } auto ret = decoder(inst, bits); - LOG(ERROR) << inst.Serialize(); +// LOG(ERROR) << inst.Serialize(); return ret; }