From: Nathan C. <co...@cs...> - 2005-09-29 16:00:06
|
The constant folder in CIL only folds over the bitwise and operation when both operands are constant. Otherwise, it leaves the expression alone. There are a couple of places (such as here and multiplying by zero) when the constant folder is sound but not maximally precise. My guess is that if you add a line in constFoldBinOp to handle bitwise and-ing with zero, then you will get the desired behavior. In other words, the conditional expression will get folded to 0 and then the partial evaluation will remove the if statement. In answer to your other quesion about who is working on this kind of stuff: I am working on an interprocedural dataflow analyzer in CIL that includes a constant propagator. It will be released in the not too distant future, but you can get an early version directly from me if you want. Nathan Shahar Golan wrote: > *Hello,* > ** > *I'm trying the following code with cil:* > > *int main() { > volatile int i;* > > * if (0 & i) > return i; > else > return 0; > } * > > *And this is what I get:* > > *int main(void) > { int volatile i ;* > > * { > if (0 & (int )i) { > return ((int )i); > } else { > return (0); > } > } > } * > > *S H A H A R > TOOLS GROUP LEADER > TEL +972 (9) 7766336 * *G O L A N > SOFTIER IL LTD > EXT 8940 * > *Needless to say that I would expect:* > > * > *int main(void) > { int volatile i ;* > > * { > return (0); > } > } > }* > * > > *BTW, "--domakeCFG --dopartial" don't do the trick.* > * > ** > *Is anyone doing any work on improving the constant folding mechanism, > or should I?* > ** > *Anyone sees any reason why I shouldn't have expected the dead code > removal?* > * > ** > > ** |