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? ------------------------------------------------------------------------------ Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________ CIL-users mailing list CIL-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cil-users