Skip to content

Commit 4d28fea

Browse files
committed
APP: handle static initializers with local var refs
1 parent 6972386 commit 4d28fea

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

chc/app/CDictionary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def index_lval(
711711
self, lval: CLval, subst: Dict[int, CExp] = {}, fid: int = -1) -> int:
712712
args: List[int] = [
713713
self.index_lhost(lval.lhost, subst=subst, fid=fid),
714-
self.index_offset(lval.offset)]
714+
self.index_offset(lval.offset, fid=fid)]
715715
return self.mk_lval_index(lval.tags, args)
716716

717717
def index_offset(self, o: COffset, fid: int = -1) -> int:

chc/app/CFileGlobals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,12 @@ def global_varinfo_names(self) -> Dict[str, "CVarInfo"]:
370370
def global_varinfo_vids(self) -> Dict[int, "CVarInfo"]:
371371
if self._globalvarinfovids is None:
372372
self._globalvarinfovids = {}
373+
for (vid, gfun) in self.gfunctions.items():
374+
self._globalvarinfovids[vid] = gfun.varinfo
373375
for (vid, vardef) in self.gvardefs.items():
374376
self._globalvarinfovids[vid] = vardef.varinfo
375377
for (vid, vardecl) in self.gvardecls.items():
376378
self._globalvarinfovids[vid] = vardecl.varinfo
377-
for (vid, gfun) in self.gfunctions.items():
378-
self._globalvarinfovids[vid] = gfun.varinfo
379379
return self._globalvarinfovids
380380

381381
def get_global_varinfos(self) -> List["CVarInfo"]:

chc/app/CGlobalDeclarations.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,15 @@ def index_init(self, init: CInitInfo, fid: int = -1) -> int:
585585

586586
if init.is_single:
587587
init = cast("CSingleInitInfo", init)
588-
args = [self.dictionary.index_exp(init.exp)]
588+
args = [self.dictionary.index_exp(init.exp, fid=fid)]
589589
return self.mk_single_init_index(init.tags, args)
590590

591591
if init.is_compound:
592592
init = cast("CCompoundInitInfo", init)
593593
gtype = self.dictionary.index_typ(init.typ)
594594
oinits: List[int] = [
595-
self.index_offset_init(x) for x in init.offset_initializers]
595+
self.index_offset_init(x, fid=fid)
596+
for x in init.offset_initializers]
596597
args = [gtype] + oinits
597598
return self.mk_compound_init_index(init.tags, args)
598599

@@ -601,8 +602,8 @@ def index_init(self, init: CInitInfo, fid: int = -1) -> int:
601602

602603
def index_offset_init(self, oinit: COffsetInitInfo, fid: int = -1) -> int:
603604
args: List[int] = [
604-
self.dictionary.index_offset(oinit.offset),
605-
self.index_init(oinit.initializer)]
605+
self.dictionary.index_offset(oinit.offset, fid=fid),
606+
self.index_init(oinit.initializer, fid=fid)]
606607
return self.mk_offset_init_index(oinit.tags, args)
607608

608609
def index_varinfo_vid(self, varref: VarReference) -> Optional[int]:
@@ -631,7 +632,19 @@ def make_global_varinfo(self, fid: int, varinfo: CVarInfo) -> None:
631632
vtype = self.dictionary.get_typ(vtypeix)
632633
if varinfo.has_initializer():
633634
vinit = varinfo.initializer
634-
gvinit = [self.index_init(vinit, fid=fid)]
635+
try:
636+
gvinit = [self.index_init(vinit, fid=fid)]
637+
except UF.CHError as e:
638+
chklogger.logger.warning(
639+
("Global variable initializer for %s "
640+
+ "(vid: %d, line: %s, fid: %d) "
641+
+ " could not be indexed: %s"),
642+
varinfo.vname,
643+
varinfo.vid,
644+
(varinfo.vdecl.line if varinfo.vdecl is not None else -1),
645+
fid,
646+
str(e))
647+
gvinit = []
635648
else:
636649
gvinit = []
637650
tags = [vname]
@@ -669,6 +682,15 @@ def f(index: int, tags: List[str], args: List[int]) -> CVarInfo:
669682
gvarinfo.vname)
670683

671684
def index_file_varinfos(self, fid: int, varinfos: List[CVarInfo]) -> None:
685+
chklogger.logger.debug(
686+
"Index %d file varinfos for fid: %d (%s)",
687+
len(varinfos), fid,
688+
", ".join(v.vname
689+
+ "("
690+
+ str(v.vid)
691+
+ ", line: "
692+
+ str(v.line if v.vdecl is not None else "?")
693+
+ ")" for v in varinfos))
672694
if len(varinfos) > 0:
673695
self.vid2gvid[fid] = {}
674696
for v in varinfos:

chc/app/CGlobalDictionary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def capp(self) -> "CApplication":
7373
def decls(self) -> "CGlobalDeclarations":
7474
return self.capp.declarations
7575

76-
def index_compinfo_key(self, compinfo, fid):
76+
def index_compinfo_key(self, compinfo, fid) -> int:
7777
chklogger.logger.info(
7878
"Index compinfo key %s for fid %d", compinfo.name, fid)
7979
return self.decls.index_compinfo_key(compinfo, fid)

0 commit comments

Comments
 (0)