Skip to content

Commit 44f156c

Browse files
Add attribute goblint_cil_nested to local varinfos that are not declared at top scope (#155)
1 parent 70a4198 commit 44f156c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/frontc/cabs2cil.ml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ let nocil: int ref = ref (-1)
7575
*)
7676
let alwaysGenerateVarDecl = false
7777

78+
(** Add an attribute to all variables which are not declared at the top scope,
79+
so tools building on CIL can know which variables were pulled up.
80+
Should be disabled when printing CIL code, as compilers will warn about this attribute.
81+
*)
82+
let addNestedScopeAttr = ref false
83+
7884
(** Indicates whether we're allowed to duplicate small chunks. *)
7985
let allowDuplication: bool ref = ref true
8086

@@ -557,9 +563,19 @@ let alphaConvertVarAndAddToEnv (addtoenv: bool) (vi: varinfo) : varinfo =
557563
in
558564
(* Store all locals in the slocals (in reversed order). We'll reverse them
559565
and take out the formals at the end of the function *)
560-
if not vi.vglob then
561-
!currentFunctionFDEC.slocals <- newvi :: !currentFunctionFDEC.slocals;
562-
566+
if not vi.vglob then (
567+
(if !addNestedScopeAttr then
568+
(* two scopes implies top-level scope in the function, one is created for the FUNDEF (includes formals etc),
569+
one for the body which is a block *)
570+
match !scopes with
571+
| _::_::_::_ ->
572+
(* i.e. List.length scopes > 2 *)
573+
newvi.vattr <- Attr("goblint_cil_nested", []) :: newvi.vattr
574+
| _ -> ()
575+
);
576+
!currentFunctionFDEC.slocals <- newvi :: !currentFunctionFDEC.slocals
577+
)
578+
;
563579
(if addtoenv then
564580
if vi.vglob then
565581
addGlobalToEnv vi.vname (EnvVar newvi)

src/frontc/cabs2cil.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ val forceRLArgEval: bool ref
4545
-1 to disable *)
4646
val nocil: int ref
4747

48+
(** Add an attribute to all variables which are not declared at the top scope,
49+
so tools building on CIL can know which variables were pulled up.
50+
Should be disabled when printing CIL code, as compilers will warn about this attribute.
51+
*)
52+
val addNestedScopeAttr: bool ref
53+
4854
(** Indicates whether we're allowed to duplicate small chunks of code. *)
4955
val allowDuplication: bool ref
5056

0 commit comments

Comments
 (0)