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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,27db9c02e8783e58,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.86.232 with SMTP id s8mr1296919paz.47.1343265037031; Wed, 25 Jul 2012 18:10:37 -0700 (PDT) Path: p10ni60144650pbh.1!nntp.google.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!ctu-peer!news.nctu.edu.tw!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: =?ISO-8859-15?Q?Markus_Sch=F6pflin?= Newsgroups: comp.lang.ada Subject: Differences in finalization of controlled objects between gcc 4.6 and gcc 4.7 Date: Thu, 19 Jul 2012 14:23:27 +0200 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: MdpKeRr+sx3LK7JQiK5aNw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-07-19T14:23:27+02:00 List-Id: 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