From 4b3a654f4407b908ab1856d914c6d0fc958daa83 Mon Sep 17 00:00:00 2001 From: rihi Date: Wed, 8 Nov 2023 15:13:34 +0000 Subject: [PATCH 1/3] Create draft PR for #357 From 7a02198e354873ed1ab0bac0edbe71a65630904d Mon Sep 17 00:00:00 2001 From: rihi <19492038+rihi@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:14:43 +0100 Subject: [PATCH 2/3] Fix incorrect signed check --- .../expression_simplification/constant_folding.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py b/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py index 2706987b0..64002a5d1 100644 --- a/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py +++ b/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py @@ -133,8 +133,9 @@ def _constant_fold_shift(constants: list[Constant], fun: Callable[[int, int], in raise IncompatibleOperandCount("Expected exactly 2 constants to fold") left, right = constants + operand_signed = isinstance(left.type, Integer) and left.type.signed - return fun(normalize_int(left.value, left.type.size, left.type.signed and signed), right.value) + return fun(normalize_int(left.value, left.type.size, operand_signed and signed), right.value) _OPERATION_TO_FOLD_FUNCTION: dict[OperationType, Callable[[list[Constant]], int]] = { From b67158d114bf8a3cf889d8e28f3b8cdb99e0812b Mon Sep 17 00:00:00 2001 From: rihi <19492038+rihi@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:47:19 +0100 Subject: [PATCH 3/3] Change syntax in constant_folding.py --- .../expression_simplification/constant_folding.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py b/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py index 64002a5d1..13f345cb7 100644 --- a/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py +++ b/decompiler/pipeline/controlflowanalysis/expression_simplification/constant_folding.py @@ -133,9 +133,9 @@ def _constant_fold_shift(constants: list[Constant], fun: Callable[[int, int], in raise IncompatibleOperandCount("Expected exactly 2 constants to fold") left, right = constants - operand_signed = isinstance(left.type, Integer) and left.type.signed + norm_signed = signed and isinstance(left.type, Integer) and left.type.signed - return fun(normalize_int(left.value, left.type.size, operand_signed and signed), right.value) + return fun(normalize_int(left.value, left.type.size, norm_signed), right.value) _OPERATION_TO_FOLD_FUNCTION: dict[OperationType, Callable[[list[Constant]], int]] = {