From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!cornell!rochester!pt.cs.cmu.edu!sei!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.lang.ada Subject: Re: over ambitious optimizers Message-ID: <6023@aw.sei.cmu.edu> Date: 24 Jun 88 21:22:17 GMT References: <8806241657.AA23329@ti.com> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (Robert Firth) Organization: Carnegie-Mellon University, SEI, Pgh, Pa List-Id: In article <8806241657.AA23329@ti.com> linnig@skvax1.csc.ti.COM (Mike Linnig) writes: Folks, I compiled the following procedure and discovered that the validated compiler I was using had optimized away the first assignment of I. I was really testing something else, but should it have deleted that assignemnt? I can imagine that the function SOMEINT actually used the value of I in it's calculation (it would be in the scope of I). Is this an over ambitious optimizer? Mike Linnig, Texas Instruments ---------------------------------------------------------------------- PROCEDURE leftside(i: IN OUT integer) IS TYPE myarray IS ARRAY(integer RANGE 1..15) OF integer; anarray: myarray; FUNCTION someint RETURN integer IS SEPARATE; BEGIN I := 5; -- OPTIMIZED AWAY ! anarray(someint) := 3; i := 7; END; The optimisation is indeed incorrect. The function SOMEINT, whose body is unknown, can legally access the (non-local) variable I, as you state, and such access should yield the value 5. This is not an illegal alias, since the access would use the simple name "I", as declared in the header of LEFTSIDE. If the compiler is the one I suspect, the error is in the phase that performs liveness analysis of variables. It does not recognise that a call of a subprogram whose body is in the scope of the variable is a potential access path to the variable.