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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!decvax!ucbvax!TECHMAX.BITNET!TENE From: TENE@TECHMAX.BITNET Newsgroups: comp.lang.ada Subject: ACCVIO in VMS ADA - not a bug. Message-ID: <8801141318.AA24459@ajpo.sei.cmu.edu> Date: 14 Jan 88 13:17:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet List-Id: In reply to: >Does anyone else think the program is erroneous? > > with UNCHECKED_DEALLOCATION; > with TEXT_IO; > procedure G_ADA_BUG is > type ACCESS_STRING is access STRING; > procedure DISPOSE is new UNCHECKED_DEALLOCATION (STRING, ACCESS_STRING); > A: ACCESS_STRING := new STRING'("Ceci est un exemple..."); > B: constant STRING := A.all; > begin -- G_ADA_BUG > TEXT_IO.PUT_LINE (A.all); > TEXT_IO.PUT_LINE (B); > DISPOSE (A); > TEXT_IO.PUT_LINE (B); > end G_ADA_BUG; >In my opinion, the program is not erroneous and the compiler is buggy. >There is no aliasing in the source code. The line > B : constant STRING := A.all >specifically requests a copy of the string from the object designated >by A into the local constant object B. For the compiler to share the >actual string is illegitimate. (In general, it is not a correct program >transformation to alias two objects of different and overlapping extent) > Your program inculdes the basic ingredients for making the program erroneous with a work-around (using the assignment to a constant) that would resolve the problem ONLY IF no optimization is done. This is not the only case where optimizers change the meaning of a program. the following expressions can also change meaning when an optimizer in applied to them. 1a. F(A) + A.all - Where the function F uses the Access variable - A (in only) to make a side effect on A.all 1b. G(A) + X - Where the function G changes the global - variable X. the optimizer may decide to activate the function F or G before or after evaluating A.all or X respectively. The ADA does not specify which way this is to be done, making programs that assume one way or the other errouneous. 2. B and F(X) - where B is a BOOLEAN and F(X) a boolean function In this case many optimizers will use Short-circut forms to save the function call. Does ADA disallow using Short-circut forms implicitly? is this program erroneous? (I don't have the LRM here). 3. Many optimizers extract constant experssions out of loops. This may not have the same results if another task decides to change variables which at compile time seem to stay constant on a sequential machine. In VMS (all programming languages) the concept of AST rentrancy is defined and if you want results to be consistent you must use ASTs correctly and write AST-reentrant routines (see VMS documentation). Other ADA compilers may ignore this but they can't SOLVE it. I think that the optimizer must be allowed some room to work. The above examples should be erroneous. I'm not sure what the book says, I wouldn't write programs using these methods in any language. An optimizer by definition will rearrange your program in a way different from the way you wrote it with the purpose of improving efficiency. This must mean some relaxation in consistency requirements even with the same compiler on the same machine. If you want optimization (which is not the default in VMS ADA) you must pay by being more careful with erroneous (or nearly erroneous) programs or allowing some variation in the results when you don't care what happens. I think that expectating the results of an optimized compilation to be the SAME as those of the non optimized one for erroneous or programs (or bad programs on the edge) is ridiculus. There is one BIG difference - execution time, for that you must pay. Taking this to an extreme you must notice that using optimization qualifiers you can remove requirements like index bound checking on arrays which are clearly required in the language. A program compiled with a NOCHECK qualifier (or its equivalent on other compilers) clearly is not legaly compiled. I still want this option to be available, (even though it should be used with care and only when the saving justifies the risk). For the same reasons I am glad that the VMS optimizer is smart enough to do the implied aliasing between B and A.all in your program. If you insist on working like this instead of rewriting your program correctly you can always use a NOOPTIMIZE pragma to get what you want. "This is NOT a bug its an option". you don't have to use it !!! Noam Tene System manager Bio-Medical Engineering Technion, Haifa, Israel tene@techmax.bitnnet