From: Christoph S. <Chr...@pa...> - 2006-08-21 12:50:02
|
Matt - THX for helping me out. > In C, "int i;" and "extern int i;" are both just > declarations. Extern linkage is a property of the global variable, > not any particular declaration, so CIL puts the linkage in the > varinfo structure (vstorage). The result of parsing > > extern int i; > ... > int i; > > into CIL would be > > GVarDecl(i) > ... > GVarDecl(i) > > where i has no storage specifier, since the NoStorage version > overrides the Extern. The second declaration is redundant, > however, so cabs2cil ignores it. So we get > > int i; > ... > > like you said. I wish we had GVarDecl(i) ... GVar(i) instead of the above and CIL would keep both. > Note that if the second declaration had an explicit initializer, > then cabs2cil wouldn't delete it. Is this translation ever wrong? Semantically the translation look correct to me. > As for your analysis that needs to know about every declaration: One > thing you can do is modify createGlobal in cabs2cil.ml, which says > if not alreadyInEnv then begin (* Only one declaration *) > cabsPushGlobal (GVarDecl (vi, !currentLoc)); > vi > end > > Removing the conditional will add a GVarDecl even for redundant > declarations. It would be harder to make a distinction between > declarations with different storage modifiers, since those are > stored in the varinfo. You could have createGlobal call back into > your analysis to announce that a variable was declared with storage > X at location Y. To be honest, I hate to change the inner workings of CIL. We have already discussed some alternatives here (e.g. pragmas before each definition/declaration of interest). > But are you sure it matters whether a declaration uses extern or > not? For the particular kind of analysis we have in mind, yes, it does matter: We want to distinguish between modules that define variables, this is, do not use "extern" ("producer" modules allocating memory) and those which "consume" variables from other modules by using "extern" declarations and not allocating memory. As we have lots of global variables this type of analysis helps us to improve on the software's architecture. Best, Chris -- Dr. Christoph L. Spiel BMW Forschungs- und Innovationszentrum, EA-410 Lauchstaedter Strasse 5, 80995 Muenchen |