Did anyone else ever have any thoughts on this issue? I ran across the same issue myself recently in a situation where the insertion of the unnecessary ops was a moderate inconvenience.
Ben On Mar 24, 2009, at 1:33 PM, Elnatan Reisner wrote: > In cabs2cil's doExp function, the case for &&, ||, and ! includes > comments saying that the results must be normalized to 0 or 1. Then, > in > the case where the expression is UnOp(LNot,_,_), there is a comment > saying that the result is already normalized. Isn't this also true for > binary operators that evaluate to boolean values? That is, couldn't we > replace line 3827 in cabs2cil.ml (revision 10610): > | CEExp (se, (UnOp(LNot, _, _) as e)) -> > with > | CEExp (se, ((UnOp(LNot, _, _)|BinOp((Eq|Ne|Le|Lt|Ge|Gt|LAnd| > LOr),_,_,_)) as e)) -> > > Right now, pattern matching falls through to the next case, causing > some > superfluous occurrences of '!= 0' to get inserted into code. For > example, this code > > int main() { > int x = 0; > return 1 && x == 4; > } > > gets transformed into > > int main(void) > { int x ; > { > x = 0; > return ((x == 4) != 0); > } > } > > This might not come up so often---it seems that this only happens when > an && or || has a constant value as an operand, or if you set CIL's > useLogicalOperators flag to true---but if it is simple to stop > generating unnecessary extra code, why not do it? > > Speaking of useLogicalOperators, here is a second question: > When useLogicalOperators is set to true, cabs2cil.ml's doCondExp > function keeps &&s and ||s (rather than transforming them to explicit > conditionals) if neither operand has side-effects. However, notice > that > the *first* operand will be evaluated regardless of whether short- > circuiting occurs; this means that we only need to check if the > *second* > operand has side-effects to see if we can keep the && or ||. This > means > we can change lines 4474-4478 in cabs2cil.ml: > > | CEExp(se1, e1'), CEExp (se2, e2') when > - !useLogicalOperators && isEmpty se1 && isEmpty se2 -> > - CEExp (empty, BinOp(LAnd, > + !useLogicalOperators && isEmpty se2 -> > + CEExp (se1, BinOp(LAnd, > makeCast e1' intType, > makeCast e2' intType, intType)) > > and similarly for the LOr case. > > Is my reasoning correct? Or is there a reason *not* to keep &&s and > ||s > in such cases? > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ CIL-users mailing list CIL-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cil-users