comp.lang.ada
 help / color / mirror / Atom feed
From: "Markus Schöpflin" <no.spam@spam.spam>
Subject: Differences in finalization of controlled objects between gcc 4.6 and gcc 4.7
Date: Thu, 19 Jul 2012 14:23:27 +0200
Date: 2012-07-19T14:23:27+02:00	[thread overview]
Message-ID: <ju8u7t$kh9$1@speranza.aioe.org> (raw)

Hello,

please consider the following piece of code:

---%<---
with ADA.FINALIZATION;
package CTRL is
    type T is new ADA.FINALIZATION.CONTROLLED with null record;
    procedure INITIALIZE (X : in out T);
    procedure ADJUST (X : in out T);
    procedure FINALIZE (X : in out T);
end CTRL;
--
with TEXT_IO;
with SYSTEM.ADDRESS_IMAGE;
package body CTRL is
    procedure INITIALIZE (X : in out T) is
    begin
       TEXT_IO.PUT_LINE (SYSTEM.ADDRESS_IMAGE (X'Address) & ": I");
    end INITIALIZE;

    procedure ADJUST (X : in out T) is
    begin
       TEXT_IO.PUT_LINE (SYSTEM.ADDRESS_IMAGE (X'Address) & ": A");
    end ADJUST;

    procedure FINALIZE (X : in out T) is
    begin
       TEXT_IO.PUT_LINE (SYSTEM.ADDRESS_IMAGE (X'Address) & ": F");
    end FINALIZE;

end CTRL;
--
with CTRL;
procedure TEST_CTRL
is
    function CREATE return CTRL.T is
    begin
       return X : CTRL.T;
    end;
    X : array (1 ..2) of CTRL.T := (others => CREATE);
begin
    null;
end;
--->%---

Compiled and executed with gcc-4.6.3 it gives the following result:

 > /opt/gcc-4.6.3/bin/gnatmake -j4 -O3 -g -gnatwa -gnatn test_ctrl
gcc -c -O3 -g -gnatwa -gnatn test_ctrl.adb
test_ctrl.adb:13:04: warning: variable "X" is not referenced
gcc -c -O3 -g -gnatwa -gnatn ctrl.adb
gnatbind -x test_ctrl.ali
gnatlink test_ctrl.ali -O3 -g
 > ./test_ctrl
BFD1BA54: I
08078450: A
BFD1BA54: F
BFD1BA20: A
BFD1BA54: I
08078460: A
BFD1BA54: F
BFD1BA2C: A
08078460: F
08078450: F
BFD1BA2C: F
BFD1BA20: F

Compiled and executed with gcc-4.7.1 it gives the following result:

 > /opt/gcc-4.7.1/bin/gnatmake -j4 -O3 -g -gnatwa -gnatn test_ctrl
gcc -c -O3 -g -gnatwa -gnatn test_ctrl.adb
test_ctrl.adb:13:04: warning: variable "X" is not referenced
gcc -c -O3 -g -gnatwa -gnatn ctrl.adb
gnatbind -x test_ctrl.ali
gnatlink test_ctrl.ali -O3 -g
 > ./test_ctrl
BFE0B018: I
08077F90: A
BFE0B018: F
BFE0B028: A
08077F90: F
08077F90: F
BFE0B018: I
08077FA0: A
BFE0B018: F
BFE0B02C: A
08077FA0: F
08077FA0: F
BFE0B02C: F
BFE0B028: F

What surprises me is that the objects with address 08077F90 and 08077FA0 are 
finalized twice in the second case. I'm aware that this is allowed but 
nevertheless I'm wondering why it happens here, because up to now I was 
thinking that only by explicitly calling finalize() or when tasks are involved 
that this actually happens. Should I consider this a regression in gcc and 
report it as such?

On a second note, I'm quite surprised at the number of temporary objects 
created in this example, both by gcc 4.6 and 4.7. Is there a way to have the 
objects created in place directly in the array?

Regards,
Markus



             reply	other threads:[~2012-07-26  1:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-19 12:23 Markus Schöpflin [this message]
2012-07-19 13:45 ` Differences in finalization of controlled objects between gcc 4.6 and gcc 4.7 Georg Bauhaus
2012-07-19 13:59   ` Markus Schöpflin
2012-07-19 14:48     ` Georg Bauhaus
2012-07-20  2:56     ` Randy Brukardt
2012-07-20  2:59 ` Randy Brukardt
2012-07-27  7:02   ` Markus Schöpflin
replies disabled

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