www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Issue 42] New: Non-POD types not implemented

http://gdcproject.org/bugzilla/show_bug.cgi?id=42


           Summary: Non-POD types not implemented
    Classification: Unclassified
           Product: GDC
           Version: development
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
        AssignedTo: ibuclaw gdcproject.org
        ReportedBy: johannespfau gmail.com


Non-POD types are currently not correctly implemented in GDC.

Because of bugs in DMD it's not 100% clear how non-PODs should work, but this
is what I've found:

In dmd, if a non-POD is returned from a function, it's returned by hidden
reference. This can be achieved in GDC by doing this:

* Setting the DECL_BY_REFERENCE flag on the result decl.
* Replacing the return type of the function with a reference type of that type
* Fixing up assigments to the result value to do the dereference
* Maybe setting SET_DECL_VALUE_EXPR? (See c++ frontend)

As code: in d_genericize:
+  if (TREE_ADDRESSABLE (TREE_TYPE (DECL_RESULT (fndecl))))
+    {
+      tree t = DECL_RESULT (fndecl);
+      TREE_TYPE (t) = build_reference_type (TREE_TYPE (t));
+      DECL_BY_REFERENCE (t) = 1;
+      TREE_ADDRESSABLE (t) = 0;
+      relayout_decl (t);
+    }

in d_gimplify_expr: (in the )
+      if(TREE_CODE(op0) == RESULT_DECL && DECL_BY_REFERENCE(op0))
+      {
+         TREE_OPERAND (*expr_p, 0) = gen.indirect(op0);
+         op0 = TREE_OPERAND (*expr_p, 0);
+      }

In dmd a non-POD is passed in memory to varargs functions. I'm not sure if it's
passed by reference, but passing by reference may be necessary, see dmd bug
9704.

AFAICS this can only be achieved by setting TREE_ADDRESSABLE on the non-POD
_type_.

In the future a non-POD will probably be passed by reference to normal
functions. This is pending dmd bug 9704. This should probably be implemented
using build_reference_type and friends for the parameters in the glue layer.
Note that as long as 9704 isn't fixed this can't be implemented properly in
gdc. Currently the frontend for example passes literals to function calls. We
can't take the address of these. We could make a copy in the glue layer, but
this should probably be fixed in the frontend.

As a final note:
The TREE_ADDRESSABLE flag on a type does not automatically make sure it's
passed by reference to a function, or returned by reference. This must be
enforced manually using DECL_BY_REFERECE and build_reference_type as described
above.

-- 
Configure issuemail: http://gdcproject.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all issue changes.
Mar 12 2013