comp.lang.ada
 help / color / mirror / Atom feed
* Errornous String instantiation
@ 2003-07-21 10:43 Lutz Donnerhacke
  2003-07-21 10:56 ` Preben Randhol
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Lutz Donnerhacke @ 2003-07-21 10:43 UTC (permalink / raw)


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
\f
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?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 10:43 Errornous String instantiation Lutz Donnerhacke
@ 2003-07-21 10:56 ` Preben Randhol
  2003-07-21 11:02   ` Lutz Donnerhacke
  2003-07-21 11:08   ` Florian Weimer
  2003-07-21 16:19 ` Matthew Heaney
  2003-07-23 14:03 ` Lutz Donnerhacke
  2 siblings, 2 replies; 12+ messages in thread
From: Preben Randhol @ 2003-07-21 10:56 UTC (permalink / raw)


Lutz Donnerhacke wrote:
> 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

You should consider upgrading to 3.3 (if you can)
-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 10:56 ` Preben Randhol
@ 2003-07-21 11:02   ` Lutz Donnerhacke
  2003-07-21 11:07     ` Preben Randhol
  2003-07-21 11:08   ` Florian Weimer
  1 sibling, 1 reply; 12+ messages in thread
From: Lutz Donnerhacke @ 2003-07-21 11:02 UTC (permalink / raw)


* Preben Randhol wrote:
> Lutz Donnerhacke wrote:
>> 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
>
> You should consider upgrading to 3.3 (if you can)

I can't (at least this month). :-/



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 11:02   ` Lutz Donnerhacke
@ 2003-07-21 11:07     ` Preben Randhol
  2003-07-21 12:35       ` Lutz Donnerhacke
  0 siblings, 1 reply; 12+ messages in thread
From: Preben Randhol @ 2003-07-21 11:07 UTC (permalink / raw)


Lutz Donnerhacke wrote:
> 
> I can't (at least this month). :-/

Do you have a sample program so I can just gnatchop and run gnatmake I
can test it for you one gcc 3.3 if you like.

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 10:56 ` Preben Randhol
  2003-07-21 11:02   ` Lutz Donnerhacke
@ 2003-07-21 11:08   ` Florian Weimer
  2003-07-21 11:17     ` Preben Randhol
  1 sibling, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2003-07-21 11:08 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> writes:

>> gcc (GCC) 3.2.2
>
> You should consider upgrading to 3.3 (if you can)

Hmm, when was 3.2 branched from mainline?  After the last significant
update of the Ada front end in February 2002?

The safest bet right now (apart from using 3.15p 8-) is to take the
3.2 branch from the FSF CVS and use the Ada front end from the ACT
CVS.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 11:08   ` Florian Weimer
@ 2003-07-21 11:17     ` Preben Randhol
  0 siblings, 0 replies; 12+ messages in thread
From: Preben Randhol @ 2003-07-21 11:17 UTC (permalink / raw)


Florian Weimer wrote:
> The safest bet right now (apart from using 3.15p 8-) is to take the
> 3.2 branch from the FSF CVS and use the Ada front end from the ACT
> CVS.

But if you don't do that the 3.3 has fewer bugs than 3.2 as I have
noticed.

-- 
Ada95 is good for you.
http://www.crystalcode.com/codemage/MainMenu/Coding/Ada/IntroducingAda.php



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 11:07     ` Preben Randhol
@ 2003-07-21 12:35       ` Lutz Donnerhacke
  2003-07-21 12:55         ` Lutz Donnerhacke
  0 siblings, 1 reply; 12+ messages in thread
From: Lutz Donnerhacke @ 2003-07-21 12:35 UTC (permalink / raw)


* Preben Randhol wrote:
> Do you have a sample program so I can just gnatchop and run gnatmake I
> can test it for you one gcc 3.3 if you like.

[private test under way, expect reports soon]

