Skip to content

Commit cb91ab2

Browse files
committed
ASTI: replace array type by base type for one-element stack arrays
1 parent ad063c6 commit cb91ab2

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

chb/astinterface/ASTInterface.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,10 @@ def introduce_ssa_variables(
934934
935935
Record addresses associated with a given variable to avoid assigning
936936
constants to variables that appear multiple times.
937+
938+
The ssanames, a map from locations to names, provide an alternative
939+
prefix for the newly introduced name. The default name is ssa_<reg>,
940+
where <reg> is the name of the register being assigned.
937941
"""
938942

939943
for (reg, locs) in rdeflocs.items():
@@ -980,7 +984,9 @@ def introduce_stack_variables(
980984
tgttypsize = tgttyp.index(self.bytesize_calculator)
981985
if tgttypsize > 0:
982986
arraysize = size // tgttypsize
983-
if arraysize > 0:
987+
if arraysize == 1:
988+
vtype = tgttyp
989+
if arraysize > 1:
984990
vtype = self.astree.mk_int_sized_array_type(
985991
tgttyp, arraysize)
986992
else:
@@ -989,8 +995,7 @@ def introduce_stack_variables(
989995
+ "%s does not fit in stack frame; "
990996
+ "adjusting stack buffer to size %d",
991997
str(offset), tgttypsize)
992-
vtype = self.astree.mk_int_sized_array_type(
993-
tgttyp, 1)
998+
vtype = tgttyp
994999

9951000
self.mk_stack_variable_lval(offset, vtype=vtype)
9961001

@@ -1080,6 +1085,17 @@ def mk_stack_variable_lval(
10801085
if varinfo.vtype is None:
10811086
return lval
10821087

1088+
if varinfo.vtype.is_compound:
1089+
structtyp = cast(AST.ASTTypComp, varinfo.vtype)
1090+
ckey = structtyp.compkey
1091+
compinfo = self.globalsymboltable.compinfo(ckey)
1092+
for (cfoff, fname) in sorted(compinfo.field_offsets.items()):
1093+
fieldoffset = self.mk_field_offset(fname, ckey)
1094+
fieldlval = self.astree.mk_vinfo_lval(
1095+
varinfo, offset=fieldoffset)
1096+
self.stack_variables[offset + cfoff] = fieldlval
1097+
return lval
1098+
10831099
if varinfo.vtype.is_array:
10841100
arraytyp = cast(AST.ASTTypArray, varinfo.vtype)
10851101
eltyp = arraytyp.tgttyp

chb/astinterface/ASTInterfaceFunction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ def mk_high_level_ast(
204204
+ self.address
205205
+ "):\n "
206206
+ str(e))
207+
chklogger.logger.error(
208+
"Unable to create high-level ast for %s (%s): %s",
209+
self.name,
210+
self.address,
211+
str(e))
207212
raise UF.CHBError(msg)
208213

209214
self.complete_instruction_connections()

0 commit comments

Comments
 (0)