Skip to content

Fix renaming bug triggered by static locals hiding other locals/formals.#229

Open
difcsi wants to merge 1 commit into
goblint:developfrom
difcsi:fix-renaming-bug
Open

Fix renaming bug triggered by static locals hiding other locals/formals.#229
difcsi wants to merge 1 commit into
goblint:developfrom
difcsi:fix-renaming-bug

Conversation

@difcsi

@difcsi difcsi commented May 13, 2026

Copy link
Copy Markdown

Hi everyone,

I'm Zoltán, working with Stephen (#228) on some CIL-related things. Besides the architectural changes, we have some bug fixes that we are keen to contribute to your efforts.

When a static local is promoted to a global, the alpha renaming usually remembers any suffix added and chooses a fresh suffix for later vars of the same name. However, if the same function also has a (non-static) local with the same name, this gets clobbered: the alpha renamer throws away the renaming state after the function scope is done. This can be triggered if (among other cases) two functions in the same file both have like-named statics hiding other locals/formals (seen in Motif).

When a static local is promoted to a global, the alpha renaming usually
remembers any suffix added and chooses a fresh suffix for later vars of
the same name. However, if the same function also has a (non-static)
local with the same name, this gets clobbered: the alpha renamer throws
away the renaming state after the function scope is done. This can be
triggered if (among other cases) two functions in the same file both
have like-named statics hiding other locals/formals (seen in Motif).

Co-authored-by: Stephen Kell <srk31@srcf.ucam.org>
@sim642 sim642 added the bug label Jul 21, 2026
@sim642

sim642 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Fiddling with the alpha renaming scopes and undos can be quite risky.
There already is staticLocals tracking in CIL:

cil/src/frontc/cabs2cil.ml

Lines 5970 to 5973 in b750f58

(* However, we have a problem if a real global appears later with the
name that we have happened to choose for this one. Remember these names
for later. *)
H.add staticLocals vi.vname vi;

cil/src/frontc/cabs2cil.ml

Lines 540 to 544 in b750f58

(* Perhaps this is because we have seen a static local which happened
to get the name that we later want to use for a global. *)
try
let static_local_vi = H.find staticLocals vi.vname in
H.remove staticLocals vi.vname;

I wonder if that could be reused also for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants