Skip to content

Commit 2ec0d3a

Browse files
committed
ARM: add support for tail call returning a value (Issue:223)
1 parent 8970220 commit 2ec0d3a

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

chb/app/CHVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
chbversion: str = "0.3.0-20250502"
1+
chbversion: str = "0.3.0-20250608"

chb/arm/ARMCallOpcode.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ def ast_call_prov(
331331
# Note that defuses[0] may be None even when defuseshigh[0] is not
332332
# None. This happens when the return value's only use is as a
333333
# return value of the caller's function itself.
334-
if rtype.is_void or ((defuses[0] is None) and (defuseshigh[0] is None)):
334+
if (
335+
rtype.is_void
336+
or ((defuses[0] is None)
337+
and (defuseshigh[0] is None)
338+
and not self.return_value)):
335339
chklogger.logger.info(
336340
"Unused: introduced ssa-variable: %s for return value of %s "
337341
+ "at address %s",

chb/arm/opcodes/ARMAdd.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ def ast_prov(
259259

260260
annotations: List[str] = [iaddr, "ADD"]
261261

262+
if xdata.is_aggregate_jumptable:
263+
chklogger.logger.warning(
264+
"ADD: aggregate jumptable at address %s not yet handled",
265+
iaddr)
266+
return ([], [])
267+
262268
# low-level assignment
263269

264270
(ll_lhs, _, _) = self.operands[0].ast_lvalue(astree)

chb/arm/opcodes/ARMBranch.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ def is_xtgt_ok(self) -> bool:
149149
else:
150150
return self.is_xpr_ok(4)
151151

152+
def has_return_xpr(self) -> bool:
153+
return self.xdata.has_return_xpr()
154+
155+
def returnval(self) -> "XXpr":
156+
return self.xdata.get_return_xpr()
157+
158+
def rreturnval(self) -> "XXpr":
159+
return self.xdata.get_return_xxpr()
160+
161+
def has_creturnval(self) -> bool:
162+
return self.xdata.has_return_cxpr()
163+
164+
def creturnval(self) -> "XXpr":
165+
return self.xdata.get_return_cxpr()
166+
152167
@property
153168
def annotation(self) -> str:
154169
if self.is_conditional:
@@ -234,6 +249,19 @@ def jump_target(self, xdata: InstrXData) -> Optional["XXpr"]:
234249
else:
235250
return xdata.xprs[0]
236251

252+
def is_return_instruction(self, xdata: InstrXData) -> bool:
253+
return ARMBranchXData(xdata).has_return_xpr()
254+
255+
def return_value(self, xdata: InstrXData) -> Optional[XXpr]:
256+
xd = ARMBranchXData(xdata)
257+
if xd.has_return_xpr():
258+
if xd.has_creturnval():
259+
return xd.creturnval()
260+
else:
261+
return xd.rreturnval()
262+
else:
263+
return None
264+
237265
def annotation(self, xdata: InstrXData) -> str:
238266
xd = ARMBranchXData(xdata)
239267
if xd.is_ok:

0 commit comments

Comments
 (0)