comp.lang.ada
 help / color / mirror / Atom feed
* gneric package breaks the restriction of No_Elaboration_Code ?
@ 2011-02-28 10:26 ytomino
  2011-02-28 12:42 ` Simon Wright
  2011-02-28 13:03 ` ytomino
  0 siblings, 2 replies; 4+ messages in thread
From: ytomino @ 2011-02-28 10:26 UTC (permalink / raw)


Hello.
I found unnecessary elaboration code is generated
that is probably caused by generic instantiation.
Please look the sources in below:

---- t_g.ads ----
pragma Restrictions (No_Elaboration_Code);
pragma No_Run_Time;
generic
procedure t_g;
pragma Pure (t_g);
---- t_g.adb ----
pragma Restrictions (No_Elaboration_Code);
pragma No_Run_Time;
procedure t_g is
begin
   null;
end t_g;
---- t_i.ads ----
pragma Restrictions (No_Elaboration_Code);
pragma No_Run_Time;
with t_g;
package t_i is
   pragma Pure (t_i);
   procedure nested is new t_g; -- *1
end t_i;
---- t_m.adb ----
pragma Restrictions (No_Elaboration_Code);
pragma No_Run_Time;
with t_g;
package t_i is
   pragma Pure (t_i);
   procedure nested is new t_g;
end t_i;
-----------------

And comple these, look b~t_m.adb.

% gnatmake -g t_m
gcc -c -g t_m.adb
gcc -c -g t_i.ads
gcc -c -g t_g.adb
gnatbind -x t_m.ali
gnatlink t_m.ali -g

---- b~t_m.adb ----
...
   procedure adainit is
      E2 : Boolean; pragma Import (Ada, E2, "t_i_E");

   begin
      null;

      t_i'elab_spec; -- *2
      E2 := True;
   end adainit;
...
-------------------

Also, I used nm, found __elabs procedure.

% nm t_i.o
00000261 D _t_i_E
00000008 T _t_i___elabs
00000000 T _t_i__nested

Next, remove generic instantiation (*1), and re-compile these,
then, elaboration code disappeared from adainit in b~t_m.adb.

---- b~t_m.adb ----
...
   procedure adainit is

   begin
      null;

   end adainit;
...
-------------------

__elabs procedure disappeared too.

% nm t_i.o
00000025 D _t_i_E

I think this is gcc's bug. (I tried with gcc-4.5.1/4.5.2)
Or, possibly this is correct on the spec ?



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

* Re: gneric package breaks the restriction of No_Elaboration_Code ?
  2011-02-28 10:26 gneric package breaks the restriction of No_Elaboration_Code ? ytomino
@ 2011-02-28 12:42 ` Simon Wright
  2011-03-07  8:51   ` ytomino
  2011-02-28 13:03 ` ytomino
  1 sibling, 1 reply; 4+ messages in thread
From: Simon Wright @ 2011-02-28 12:42 UTC (permalink / raw)


ytomino <aghia05@gmail.com> writes:

> I think this is gcc's bug. (I tried with gcc-4.5.1/4.5.2)

Same with 4.6.0 experimental at 20110225.



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

* Re: gneric package breaks the restriction of No_Elaboration_Code ?
  2011-02-28 10:26 gneric package breaks the restriction of No_Elaboration_Code ? ytomino
  2011-02-28 12:42 ` Simon Wright
@ 2011-02-28 13:03 ` ytomino
  1 sibling, 0 replies; 4+ messages in thread
From: ytomino @ 2011-02-28 13:03 UTC (permalink / raw)


Sorry, I missed copy & paste t_m.adb.

pragma Restrictions (No_Elaboration_Code);
pragma No_Run_Time;
with t_i;
procedure t_m is
begin
   null;
end t_m;



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

* Re: gneric package breaks the restriction of No_Elaboration_Code ?
  2011-02-28 12:42 ` Simon Wright
@ 2011-03-07  8:51   ` ytomino
  0 siblings, 0 replies; 4+ messages in thread
From: ytomino @ 2011-03-07  8:51 UTC (permalink / raw)


On Feb 28, 9:42 pm, Simon Wright <si...@pushface.org> wrote:
> ytomino <aghi...@gmail.com> writes:
> > I think this is gcc's bug. (I tried with gcc-4.5.1/4.5.2)
>
> Same with 4.6.0 experimental at 20110225.

Thanks for confirmation.

I reported this to GCC Bugzilla.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48013

and I made dirty-patch. It tentatively seems correct.
I don't know the details of gcc, cannot judge whether this solution is
correct or ill...
(Most of adainit was decreased with this patch, therefore disused .o
were removed on linking. I'm happy a little... Is it good or bad???)

Index: gcc/ada/gcc-interface/trans.c
===================================================================
--- gcc/ada/gcc-interface/trans.c	(revision 170538)
+++ gcc/ada/gcc-interface/trans.c	(working copy)
@@ -223,6 +223,34 @@
    of configurations.  */
 static const char *extract_encoding (const char *) ATTRIBUTE_UNUSED;
 static const char *decode_name (const char *) ATTRIBUTE_UNUSED;
+
+static bool is_empty (tree x);
+static bool is_empty (tree x)
+{
+  if (x){
+    switch (TREE_CODE (x)){
+    case STATEMENT_LIST:
+      do {
+        struct tree_statement_list_node *i = STATEMENT_LIST_HEAD(x);
+        while (i){
+          if (! is_empty (i->stmt)){
+            return false;
+          }
+          i = i->next;
+        }
+      }while (0);
+      break;
+    case STMT_STMT:
+      if (! is_empty (STMT_STMT_STMT (x))){ /* elm->exp.operands[0]
*/
+        return false;
+      }
+      break;
+    default:
+      return false;
+    }
+  }
+  return true;
+}

 /* This is the main program of the back-end.  It sets up all the
table
    structures and then generates code.  */
@@ -644,7 +672,7 @@
       gnu_stmts = gnu_body;
       if (TREE_CODE (gnu_stmts) == BIND_EXPR)
 	gnu_stmts = BIND_EXPR_BODY (gnu_stmts);
-      if (!gnu_stmts || !STATEMENT_LIST_HEAD (gnu_stmts))
+      if (is_empty (gnu_stmts))
 	Set_Has_No_Elaboration_Code (info->gnat_node, 1);
       else
 	{



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

end of thread, other threads:[~2011-03-07  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 10:26 gneric package breaks the restriction of No_Elaboration_Code ? ytomino
2011-02-28 12:42 ` Simon Wright
2011-03-07  8:51   ` ytomino
2011-02-28 13:03 ` ytomino

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