Skip to content

Commit 7eacf6a

Browse files
committed
XXPRUTIL: rationalize memory variable handling
1 parent 66db636 commit 7eacf6a

File tree

4 files changed

+48
-70
lines changed

4 files changed

+48
-70
lines changed

chb/arm/opcodes/ARMAdd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,9 @@ def pointer_arithmetic_expr() -> AST.ASTExpr:
432432
astree.add_lval_defuses(hl_lhs, defuses[0])
433433
astree.add_lval_defuses_high(hl_lhs, defuseshigh[0])
434434

435+
if astree.has_register_variable_intro(iaddr):
436+
rvintro = astree.get_register_variable_intro(iaddr)
437+
if rvintro.has_cast():
438+
astree.add_expose_instruction(hl_assign.instrid)
439+
435440
return ([hl_assign], [ll_assign])

chb/arm/opcodes/ARMStoreRegisterHalfword.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ def ast_prov(
223223
# assignments must be explicitly forced to appear in the lifting
224224
if (
225225
xd.is_vmem_unknown
226+
or lhs.is_memory_variable and cast("VMemoryVariable",
227+
lhs.denotation).base.is_basevar
226228
or hl_lhs.offset.is_index_offset
227229
or hl_lhs.offset.is_field_offset):
228230
astree.add_expose_instruction(hl_assign.instrid)

chb/ast/ASTNode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ------------------------------------------------------------------------------
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2021-2023 Aarno Labs LLC
7+
# Copyright (c) 2021-2025 Aarno Labs LLC
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal

chb/invariants/XXprUtil.py

Lines changed: 40 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,11 @@ def memory_variable_to_lval_expression(
397397
astbase, offset=astoffset, anonymous=anonymous)
398398

399399
else:
400-
chklogger.logger.error(
401-
"AST conversion of non-typecast basevar %s at address %s "
402-
+ "not yet supported",
403-
str(base), iaddr)
400+
if not anonymous:
401+
chklogger.logger.error(
402+
"AST conversion of non-typecast basevar %s at address %s "
403+
+ "not yet supported",
404+
str(base), iaddr)
404405
return astree.mk_temp_lval_expression()
405406

406407
name = str(base)
@@ -699,71 +700,14 @@ def vinitmemory_value_to_ast_lval_expression(
699700

700701
if avar.is_memory_variable and avar.is_basevar_variable:
701702
avar = cast("VMemoryVariable", avar)
702-
if not (avar.offset.is_constant_value_offset or avar.offset.is_no_offset):
703-
chklogger.logger.error(
704-
"Non-constant offset: %s not yet supported at address %s",
705-
str(avar.offset), iaddr)
706-
return astree.mk_temp_lval_expression()
707-
708-
coff = avar.offset.offsetvalue()
709-
astbase = xvariable_to_ast_def_lval_expression(
710-
avar.basevar, xdata, iaddr, astree, size=size, anonymous=anonymous)
711-
astbasetype = astbase.ctype(astree.ctyper)
712-
713-
if astbasetype is None:
714-
chklogger.logger.error(
715-
"AST conversion of vinitmemory value %s with basevar %s and "
716-
+ "offset %s at address %s unsuccessful because of lack of type "
717-
+ "of basevar",
718-
str(vconstvar), str(astbase), str(coff), iaddr)
719-
return astree.mk_temp_lval_expression()
720-
721-
if astbasetype.is_pointer:
722-
tgttype = cast(AST.ASTTypPtr, astbasetype).tgttyp
723-
if tgttype.is_scalar:
724-
return astree.mk_memref_expr(astbase, anonymous=anonymous)
725-
726-
if tgttype.is_compound:
727-
728-
compkey = cast(AST.ASTTypComp, tgttype).compkey
729-
if not astree.has_compinfo(compkey):
730-
chklogger.logger.error(
731-
"Encountered compinfo key without definition in"
732-
+ "symbol table: %d",
733-
compkey)
734-
return astree.mk_temp_lval_expression()
735-
736-
compinfo = astree.compinfo(compkey)
737-
if not compinfo.has_field_offsets():
738-
chklogger.logger.error(
739-
"No fields are specified for compinfo %s (at address %s)",
740-
compinfo.compname, iaddr)
741-
return astree.mk_temp_lval_expression()
742-
743-
if not compinfo.has_field_offset(coff):
744-
chklogger.logger.error(
745-
"Compinfo %s does not have a field at offset %d "
746-
+ "(at address %s)",
747-
compinfo.compname, coff, iaddr)
748-
return astree.mk_temp_lval_expression()
749-
750-
(field, restoffset) = compinfo.field_at_offset(coff)
751-
if restoffset > 0:
752-
chklogger.logger.error(
753-
"Rest offset in memory dereference not yet handled at "
754-
+ "%s: %s",
755-
iaddr, str(restoffset))
756-
return astree.mk_temp_lval_expression()
757-
foffset = astree.mk_field_offset(field.fieldname, compkey)
758-
return astree.mk_memref_expr(
759-
astbase, offset=foffset, anonymous=anonymous)
760-
761-
chklogger.logger.error(
762-
"AST conversion of vinitmemory value %s with astbase %s (type: "
763-
+ "%s) and offset %s at address %s",
764-
str(vconstvar), str(astbase), str(astbasetype), str(avar.offset),
765-
iaddr)
766-
return astree.mk_temp_lval_expression()
703+
return memory_variable_to_lval_expression(
704+
avar.base,
705+
avar.offset,
706+
xdata,
707+
iaddr,
708+
astree,
709+
size=size,
710+
anonymous=anonymous)
767711

768712
if avar.is_memory_variable and avar.is_stack_argument:
769713
return stack_argument_to_ast_lval_expression(
@@ -1056,6 +1000,21 @@ def default() -> AST.ASTExpr:
10561000

10571001
subfoffset: AST.ASTOffset
10581002
compinfo = astree.globalsymboltable.compinfo(compkey)
1003+
if not compinfo.has_field_offsets():
1004+
if not anonymous:
1005+
chklogger.logger.error(
1006+
"No fields are specified for compinfo %s (at address %s)",
1007+
compinfo.compname, iaddr)
1008+
return astree.mk_temp_lval_expression()
1009+
1010+
if not compinfo.has_field_offset(cst2):
1011+
if not anonymous:
1012+
chklogger.logger.error(
1013+
"Compinfo %s does not have a field at offset %d "
1014+
+ "(at address %s)",
1015+
compinfo.compname, cst2, iaddr)
1016+
return astree.mk_temp_lval_expression()
1017+
10591018
(field, restoffset) = compinfo.field_at_offset(cst2)
10601019

10611020
if restoffset > 0:
@@ -1846,6 +1805,18 @@ def vargument_deref_value_to_ast_lval(
18461805
vinfo, anonymous=anonymous)
18471806
return astree.mk_memref_lval(vexpr, anonymous=anonymous)
18481807

1808+
if offset.is_field_offset:
1809+
if basevar.is_typecast_value:
1810+
tcval = cast("VTypeCastValue", basevar.denotation.auxvar)
1811+
asttgttype = tcval.tgttype.convert(astree.typconverter)
1812+
vinfo = astree.mk_vinfo(tcval.name, vtype=asttgttype)
1813+
astbase = astree.mk_vinfo_lval_expression(vinfo)
1814+
offset = cast("VMemoryOffsetFieldOffset", offset)
1815+
astoffset: AST.ASTOffset = field_offset_to_ast_offset(
1816+
offset, xdata, iaddr, astree, anonymous=anonymous)
1817+
return astree.mk_memref_lval(
1818+
astbase, offset=astoffset, anonymous=anonymous)
1819+
18491820
if not offset.is_constant_value_offset:
18501821
if not anonymous:
18511822
chklogger.logger.error(

0 commit comments

Comments
 (0)