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!attcan!uunet!husc6!bloom-beacon!mit-eddie!bbn!rochester!pt.cs.cmu.edu!sei!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.lang.ada Subject: Re: BUG in Ada compiler? Keywords: bug, Ada, VAX, compiler Message-ID: <7693@aw.sei.cmu.edu> Date: 14 Nov 88 13:07:47 GMT References: <781@wsccs.UUCP> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu (Robert Firth) Organization: Carnegie-Mellon University, SEI, Pgh, Pa List-Id: In article <781@wsccs.UUCP> rargyle@wsccs.UUCP (Bob Argyle) writes: >The following program on a VAX 8700 prints out: >"Hello, your program is exceptional!" >but if I change either 32767 to 32768, it runs fine: "Hello, World" >Two questions: 1. Am I overlooking something very basic? Or, >2. Is the compiler here broken? Is _yours_? > >with text_io; use text_io; >procedure bug is > m:array (0..32767,0..32767) of character; > begin > m(0,8) := 'c'; > put("Hello, "); > m(1,8) := 'c'; [at which point the exception occurs] The program is legal (though certainly exceptional), and so one suspects that the compiler has a bug here. Wild conjecture: as shown, the array M has an index type that is implicitly WORD, ie 16 bits. The compiler expands the two-dimensional array index expression by the multiplicative method into (mbase + index1 * stride + index2) Because the indices are considered to be of type word, the compiler resolves the "*" and "+" operations to be also of type word, ie 16 bits. This works by sheer chance for the first expression, which stays within 16-bit range, but blows up on the second expression. If the upper bounds are changed to 32768 the index type becomes implicitly longword, which works. Source of problem: the premature expansion of the array index expression before overload resolution, followed by application of Ada's resolution rules to an expression that isn't in Ada and shouldn't follow those rules. Hope that helps - remember: a wild conjecture, no more.