diff --git a/src/kernel_internals/typing/cabs2cil.ml b/src/kernel_internals/typing/cabs2cil.ml index 7f5b53a7cd886e40910c5a6f71ce238aa23bd5d7..b66c18cb4e11215d2f3100da039d73a0f03610f7 100644 --- a/src/kernel_internals/typing/cabs2cil.ml +++ b/src/kernel_internals/typing/cabs2cil.ml @@ -1628,13 +1628,26 @@ struct (fun (stmt, _, _, _, _) -> ignore (Cil.visitCilStmt vis stmt)) c.stmts - (* if we're about to drop a chunk, clean up locals of current func. *) - let clean_up_chunk_locals c = + let remove_locals l = !currentFunctionFDEC.slocals <- List.filter - (fun x -> not (List.exists (Cil_datatype.Varinfo.equal x) c.locals)) + (fun x -> not (List.exists (Cil_datatype.Varinfo.equal x) l)) !currentFunctionFDEC.slocals + let clean_up_block_locals (s, _, _, _, _) = + let vis = + object + inherit Cil.nopCilVisitor + method! vblock b = remove_locals b.blocals; DoChildren + end + in + ignore (Cil.visitCilStmt vis s) + + (* if we're about to drop a chunk, clean up locals of current func. *) + let clean_up_chunk_locals c = + remove_locals c.locals; + List.iter clean_up_block_locals c.stmts + (* Gathers locals of blocks. *) class locals_visitor () = object inherit Cil.nopCilVisitor diff --git a/tests/syntax/local-variable.i b/tests/syntax/local-variable.i index 52067d1dcec47c9a1f0bfe03d2bd47f268a401a3..6e6d1b453d0de500811cd8693c15c71852a63760 100644 --- a/tests/syntax/local-variable.i +++ b/tests/syntax/local-variable.i @@ -10,3 +10,6 @@ void f() { int b; } } + +int c; +int g() { return 1 || (-1L || g(), c); } diff --git a/tests/syntax/oracle/local-variable.res.oracle b/tests/syntax/oracle/local-variable.res.oracle index e7cfa00d9cd4d059da7232a5b942bdd99766ab1e..13981c134682d221a2d6407b578817971306095c 100644 --- a/tests/syntax/oracle/local-variable.res.oracle +++ b/tests/syntax/oracle/local-variable.res.oracle @@ -16,4 +16,12 @@ void f(void) return; } +int c; +int g(void) +{ + int __retres; + __retres = 1; + return __retres; +} +