From a51d625ac5005c2b2f701396e2c75d82eb102e30 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 9 Apr 2018 20:57:19 +0200 Subject: Check for redefinition of globals and preserve static initialized variables (#81) * Added check for redefinition of globals. Since Cleanup may remove duplicated static functions or global definitions we need to check for duplication during elaboration, not just in C2C. Bug 23410 * Do not eliminate unreferenced static variables with initializers This way all initialized variables make it to the C2C pass, where the initializers are checked for constant-ness. Bug 23410 --- cparser/Cleanup.ml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'cparser/Cleanup.ml') diff --git a/cparser/Cleanup.ml b/cparser/Cleanup.ml index fe674d9b..75ee0e5a 100644 --- a/cparser/Cleanup.ml +++ b/cparser/Cleanup.ml @@ -118,11 +118,23 @@ let add_enum e = e (* Saturate the set of referenced identifiers, starting with externally - visible global declarations *) + visible global declarations. + + Externally-visible globals include a minima: + - Definitions of functions, unless "static" or "inline". + - Declaration of variables with default storage. + + We choose to also treat as visible and therefore to keep: + - "static" initialized variables, so that the checks on initializers + performed in C2C are performed on all initializers. + If the variable turns out to be unused, it will be removed + later by the Unusedglob pass. +*) let visible_decl (sto, id, ty, init) = - sto = Storage_default && - match ty with TFun _ -> false | _ -> true + init <> None || + (sto = Storage_default && + match ty with TFun _ -> false | _ -> true) let visible_fundef f = match f.fd_storage with -- cgit