Can analysis detect undefined expressions?

Thomas M. Breuel tmb at ai.mit.edu
Wed Jun 19 14:07:32 AEST 1991


In article <14394 at dog.ee.lbl.gov> torek at elf.ee.lbl.gov (Chris Torek) writes:
   >>From: ckp at grebyn.com (Checkpoint Technologies)
   >>I'd like to know if there has been any attempt to diagnose such undefined
   >>expressions.  It seems like an exceedingly difficult thing to do ...

   In article <14206.285B7688 at stjhmc.fidonet.org>
   Dave.Harris at f14.n15.z1.fidonet.org (Dave Harris) writes:
   >On the whole, I would say it is NOT possible to contend with every case.

   Indeed, it is fairly easy to show that no compiler can diagnose all
   misuses correctly.

However, a compiler can do better than just detecting problems
with builtins:

(1) it can warn about all potential dependencies on order of
    evaluation. To be useful it requires that all functions
    without side effects are declared as such (see GNU CC/C++):

Thus, this fragment should not generate a warning:

    const double sin(double);

	sin(x)+sin(x)*sin(x)

On the other hand, this fragment should:

    double sin(double);
    ...
	sin(x)+sin(x)*sin(x)

    >>> Warning: potential dependency on order of evaluation

(2) it can generate code to run several versions of the program
    with different orders of evaluation in parallel and detect
    differences in their execution

					Thomas.



More information about the Comp.lang.c mailing list