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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ed23aab45a548fd6,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-21 03:43:35 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!elnk-atl-nf1!newsfeed.earthlink.net!feed2.news.rcn.net!rcn!news-FFM2.ecrc.net!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Errornous String instantiation Date: Mon, 21 Jul 2003 10:43:35 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1058784215 19874 217.17.192.37 (21 Jul 2003 10:43:35 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Mon, 21 Jul 2003 10:43:35 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:40542 Date: 2003-07-21T10:43:35+00:00 List-Id: Sorry for posting this problem in such an early stage, but it's a moving target where small modifications of the source the problem cause to disappear. So I present a short (but not buggy) example of the source skeleton in question and show you some results of the real data. gcc (GCC) 3.2.2 ************************************************************************ package Constants is t1 : aliased constant String := "Test"; t2 : aliased constant String := "A longer test string"; end Constants; package Top is type Constant_String is access constant String; type Constant_String_Array is array(Positive range <>) of Constant_String; end Top; generic data : Constant_String_Array; package Top.Generic_Package is pragma Elaborate_Body; end Top.Generic_Package; with Ada.Text_IO; use Ada.Text_IO; package body Top.Generic_Package is begin for i in data'Range loop Put_Line("data (" & i'Img & " ) =" & data(i)'Length'Img); end loop; for i in data'Range loop Put_Line("data (" & i'Img & " ) =" & data(i)'Length'Img); end loop; end Top.Generic_Package; with Top.Generic_Package, Constants; use Constants; package MyPackage is new Top.Generic_Package((t1'Access, t2'Access)); with MyPackage; procedure Main is begin null; end Main; ************************************************************************ The expected result is: data ( 1 ) = 4 data ( 2 ) = 20 data ( 1 ) = 4 data ( 2 ) = 20 Doin this with the real program results in: Start Elaborating Testing Len 1 20 Testing Len 2 4 Testing Len 3 20 Testing Len 4 50 Testing Len 5 20 Testing Len 6 80 Testing Len 7 80 Testing Len 1 20 Testing Len 2 0 Testing Len 3 20 Testing Len 4 50 Testing Len 5 20 Testing Len 6 80 Testing Len 7 80 End Elaborating using the Source: Debugging.Hex_Dump(True, "", "Start Elaborating"); for i in keys'Range loop Debugging("Testing Len " & i'Img & keys(i)'Length'Img); end loop; for i in keys'Range loop Debugging("Testing Len " & i'Img & keys(i)'Length'Img); end loop; Debugging.Hex_Dump(True, "", "End Elaborating"); The excerpt from the ASM-Output look strange: .section .rodata .LC17: .ascii "Jefe" [...] movl $rfc2202__k1+8, -72(%ebp) movl $rfc2202__k1, -68(%ebp) movl $.LC17, -64(%ebp) movl $1, %eax movl $4, %edx movl %eax, -80(%ebp) movl %edx, -76(%ebp) leal -80(%ebp), %eax movl %eax, -60(%ebp) movl $rfc2202__k3+8, -56(%ebp) movl $rfc2202__k3, -52(%ebp) Where the referred constants come from: package RfC2202 is k1 : aliased constant String := (1 .. 20 => Character'Val(16#0b#)); d1 : aliased constant String := "Hi There"; sha1_1 : aliased constant Hex_String := "b6173186 55057264 e28bc0b6 fb378c8e f146be00"; md5_1 : aliased constant Hex_String := "9294727a 3638bb1c 13f48ef8 158bfc9d"; k2 : aliased constant String := "Jefe"; d2 : aliased constant String := "what do ya want for nothing?"; sha1_2 : aliased constant Hex_String := "effcdf6a e5eb2fa2 d27416d5 f184df9c 259a7c79"; md5_2 : aliased constant Hex_String := "750c783e 6ab0b503 eaa86e31 0a5db738"; [...] end RfC2202; .globl rfc2202__k1 .align 4 .type rfc2202__k1,@object .size rfc2202__k1,28 rfc2202__k1: .long 1 .long 20 .byte 11 [...] .byte 11 .globl rfc2202__d1 .data .align 4 .type rfc2202__d1,@object .size rfc2202__d1,16 rfc2202__d1: .long 1 .long 8 .ascii "Hi There" .globl rfc2202__sha1_1 .section .rodata .align 32 .type rfc2202__sha1_1,@object .size rfc2202__sha1_1,52 rfc2202__sha1_1: .long 1 .long 44 .ascii "b6173186 55057264 e28bc0b6 fb378c8e f146be00" .globl rfc2202__md5_1 .align 32 .type rfc2202__md5_1,@object .size rfc2202__md5_1,44 rfc2202__md5_1: .long 1 .long 35 .ascii "9294727a 3638bb1c 13f48ef8 158bfc9d" .zero 1 .globl rfc2202__k2 .data .align 4 .type rfc2202__k2,@object .size rfc2202__k2,12 rfc2202__k2: .long 1 .long 4 .ascii "Jefe" .globl rfc2202__d2 .section .rodata .align 32 .type rfc2202__d2,@object .size rfc2202__d2,36 rfc2202__d2: .long 1 .long 28 .ascii "what do ya want for nothing?" [...] It's interesting to note, that short string constants (<= 8 Characters) are deferred instantiated (not .rodata), while longer string constants are stored in the object file rfc2202.o. When constructing the array for the generic instantiation, the short constant string is instantiated directly without the bounds. Beside array with the bounds is constructed correctly on the stack (and then copied to an explicit data section), the constructing stack space is reused directly afterwards. That's why the bounds (which are stored indirectly) are destroyed later in the program. Did anybody came across this type of bug? Any idea how to solve the problem?