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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: GNAT: Why does a large 'new' allocation blow the stack when an initialiser is present ? Date: Fri, 01 Nov 2013 08:45:51 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="feb3f5761668d64af19c3661aa3d3ca4"; logging-data="29217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aC5swm08wi1yOP8iD6ePQTFzeG+L0CMk=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:lf5rWrWAq16e/zbpFaOlWNK/1Ws= sha1:8g1KuFshgMTi4x/CzYtGJoyoie4= Xref: news.eternal-september.org comp.lang.ada:17572 Date: 2013-11-01T08:45:51+00:00 List-Id: Rod Kay writes: > Hi all, > > Is this a bug ? > > procedure bug_Test > is > type Integer_array is array (Integer range <>) of Integer; > > the_Array_1 : access Integer_array > := new Integer_array (1 .. 10_000_000); -- Fine. > > the_Array_2 : access Integer_array > := new Integer_array' (1 .. 10_000_000 => <>); -- Stack overflow. > > begin > null; > end; > > It seems that, with the initialiser, GNAT is creating the array on > the stack before copying it to the final heap memory ? Not sure precisely what the bug is, but something odd is going on. This is on a Mac with GNAT GPL 2013. The stack overflow occurs with an array length 2**21 but not 2**20. The traceback shows it happening at the start of the procedure (line "procedure bug_Test"). I put the declarations into their own declare blocks with Put_Lines, and the first never got executed. I'm not sure what "=> <>" is expected to do when there's no default value; I added "with Default_Component_Value => 42" to Integer_Array, and The_Array_1 (0) was 42 but The_Array_2 (1) was unchanged at 0!