Tests with optimization (-O2) shows, that the bound data is destroyed before
any access can be made.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 12:35       ` Lutz Donnerhacke
@ 2003-07-21 12:55         ` Lutz Donnerhacke
  2003-07-21 21:54           ` Adrian Knoth
  0 siblings, 1 reply; 12+ messages in thread
From: Lutz Donnerhacke @ 2003-07-21 12:55 UTC (permalink / raw)


* Lutz Donnerhacke wrote:
> * Preben Randhol wrote:
>> Do you have a sample program so I can just gnatchop and run gnatmake I
>> can test it for you one gcc 3.3 if you like.
> 
> [private test under way, expect reports soon]

gcc 3.3  -O0:
  Start Elaborating 
  Testing Len 1 20 
  Testing Len 2 4 
  Testing Len 3 20 
  Testing Len 4 25 
  Testing Len 5 20 
  Testing Len 6 80 
  Testing Len 7 1   <-- Wrong: "k7 : String renames k6;"
  Testing Len 1 20 
  Testing Len 2 112 <-- Modified bounds as described in the top posting 
  Testing Len 3 20 
  Testing Len 4 25 
  Testing Len 5 20 
  Testing Len 6 80 
  Testing Len 7 1   <-- Wrong: "k7 : String renames k6;"

gcc 3.3  -O2:
  Start Elaborating   
  Testing Len 1 20   
  Testing Len 2 0   <-- Modified bounds before first access
  Testing Len 3 20   
  Testing Len 4 25   
  Testing Len 5 20   
  Testing Len 6 80   
  Testing Len 7 1   <--
  Testing Len 1 20   
  Testing Len 2 0   <--
  Testing Len 3 20   
  Testing Len 4 25   
  Testing Len 5 20   
  Testing Len 6 80   
  Testing Len 7 1   <--

Gnat 3.14p -O0 and -O2:
  Testing Len 1 20   
  Testing Len 2 4   
  Testing Len 3 20   
  Testing Len 4 25   
  Testing Len 5 20   
  Testing Len 6 80   
  Testing Len 7 1   <-- Wrong: "k7 : String renames k6;"
  Testing Len 1 20   
  Testing Len 2 4   
  Testing Len 3 20   
  Testing Len 4 25   
  Testing Len 5 20   
  Testing Len 6 80   
  Testing Len 7 1   
  
Otherwise, it looks stable (besides it fails the regression tests).
Those tests are successful, when run after elaboration.


In order to ease debugging, I provide a snapshot of the program at:
  ftp://ftp.iks-jena.de/pub/mitarb/lutz/ada/compilerbug.tgz



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 10:43 Errornous String instantiation Lutz Donnerhacke
  2003-07-21 10:56 ` Preben Randhol
@ 2003-07-21 16:19 ` Matthew Heaney
  2003-07-21 16:26   ` Lutz Donnerhacke
  2003-07-23 14:03 ` Lutz Donnerhacke
  2 siblings, 1 reply; 12+ messages in thread
From: Matthew Heaney @ 2003-07-21 16:19 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> wrote in message news:<slrnbhnguj.oa.lutz@taranis.iks-jena.de>...

Have you tried using the categorization pragmas?


> package Constants is
     pragma Pure;  --or else Preelaborate;     

>    t1 : aliased constant String := "Test";
>    t2 : aliased constant String := "A longer test string";
> end Constants;
> 
> package Top is
     pragma Preelaborate;

>    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;

pragma Elaborate_All (Top.Generic_Package);
pragma Elaborate_All (Contants);

> 
> package MyPackage is new Top.Generic_Package((t1'Access, t2'Access));


> Did anybody came across this type of bug? Any idea how to solve the problem?

I don't know whether including the categorization pragmas will help
any, but it can't hurt.

Are you using GNAT?  Did you try the -gnatwl switch?

-Matt



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 16:19 ` Matthew Heaney
@ 2003-07-21 16:26   ` Lutz Donnerhacke
  0 siblings, 0 replies; 12+ messages in thread
From: Lutz Donnerhacke @ 2003-07-21 16:26 UTC (permalink / raw)


* Matthew Heaney wrote:
> Lutz Donnerhacke <lutz@iks-jena.de> wrote in message news:<slrnbhnguj.oa.lutz@taranis.iks-jena.de>...
> 
> Have you tried using the categorization pragmas?

Yes. Without success. It's really not an elaboration problem (witch I
assumed last week).

> I don't know whether including the categorization pragmas will help
> any, but it can't hurt.

Don't help.

> Are you using GNAT?  Did you try the -gnatwl switch?

I'm using gcc 3.2.2.
No, the problem is an instantiation bug in the compiler itself.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 12:55         ` Lutz Donnerhacke
@ 2003-07-21 21:54           ` Adrian Knoth
  0 siblings, 0 replies; 12+ messages in thread
From: Adrian Knoth @ 2003-07-21 21:54 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> wrote:

> In order to ease debugging, I provide a snapshot of the program at:
>   ftp://ftp.iks-jena.de/pub/mitarb/lutz/ada/compilerbug.tgz

gcc version 3.4 20030615 (experimental):

adi@drcomp:/tmp/ssh$ gnatmake -O2 test
gcc -c -O2 test.adb
gcc -c -O2 debugging.adb
gcc -c -O2 hashes.adb
gcc -c -O2 hashes-hmac_sha1.ads
gcc -c -O2 test_lib.ads
gcc -c -O2 hex_strings.adb
gcc -c -O2 hashes-hmac.adb
gcc -c -O2 hashes-sha1.adb
gcc -c -O2 rfc2202.ads
gcc -c -O2 unconstraint_storage.adb
gcc -c -O2 buffer_mixin.adb
gnatbind -x test.ali
gnatlink test.ali
gnatlink: warning: executable name "test" may conflict with shell command
./hashes-hmac_sha1.o(.rodata+0x10): undefined reference to `.LC1'
collect2: ld returned 1 exit status
gnatlink: cannot call /usr/local/bin/gcc
gnatmake: *** link failed.
adi@drcomp:/tmp/ssh$

