[LLVMdev] Advice on CFG pre-analysis
Joachim Durchholz
jo at durchholz.org
Wed May 28 02:12:54 PDT 2008
Am Dienstag, den 27.05.2008, 20:41 -0700 schrieb Chris Lattner:
> On May 27, 2008, at 1:57 PM, Mike Stump wrote:
>
> > On May 23, 2008, at 11:53 PM, Talin wrote:
> >> In the language I am working on, there are cases where the call flow
> >> graph can affect the type of a variable.
> >
> > :-)
> >
> > This reminds me of people that want to use CFG and the optimizer to
> > make:
> >
> > int i; int() { if (i) return 1; else return 0; }
> >
> > not warn/error that flow falls off the end.
Java does exactly this.
> > Extend that out and you have to do arbitrarily hard things and the
> > document the limit of what was done, which is messy and wrong
Correct in general, but not an issue if you draw a clear line.
In Java's case, the line is that the inference uses just structural
control flow information.
This is clearly spelled out in the language reference.
> [...] any
> compiler that emits a false positive for that would be pretty useless
> in practice.
I'd agree that such a language is more restrictive than necessary, but I
wouldn't say it is useless.
You can always rewrite examples like the above as
int result;
if (i) result = 1; else result = 0;
return result;
If the resulting ugliness is a factor, the computation can be moved to a
function and we get
return int_to_01 (i)
which even gives us an opportunity to name that piece of code.
(Returns that are buried in multiple levels of nesting aren't too
beautiful either...)
Regards,
Jo
More information about the llvm-dev
mailing list