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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.171.72 with SMTP id g8mr484437qaz.7.1376615883849; Thu, 15 Aug 2013 18:18:03 -0700 (PDT) X-Received: by 10.50.124.66 with SMTP id mg2mr307131igb.16.1376615883615; Thu, 15 Aug 2013 18:18:03 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.bbs-scene.org!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!f7no2515779qan.0!news-out.google.com!he10ni2163qab.0!nntp.google.com!fx3no2641390qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 15 Aug 2013 18:18:03 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=59.16.25.168; posting-account=AHt6zAoAAABQOfQrPx9x4er-wkJ_JuMM NNTP-Posting-Host: 59.16.25.168 References: <9de9c3bf-c4c5-466f-a8cd-fca992daecbe@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9052bbd2-a4b4-482e-a362-f717370d9463@googlegroups.com> Subject: Re: GNAT Allocation of a very large record From: Hyung-Hwan Chung Injection-Date: Fri, 16 Aug 2013 01:18:03 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:16885 Date: 2013-08-15T18:18:03-07:00 List-Id: On Thursday, August 15, 2013 11:27:41 PM UTC+9, Robert A Duff wrote: > > > Anyway, when the upper bound is set to Storage_Count'Last, > > Pointer_Object_Record'Max_Size_In_Storage_Elements and > > Pointer_Object_Record'Size seem to wrap around to an undesired value > > Do you have overflow checks enabled (-gnato)? > > - Bob Yes, I did. That didn't make any difference. GNAT, however, is able to detect it if a predictable size is in play. The following raises the Storage_Error exception with the message "object too large". No compile time warning is given. ---- begin ObjPtr := new Object_Record'( Kind => Pointer_Object, Size => Pointer_Object_Size'Last, Flags => 0, Extra => 0, Unit => 0, Class => null, Pointer_Slot => (others=>null) ); ---- end X1; The following raises the CONSTRAINT_ERROR exception. A compile-time warning is also issued - "warning: "Constraint_Error" will be raised at run time". ---- subtype Dummy_Object_Record is Object_Record (Pointer_Object, Pointer_Object_Size'Last); begin Ada.Text_IO.Put_Line (Storage_Count'Image(Dummy_Object_Record'Max_Size_In_Storage_Elements)); ---- end X1; In my case, the type definition is rather dynamic as it uses the Size parameter passed to the function. I put this line in Alloc_Pointer_Object before 'Ptr := new Pointer_Object_Record'...'. Ada.Text_IO.Put_Line (Pointer_Object_Record'Max_Size_In_Storage_Elements'Img); and generated the assembly listing, of course with -gnato enabled. ---- call system__img_lli__image_long_long_integer movl %eax, %edx testl %edx, %edx movl %eax, %edx testl %edx, %edx movl %eax, %edx testl %edx, %edx leaq -160(%rbp), %rdx movq %rdx, -112(%rbp) movl $1, -96(%rbp) movl %eax, -92(%rbp) leaq -96(%rbp), %rax movq %rax, -104(%rbp) movq -112(%rbp), %rdx movq -104(%rbp), %rax movq %rdx, %rdi movq %rax, %rsi call ada__text_io__put_line__2 movq -808(%rbp), %rax salq $3, %rax addq $7, %rax andq $-8, %rax addq $7, %rax andq $-8, %rax addq $31, %rax andq $-8, %rax movq %rax, %rdi call __gnat_malloc ---- There is no call to the range check routines. GNAT seems to produce calls to __gnat_rcheck_XX when it performs the range check for normal cases. call __gnat_rcheck_00 call __gnat_rcheck_02 and so on. Cheers, Hyung-Hwan