From: Matt H. <ma...@cs...> - 2006-08-18 21:05:07
|
Hi Chris, 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. Note that if the second declaration had an explicit initializer, then cabs2cil wouldn't delete it. Is this translation ever wrong? 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. But are you sure it matters whether a declaration uses extern or not? Cheers, Matt Christoph Spiel wrote: > Hi All! > > We would like to run an analysis that relies > on the declaration and definition points of > variables. However, CIL simplifies the code by > replacing the first declaration with a > definition and droping all later declarations or > definitions. There is no way to switch off this > "feature". > > For example > extern int i; > > int i; > > void > f(void) > { > i = 1; > } > > becomes > /* Generated by CIL v. 1.3.5 */ > /* print_CIL_Input is true */ > > #line 1 "def-vs-decl.c" > int i ; > #line 5 "def-vs-decl.c" > void f(void) > { > > { > #line 8 > i = 1; > #line 9 > return; > } > } > > whereas we would prefer > #line 1 "def-vs-decl.c" > extern int i ; > #line 3 "def-vs-decl.c" > int i ; > #line 5 "def-vs-decl.c" > void f(void) > { > > { > #line 8 > i = 1; > #line 9 > return; > } > } > > We did wade through the sources, however we > could not spot the piece of code that is > respsonsible for this simplification. Can > anyone please point us to the relevant > function[s]? > > > TIA, > Chris > > -- > Dr. Christoph L. Spiel > BMW Forschungs- und Innovationszentrum, EA-410 > Lauchstaedter Strasse 5, 80995 Muenchen > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > CIL-users mailing list > CIL...@li... > https://lists.sourceforge.net/lists/listinfo/cil-users |