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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f891f,eac70c5fad02d925 X-Google-Attributes: gidf891f,public X-Google-Thread: 103376,eac70c5fad02d925 X-Google-Attributes: gid103376,public From: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: Concerning subscript bounds checks Date: 1996/06/21 Message-ID: #1/1 X-Deja-AN: 161531851 references: <4qdj3e$btf@goanna.cs.rmit.EDU.AU> organization: Courant Institute of Mathematical Sciences keywords: subscripts newsgroups: comp.lang.ada,comp.lang.misc Date: 1996-06-21T00:00:00+00:00 List-Id: Richard said "The remaining 4 occur in this context: subtype Simplex_Range is Natural range 0 .. Point'Length; P: "array (Simplex_Range) of ..." Y: "array (Simplex_Range) of ..." X: Point; J: Simplex_Range; ... J := 0; -- at the start, J = Simplex_Range'First for I in X'Range loop ... P(J) := ... Y(J) := ... J := J + 1; end loop; -- at the end, J = Simplex_Range'Last P(J) := ... Y(J) := ... end; A reasonably smart compiler should be able to tell that these four subscripts are also safe. " I suspect this judgment is based on informal reasoning ("well it is pretty obvious to me that it can be figured out"). As always compiler optimizations, particularly range analysis are always more complicated than they appear from simple examples. Yes, a compiler could figure this out, but "reasonably smart" is probably an underestimate. I would be surprised if many existing compilers can figure even this particular one out. P.S. GNAT has not even started to think about optimizing checks yet, you get junk checks even in simple loops. It's something we plan to start work on soon!