gcc-3.14p:

gcc -c hashes-hmac_sha1.ads
+===========================GNAT BUG DETECTED==============================+
| 3.14p (20010503) (i686-pc-linux-gnu) Gigi abort, Code=999                |
| Error detected at hashes-hmac.ads:24:9 [hashes-hmac_sha1.ads:4:1]        |
| Please submit bug report by email to report@gnat.com.                    |


-- 
mail: adi@thur.de  	http://adi.thur.de	PGP: v2-key via keyserver

Der Tod der reicht dir bald die Hand rauchst du Peter Stuyvesant.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Errornous String instantiation
  2003-07-21 10:43 Errornous String instantiation Lutz Donnerhacke
  2003-07-21 10:56 ` Preben Randhol
  2003-07-21 16:19 ` Matthew Heaney
@ 2003-07-23 14:03 ` Lutz Donnerhacke
  2 siblings, 0 replies; 12+ messages in thread
From: Lutz Donnerhacke @ 2003-07-23 14:03 UTC (permalink / raw)


* Lutz Donnerhacke wrote:
> 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.

Current workaround:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  package Top is
     type Constant_String is access constant String;
     type Constant_String_Array is array(Positive range <>) of Constant_String;
  end Top;
  
+ with Top;
+
  package Constants is
     t1 : aliased constant String := "Test";
     t2 : aliased constant String := "A longer test string";
+
+    a  : constant Top.Constant_String_Array := (t1'Access, t2'Access);
  end Constants;
  
  generic
     data : Constant_String_Array;
  package Top.Generic_Package is
     pragma Elaborate_Body;
  end Top.Generic_Package;
  
  with Top.Generic_Package, Constants;
- use Constants;

- package MyPackage is new Top.Generic_Package((t1'Access, t2'Access));
+ package MyPackage is new Top.Generic_Package(Constants.a);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This requires the compiler to instantiate t1 in the scope of Constants for
external use. And this is done correctly.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-07-23 14:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-21 10:43 Errornous String instantiation Lutz Donnerhacke
2003-07-21 10:56 ` Preben Randhol
2003-07-21 11:02   ` Lutz Donnerhacke
2003-07-21 11:07     ` Preben Randhol
2003-07-21 12:35       ` Lutz Donnerhacke
2003-07-21 12:55         ` Lutz Donnerhacke
2003-07-21 21:54           ` Adrian Knoth
2003-07-21 11:08   ` Florian Weimer
2003-07-21 11:17     ` Preben Randhol
2003-07-21 16:19 ` Matthew Heaney
2003-07-21 16:26   ` Lutz Donnerhacke
2003-07-23 14:03 ` Lutz Donnerhacke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox