www.digitalmars.com         C & C++   DMDScript  

D.gnu - To POD or not to POD

reply Johannes Pfau <nospam example.com> writes:
I've started debugging the unit test failures in std.datetime:

We have this Date struct:
-----
struct Date
{
    this(int a){}
    short _year  = 2;
    ubyte _month = 1;
    ubyte _day   = 1;
}
-----

It's passed to D runtime variadic functions. It's 4 bytes in total so
GCC passes this struct in registers on x86_64 and it's therefore saved
in reg_save_area.

But our va_arg implementation using TypeInfo calls TypeInfo.argTypes()
to check if the type can be passed in parameters. This check returns
false as it depends on the dmd check sym->isPOD. Therefore our va_arg
tries to load the Date instance from the overflow_arg / stack save area
instead of the register save area.

What would be the correct way to tell the gcc backend not to pass !isPOD
structs in registers? Using TREE_ADDRESSABLE?

OT: I think a simple constructor shouldn't prevent a type from being a
POD, but that should be defined by dmd /frontend.
Feb 12 2013
next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--047d7bb70dfe698a6604d58b0644
Content-Type: text/plain; charset=ISO-8859-1

On 12 February 2013 17:45, Johannes Pfau <nospam example.com> wrote:

 I've started debugging the unit test failures in std.datetime:

 We have this Date struct:
 -----
 struct Date
 {
     this(int a){}
     short _year  = 2;
     ubyte _month = 1;
     ubyte _day   = 1;
 }
 -----

 It's passed to D runtime variadic functions. It's 4 bytes in total so
 GCC passes this struct in registers on x86_64 and it's therefore saved
 in reg_save_area.

 But our va_arg implementation using TypeInfo calls TypeInfo.argTypes()
 to check if the type can be passed in parameters. This check returns
 false as it depends on the dmd check sym->isPOD. Therefore our va_arg
 tries to load the Date instance from the overflow_arg / stack save area
 instead of the register save area.

 What would be the correct way to tell the gcc backend not to pass !isPOD
 structs in registers? Using TREE_ADDRESSABLE?

top of my head why not. -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --047d7bb70dfe698a6604d58b0644 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= 2 February 2013 17:45, Johannes Pfau <span dir=3D"ltr">&lt;<a href=3D"mailt= o:nospam example.com" target=3D"_blank">nospam example.com</a>&gt;</span> w= rote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">I&#39;ve started debugging the unit test fai= lures in std.datetime:<br> <br> We have this Date struct:<br> -----<br> struct Date<br> {<br> =A0 =A0 this(int a){}<br> =A0 =A0 short _year =A0=3D 2;<br> =A0 =A0 ubyte _month =3D 1;<br> =A0 =A0 ubyte _day =A0 =3D 1;<br> }<br> -----<br> <br> It&#39;s passed to D runtime variadic functions. It&#39;s 4 bytes in total = so<br> GCC passes this struct in registers on x86_64 and it&#39;s therefore saved<= br> in reg_save_area.<br> <br> But our va_arg implementation using TypeInfo calls TypeInfo.argTypes()<br> to check if the type can be passed in parameters. This check returns<br> false as it depends on the dmd check sym-&gt;isPOD. Therefore our va_arg<br=

instead of the register save area.<br> <br> What would be the correct way to tell the gcc backend not to pass !isPOD<br=

<br clear=3D"all"></blockquote></div><br></div><div class=3D"gmail_extra">T= REE_ADDRESSABLE should be sufficient.=A0 I can&#39;t think any reason off t= he top of my head why not.<br></div><div class=3D"gmail_extra"><br>-- <br>I= ain Buclaw<br> <br>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;; </div></div> --047d7bb70dfe698a6604d58b0644--
Feb 12 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Tue, 12 Feb 2013 18:16:31 +0000
schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 TREE_ADDRESSABLE should be sufficient.  I can't think any reason off
 the top of my head why not.
 

maybe TREE_ADDRESSABLE is too strong: It generates errors in the backend if the frontend produces non-lvalues: --- auto b = Date(); a(b); --- works, but --- a(Date()); --- fails in gimplify.c. Do we really have to rewrite such cases so that non-PODs get a temporary variable? And how would this be done? It seems we would have to use the frontend for this, as maybeMakeTemp and makeTemp refuse to work for TREE_ADDRESSABLE types.
Feb 13 2013
prev sibling next sibling parent "David Nadlinger" <see klickverbot.at> writes:
On Tuesday, 12 February 2013 at 17:45:11 UTC, Johannes Pfau wrote:
 OT: I think a simple constructor shouldn't prevent a type from 
 being a
 POD, but that should be defined by dmd /frontend.

I wouldn't spend too much time on implementing the old behavior - I think I managed to convince Walter that constructors preventing PODness is a bad idea in the last bigger discussion on the topic. He also mentioned what sounded like plans in this regard in a recent pull request. Instead, I'd just comment out that specific check in isPOD. David
Feb 13 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--047d7b6dc3ac34d1c604d59bb419
Content-Type: text/plain; charset=ISO-8859-1

On 13 February 2013 13:26, Johannes Pfau <nospam example.com> wrote:

 Am Tue, 12 Feb 2013 18:16:31 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 TREE_ADDRESSABLE should be sufficient.  I can't think any reason off
 the top of my head why not.

maybe TREE_ADDRESSABLE is too strong: It generates errors in the backend if the frontend produces non-lvalues: --- auto b = Date(); a(b); --- works, but --- a(Date()); --- fails in gimplify.c. Do we really have to rewrite such cases so that non-PODs get a temporary variable? And how would this be done? It seems we would have to use the frontend for this, as maybeMakeTemp and makeTemp refuse to work for TREE_ADDRESSABLE types.

Don't set it on the variable, set it on the type. TypeStruct::toCtype() { TYPE_ADDRESSABLE(ctype) = !isPOD(); } -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --047d7b6dc3ac34d1c604d59bb419 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= 3 February 2013 13:26, Johannes Pfau <span dir=3D"ltr">&lt;<a href=3D"mailt= o:nospam example.com" target=3D"_blank">nospam example.com</a>&gt;</span> w= rote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">Am Tue, 12 Feb 2013 18:16:31 +0000<br> schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw ubunt= u.com</a>&gt;:<br> <div class=3D"im"><br> &gt; TREE_ADDRESSABLE should be sufficient. =A0I can&#39;t think any reason= off<br> &gt; the top of my head why not.<br> &gt;<br> <br> </div>maybe TREE_ADDRESSABLE is too strong: It generates errors in the<br> backend if the frontend produces non-lvalues:<br> ---<br> =A0 =A0 auto b =3D Date();<br> =A0 =A0 a(b);<br> ---<br> <br> works, but<br> ---<br> =A0 =A0 a(Date());<br> ---<br> <br> fails in gimplify.c. Do we really have to rewrite such cases so that<br> non-PODs get a temporary variable? And how would this be done? It seems<br> we would have to use the frontend for this, as maybeMakeTemp =A0and<br> makeTemp refuse to work for TREE_ADDRESSABLE types.<br> </blockquote></div><br></div><div class=3D"gmail_extra">Don&#39;t set it on= the variable, set it on the type.<br><br></div><div class=3D"gmail_extra">= TypeStruct::toCtype()<br>{<br>=A0=A0=A0 TYPE_ADDRESSABLE(ctype) =3D !isPOD(= );<br></div> <div class=3D"gmail_extra">}<br></div><div class=3D"gmail_extra"><br clear= =3D"all"><br><br>-- <br>Iain Buclaw<br><br>*(p &lt; e ? p++ : p) =3D (c &am= p; 0x0f) + &#39;0&#39;; </div></div> --047d7b6dc3ac34d1c604d59bb419--
Feb 13 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--047d7b6dc3acab4be804d59bd19d
Content-Type: text/plain; charset=ISO-8859-1

On 13 February 2013 14:10, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 On 13 February 2013 13:26, Johannes Pfau <nospam example.com> wrote:

 Am Tue, 12 Feb 2013 18:16:31 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 TREE_ADDRESSABLE should be sufficient.  I can't think any reason off
 the top of my head why not.

maybe TREE_ADDRESSABLE is too strong: It generates errors in the backend if the frontend produces non-lvalues: --- auto b = Date(); a(b); --- works, but --- a(Date()); --- fails in gimplify.c. Do we really have to rewrite such cases so that non-PODs get a temporary variable? And how would this be done? It seems we would have to use the frontend for this, as maybeMakeTemp and makeTemp refuse to work for TREE_ADDRESSABLE types.

Don't set it on the variable, set it on the type. TypeStruct::toCtype() { TYPE_ADDRESSABLE(ctype) = !isPOD();

TREE_ADDRESSABLE (ctype) = !sym->isPOD() even :-) Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --047d7b6dc3acab4be804d59bd19d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= 3 February 2013 14:10, Iain Buclaw <span dir=3D"ltr">&lt;<a href=3D"mailto:= ibuclaw ubuntu.com" target=3D"_blank">ibuclaw ubuntu.com</a>&gt;</span> wro= te:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-= left:1px #ccc solid;padding-left:1ex"> <div dir=3D"ltr"><div><div class=3D"h5"><div class=3D"gmail_extra"><div cla= ss=3D"gmail_quote">On 13 February 2013 13:26, Johannes Pfau <span dir=3D"lt= r">&lt;<a href=3D"mailto:nospam example.com" target=3D"_blank">nospam examp= le.com</a>&gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">Am Tue, 12 Feb 2013 18:16:31 +0000<br> schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com" target=3D"_bl= ank">ibuclaw ubuntu.com</a>&gt;:<br> <div><br> &gt; TREE_ADDRESSABLE should be sufficient. =A0I can&#39;t think any reason= off<br> &gt; the top of my head why not.<br> &gt;<br> <br> </div>maybe TREE_ADDRESSABLE is too strong: It generates errors in the<br> backend if the frontend produces non-lvalues:<br> ---<br> =A0 =A0 auto b =3D Date();<br> =A0 =A0 a(b);<br> ---<br> <br> works, but<br> ---<br> =A0 =A0 a(Date());<br> ---<br> <br> fails in gimplify.c. Do we really have to rewrite such cases so that<br> non-PODs get a temporary variable? And how would this be done? It seems<br> we would have to use the frontend for this, as maybeMakeTemp =A0and<br> makeTemp refuse to work for TREE_ADDRESSABLE types.<br> </blockquote></div><br></div></div></div><div class=3D"gmail_extra">Don&#39= ;t set it on the variable, set it on the type.<br><br></div><div class=3D"g= mail_extra">TypeStruct::toCtype()<br>{<br>=A0=A0=A0 TYPE_ADDRESSABLE(ctype)= =3D !isPOD();<br> </div></div></blockquote><div><br><br></div><div>TREE_ADDRESSABLE (ctype) = =3D !sym-&gt;isPOD()=A0=A0 even :-)<br></div></div><br><br>Regards<br>-- <b= r>Iain Buclaw<br><br>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;= ; </div></div> --047d7b6dc3acab4be804d59bd19d--
Feb 13 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 13 Feb 2013 14:10:26 +0000
schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 On 13 February 2013 13:26, Johannes Pfau <nospam example.com> wrote:
 
 Am Tue, 12 Feb 2013 18:16:31 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 TREE_ADDRESSABLE should be sufficient.  I can't think any reason
 off the top of my head why not.

maybe TREE_ADDRESSABLE is too strong: It generates errors in the backend if the frontend produces non-lvalues: --- auto b = Date(); a(b); --- works, but --- a(Date()); --- fails in gimplify.c. Do we really have to rewrite such cases so that non-PODs get a temporary variable? And how would this be done? It seems we would have to use the frontend for this, as maybeMakeTemp and makeTemp refuse to work for TREE_ADDRESSABLE types.

Don't set it on the variable, set it on the type. TypeStruct::toCtype() { TYPE_ADDRESSABLE(ctype) = !isPOD(); }

That's actually what I did. But the backend wants to create a copy of the Date type which then fails as create_tmp_var fails for TREE_ADDRESSABLE types. Complete test case: https://gist.github.com/jpf91/4944999 ----- ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-test.reduced/datetime2.d:22: internal compiler error: in create_tmp_var, at gimplify.c:479 0x804509 -----
Feb 13 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 13 Feb 2013 15:14:36 +0100
schrieb "David Nadlinger" <see klickverbot.at>:

 On Tuesday, 12 February 2013 at 17:45:11 UTC, Johannes Pfau wrote:
 OT: I think a simple constructor shouldn't prevent a type from 
 being a
 POD, but that should be defined by dmd /frontend.

I wouldn't spend too much time on implementing the old behavior - I think I managed to convince Walter that constructors preventing PODness is a bad idea in the last bigger discussion on the topic. He also mentioned what sounded like plans in this regard in a recent pull request. Instead, I'd just comment out that specific check in isPOD. David

Good to know. This fixes the datetime specific instance of the problem. But we should probably tell the gcc backend that non-POD types should not be passed in registers anyway, right? Even when ignoring constructors in the isPOD check, marking non-POD types as TREE_ADDRESSABLE causes many errors in the test suite. Maybe we also have to set TREE_ADDRESSABLE on function TYPE, CONSTRUCTOR, VAR_DECL, PARM_DECL and RESULT_DECL nodes if a non-POD type is involved, but I'd expect the backend to do that automatically?
Feb 13 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--485b397dd4fbebe8ce04d59caf48
Content-Type: text/plain; charset=ISO-8859-1

On 13 February 2013 14:35, Johannes Pfau <nospam example.com> wrote:

 Am Wed, 13 Feb 2013 14:10:26 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 On 13 February 2013 13:26, Johannes Pfau <nospam example.com> wrote:

 Am Tue, 12 Feb 2013 18:16:31 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 TREE_ADDRESSABLE should be sufficient.  I can't think any reason
 off the top of my head why not.

maybe TREE_ADDRESSABLE is too strong: It generates errors in the backend if the frontend produces non-lvalues: --- auto b = Date(); a(b); --- works, but --- a(Date()); --- fails in gimplify.c. Do we really have to rewrite such cases so that non-PODs get a temporary variable? And how would this be done? It seems we would have to use the frontend for this, as maybeMakeTemp and makeTemp refuse to work for TREE_ADDRESSABLE types.

Don't set it on the variable, set it on the type. TypeStruct::toCtype() { TYPE_ADDRESSABLE(ctype) = !isPOD(); }

That's actually what I did. But the backend wants to create a copy of the Date type which then fails as create_tmp_var fails for TREE_ADDRESSABLE types. Complete test case: https://gist.github.com/jpf91/4944999 ----- ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-test.reduced/datetime2.d:22: internal compiler error: in create_tmp_var, at gimplify.c:479 0x804509 -----

Ahh, that's because of this piece of codegen: SAVE_EXPR <*test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)> Gimple doesn't like the dereference in SAVE_EXPR. This should work. tree IRState::makeTemp (tree t) { tree type = TREE_TYPE (t); if (TREE_CODE (type) != ARRAY_TYPE && !TREE_ADDRESSABLE (type)) return save_expr (t); return stabilize_reference (t); } So the generated code is now: *SAVE_EXPR <test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)> Regards -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --485b397dd4fbebe8ce04d59caf48 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= 3 February 2013 14:35, Johannes Pfau <span dir=3D"ltr">&lt;<a href=3D"mailt= o:nospam example.com" target=3D"_blank">nospam example.com</a>&gt;</span> w= rote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left:1px solid rgb(204,204,204);padding-left:1ex">Am Wed, 13 Feb 2013 14:10= :26 +0000<br> schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw ubunt= u.com</a>&gt;:<br> <div class=3D"im"><br> &gt; On 13 February 2013 13:26, Johannes Pfau &lt;<a href=3D"mailto:nospam = example.com">nospam example.com</a>&gt; wrote:<br> &gt;<br> </div><div><div class=3D"h5">&gt; &gt; Am Tue, 12 Feb 2013 18:16:31 +0000<b= r> &gt; &gt; schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibu= claw ubuntu.com</a>&gt;:<br> &gt; &gt;<br> &gt; &gt; &gt; TREE_ADDRESSABLE should be sufficient. =A0I can&#39;t think = any reason<br> &gt; &gt; &gt; off the top of my head why not.<br> &gt; &gt; &gt;<br> &gt; &gt;<br> &gt; &gt; maybe TREE_ADDRESSABLE is too strong: It generates errors in the<= br> &gt; &gt; backend if the frontend produces non-lvalues:<br> &gt; &gt; ---<br> &gt; &gt; =A0 =A0 auto b =3D Date();<br> &gt; &gt; =A0 =A0 a(b);<br> &gt; &gt; ---<br> &gt; &gt;<br> &gt; &gt; works, but<br> &gt; &gt; ---<br> &gt; &gt; =A0 =A0 a(Date());<br> &gt; &gt; ---<br> &gt; &gt;<br> &gt; &gt; fails in gimplify.c. Do we really have to rewrite such cases so t= hat<br> &gt; &gt; non-PODs get a temporary variable? And how would this be done? It= <br> &gt; &gt; seems we would have to use the frontend for this, as maybeMakeTem= p<br> &gt; &gt; and makeTemp refuse to work for TREE_ADDRESSABLE types.<br> &gt; &gt;<br> &gt;<br> </div></div><div class=3D"im">&gt; Don&#39;t set it on the variable, set it= on the type.<br> &gt;<br> &gt; TypeStruct::toCtype()<br> &gt; {<br> &gt; =A0 =A0 TYPE_ADDRESSABLE(ctype) =3D !isPOD();<br> &gt; }<br> <br> </div>That&#39;s actually what I did. But the backend wants to create a cop= y of<br> the Date type which then fails as create_tmp_var fails for<br> TREE_ADDRESSABLE types.<br> <br> Complete test case:<br> <a href=3D"https://gist.github.com/jpf91/4944999" target=3D"_blank">https:/= /gist.github.com/jpf91/4944999</a><br> <br> -----<br> ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-test.reduced/datetim= e2.d:22:<br> internal compiler error: in create_tmp_var, at gimplify.c:479 0x804509<br> -----<br> <br> </blockquote></div><br><br></div><div class=3D"gmail_extra">Ahh, that&#39;s= because of this piece of codegen:<br><br>SAVE_EXPR &lt;*test.Date.this (&a= mp;((void) (__ctmp971 =3D _D4test4Date6__initZ);, __ctmp971), 0)&gt;<br cle= ar=3D"all"> </div><div class=3D"gmail_extra"><br><br></div><div class=3D"gmail_extra">G= imple doesn&#39;t like the dereference in SAVE_EXPR.=A0 This should work.<b= r><br>tree<br>IRState::makeTemp (tree t)<br>{<br>=A0 tree type =3D TREE_TYP= E (t);<br> =A0 if (TREE_CODE (type) !=3D ARRAY_TYPE &amp;&amp; !TREE_ADDRESSABLE (type= ))<br>=A0=A0=A0 return save_expr (t);<br><br>=A0 return stabilize_reference= (t);<br>}<br><br><br></div><div class=3D"gmail_extra">So the generated cod= e is now:<br> <br>*SAVE_EXPR &lt;test.Date.this (&amp;((void) (__ctmp971 =3D _D4test4Date= 6__initZ);, __ctmp971), 0)&gt;<br><br><br></div><div class=3D"gmail_extra">= <br></div><div class=3D"gmail_extra">Regards<br></div><div class=3D"gmail_e= xtra"> -- <br>Iain Buclaw<br><br>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0= &#39;; </div></div> --485b397dd4fbebe8ce04d59caf48--
Feb 13 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--047d7bb70dfec3275504d59e4f89
Content-Type: text/plain; charset=ISO-8859-1

On 13 February 2013 15:20, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 On 13 February 2013 14:35, Johannes Pfau <nospam example.com> wrote:

 Am Wed, 13 Feb 2013 14:10:26 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 On 13 February 2013 13:26, Johannes Pfau <nospam example.com> wrote:

 Am Tue, 12 Feb 2013 18:16:31 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 TREE_ADDRESSABLE should be sufficient.  I can't think any reason
 off the top of my head why not.

maybe TREE_ADDRESSABLE is too strong: It generates errors in the backend if the frontend produces non-lvalues: --- auto b = Date(); a(b); --- works, but --- a(Date()); --- fails in gimplify.c. Do we really have to rewrite such cases so that non-PODs get a temporary variable? And how would this be done? It seems we would have to use the frontend for this, as maybeMakeTemp and makeTemp refuse to work for TREE_ADDRESSABLE types.

Don't set it on the variable, set it on the type. TypeStruct::toCtype() { TYPE_ADDRESSABLE(ctype) = !isPOD(); }

That's actually what I did. But the backend wants to create a copy of the Date type which then fails as create_tmp_var fails for TREE_ADDRESSABLE types. Complete test case: https://gist.github.com/jpf91/4944999 ----- ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-test.reduced/datetime2.d:22: internal compiler error: in create_tmp_var, at gimplify.c:479 0x804509 -----

Ahh, that's because of this piece of codegen: SAVE_EXPR <*test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)> Gimple doesn't like the dereference in SAVE_EXPR. This should work. tree IRState::makeTemp (tree t) { tree type = TREE_TYPE (t); if (TREE_CODE (type) != ARRAY_TYPE && !TREE_ADDRESSABLE (type)) return save_expr (t); return stabilize_reference (t); } So the generated code is now: *SAVE_EXPR <test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)>

-- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --047d7bb70dfec3275504d59e4f89 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= 3 February 2013 15:20, Iain Buclaw <span dir=3D"ltr">&lt;<a href=3D"mailto:= ibuclaw ubuntu.com" target=3D"_blank">ibuclaw ubuntu.com</a>&gt;</span> wro= te:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-= left:1px #ccc solid;padding-left:1ex"> <div dir=3D"ltr"><div><div class=3D"h5"><div class=3D"gmail_extra"><div cla= ss=3D"gmail_quote">On 13 February 2013 14:35, Johannes Pfau <span dir=3D"lt= r">&lt;<a href=3D"mailto:nospam example.com" target=3D"_blank">nospam examp= le.com</a>&gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left:1px solid rgb(204,204,204);padding-left:1ex">Am Wed, 13 Feb 2013 14:10= :26 +0000<br> schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com" target=3D"_bl= ank">ibuclaw ubuntu.com</a>&gt;:<br> <div><br> &gt; On 13 February 2013 13:26, Johannes Pfau &lt;<a href=3D"mailto:nospam = example.com" target=3D"_blank">nospam example.com</a>&gt; wrote:<br> &gt;<br> </div><div><div>&gt; &gt; Am Tue, 12 Feb 2013 18:16:31 +0000<br> &gt; &gt; schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com" tar= get=3D"_blank">ibuclaw ubuntu.com</a>&gt;:<br> &gt; &gt;<br> &gt; &gt; &gt; TREE_ADDRESSABLE should be sufficient. =A0I can&#39;t think = any reason<br> &gt; &gt; &gt; off the top of my head why not.<br> &gt; &gt; &gt;<br> &gt; &gt;<br> &gt; &gt; maybe TREE_ADDRESSABLE is too strong: It generates errors in the<= br> &gt; &gt; backend if the frontend produces non-lvalues:<br> &gt; &gt; ---<br> &gt; &gt; =A0 =A0 auto b =3D Date();<br> &gt; &gt; =A0 =A0 a(b);<br> &gt; &gt; ---<br> &gt; &gt;<br> &gt; &gt; works, but<br> &gt; &gt; ---<br> &gt; &gt; =A0 =A0 a(Date());<br> &gt; &gt; ---<br> &gt; &gt;<br> &gt; &gt; fails in gimplify.c. Do we really have to rewrite such cases so t= hat<br> &gt; &gt; non-PODs get a temporary variable? And how would this be done? It= <br> &gt; &gt; seems we would have to use the frontend for this, as maybeMakeTem= p<br> &gt; &gt; and makeTemp refuse to work for TREE_ADDRESSABLE types.<br> &gt; &gt;<br> &gt;<br> </div></div><div>&gt; Don&#39;t set it on the variable, set it on the type.= <br> &gt;<br> &gt; TypeStruct::toCtype()<br> &gt; {<br> &gt; =A0 =A0 TYPE_ADDRESSABLE(ctype) =3D !isPOD();<br> &gt; }<br> <br> </div>That&#39;s actually what I did. But the backend wants to create a cop= y of<br> the Date type which then fails as create_tmp_var fails for<br> TREE_ADDRESSABLE types.<br> <br> Complete test case:<br> <a href=3D"https://gist.github.com/jpf91/4944999" target=3D"_blank">https:/= /gist.github.com/jpf91/4944999</a><br> <br> -----<br> ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-test.reduced/datetim= e2.d:22:<br> internal compiler error: in create_tmp_var, at gimplify.c:479 0x804509<br> -----<br> <br> </blockquote></div><br><br></div></div></div><div class=3D"gmail_extra">Ahh= , that&#39;s because of this piece of codegen:<br><br>SAVE_EXPR &lt;*test.D= ate.this (&amp;((void) (__ctmp971 =3D _D4test4Date6__initZ);, __ctmp971), 0= )&gt;<br clear=3D"all"> </div><div class=3D"gmail_extra"><br><br></div><div class=3D"gmail_extra">G= imple doesn&#39;t like the dereference in SAVE_EXPR.=A0 This should work.<b= r><br>tree<br>IRState::makeTemp (tree t)<br>{<br>=A0 tree type =3D TREE_TYP= E (t);<br> =A0 if (TREE_CODE (type) !=3D ARRAY_TYPE &amp;&amp; !TREE_ADDRESSABLE (type= ))<br>=A0=A0=A0 return save_expr (t);<br><br>=A0 return stabilize_reference= (t);<br>}<br><br><br></div><div class=3D"gmail_extra">So the generated cod= e is now:<br> <br>*SAVE_EXPR &lt;test.Date.this (&amp;((void) (__ctmp971 =3D _D4test4Date= 6__initZ);, __ctmp971), 0)&gt;<br><br clear=3D"all"></div></div></blockquot= e></div><br></div><div class=3D"gmail_extra">After some more playing about,= David&#39;s suggestion would be the quickest. ;-)<br> </div><div class=3D"gmail_extra"><br>-- <br>Iain Buclaw<br><br>*(p &lt; e ?= p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;; </div></div> --047d7bb70dfec3275504d59e4f89--
Feb 13 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Wed, 13 Feb 2013 17:17:06 +0000
schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 On 13 February 2013 15:20, Iain Buclaw <ibuclaw ubuntu.com> wrote:
 
 Complete test case:
 https://gist.github.com/jpf91/4944999

 -----

 ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-test.reduced/datetime2.d:22:
 internal compiler error: in create_tmp_var, at gimplify.c:479
 0x804509 -----

Ahh, that's because of this piece of codegen: SAVE_EXPR <*test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)> Gimple doesn't like the dereference in SAVE_EXPR. This should work. tree IRState::makeTemp (tree t) { tree type = TREE_TYPE (t); if (TREE_CODE (type) != ARRAY_TYPE && !TREE_ADDRESSABLE (type)) return save_expr (t); return stabilize_reference (t); } So the generated code is now: *SAVE_EXPR <test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)>

quickest. ;-)

Indeed. But what if the example is slightly adjusted to define a destructor or postblit instead of the constructor? Does the backend know about those or would it still try to pass Date in registers? For this current test case the issue seems to be that DMD creates a StructLiteralExp for the default constructor call which is of course not an lvalue and gimple seems to dislike that. But I don't know how to fix this and there could be many more cases...
Feb 13 2013
prev sibling next sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--001636c5b473365e8c04d5a18c2f
Content-Type: text/plain; charset=ISO-8859-1

On Feb 13, 2013 6:55 PM, "Johannes Pfau" <nospam example.com> wrote:
 Am Wed, 13 Feb 2013 17:17:06 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 On 13 February 2013 15:20, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 Complete test case:
 https://gist.github.com/jpf91/4944999

 -----




 internal compiler error: in create_tmp_var, at gimplify.c:479
 0x804509 -----

Ahh, that's because of this piece of codegen: SAVE_EXPR <*test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)> Gimple doesn't like the dereference in SAVE_EXPR. This should work. tree IRState::makeTemp (tree t) { tree type = TREE_TYPE (t); if (TREE_CODE (type) != ARRAY_TYPE && !TREE_ADDRESSABLE (type)) return save_expr (t); return stabilize_reference (t); } So the generated code is now: *SAVE_EXPR <test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)>

quickest. ;-)

Indeed. But what if the example is slightly adjusted to define a destructor or postblit instead of the constructor? Does the backend know about those or would it still try to pass Date in registers?

Backend doesn't know of those, and yes it would pass it in registers because it will always see structs as a value type rather than a reference (though passing round 'this' should always be done in memory). Regards Iain. --001636c5b473365e8c04d5a18c2f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p><br> On Feb 13, 2013 6:55 PM, &quot;Johannes Pfau&quot; &lt;<a href=3D"mailto:no= spam example.com">nospam example.com</a>&gt; wrote:<br> &gt;<br> &gt; Am Wed, 13 Feb 2013 17:17:06 +0000<br> &gt; schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw = ubuntu.com</a>&gt;:<br> &gt;<br> &gt; &gt; On 13 February 2013 15:20, Iain Buclaw &lt;<a href=3D"mailto:ibuc= law ubuntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt; &gt;<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt; Complete test case:<br> &gt; &gt; &gt;&gt; <a href=3D"https://gist.github.com/jpf91/4944999">https:= //gist.github.com/jpf91/4944999</a><br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt; -----<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt; ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-t= est.reduced/datetime2.d:22:<br> &gt; &gt; &gt;&gt; internal compiler error: in create_tmp_var, at gimplify.= c:479<br> &gt; &gt; &gt;&gt; 0x804509 -----<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; Ahh, that&#39;s because of this piece of codegen:<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; SAVE_EXPR &lt;*test.Date.this (&amp;((void) (__ctmp971 =3D<b= r> &gt; &gt; &gt; _D4test4Date6__initZ);, __ctmp971), 0)&gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; Gimple doesn&#39;t like the dereference in SAVE_EXPR. =A0Thi= s should work.<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; tree<br> &gt; &gt; &gt; IRState::makeTemp (tree t)<br> &gt; &gt; &gt; {<br> &gt; &gt; &gt; =A0 tree type =3D TREE_TYPE (t);<br> &gt; &gt; &gt; =A0 if (TREE_CODE (type) !=3D ARRAY_TYPE &amp;&amp; !TREE_AD= DRESSABLE (type))<br> &gt; &gt; &gt; =A0 =A0 return save_expr (t);<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; =A0 return stabilize_reference (t);<br> &gt; &gt; &gt; }<br> &gt; &gt; &gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; So the generated code is now:<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; *SAVE_EXPR &lt;test.Date.this (&amp;((void) (__ctmp971 =3D<b= r> &gt; &gt; &gt; _D4test4Date6__initZ);, __ctmp971), 0)&gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt;<br> &gt; &gt; After some more playing about, David&#39;s suggestion would be th= e<br> &gt; &gt; quickest. ;-)<br> &gt; &gt;<br> &gt;<br> &gt; Indeed. But what if the example is slightly adjusted to define a<br> &gt; destructor or postblit instead of the constructor? Does the backend<br=

&gt;</p> <p>Backend doesn&#39;t know of those, and yes it would pass it in registers= because it will always see structs as a value type rather than a reference= (though passing round &#39;this&#39; should always be done in memory).</p> <p>Regards<br> Iain. <br> </p> --001636c5b473365e8c04d5a18c2f--
Feb 13 2013
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--047d7b6dc3ac08724804d5a277ae
Content-Type: text/plain; charset=ISO-8859-1

On Feb 13, 2013 6:55 PM, "Johannes Pfau" <nospam example.com> wrote:
 Am Wed, 13 Feb 2013 17:17:06 +0000
 schrieb Iain Buclaw <ibuclaw ubuntu.com>:

 On 13 February 2013 15:20, Iain Buclaw <ibuclaw ubuntu.com> wrote:

 Complete test case:
 https://gist.github.com/jpf91/4944999

 -----




 internal compiler error: in create_tmp_var, at gimplify.c:479
 0x804509 -----

Ahh, that's because of this piece of codegen: SAVE_EXPR <*test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)> Gimple doesn't like the dereference in SAVE_EXPR. This should work. tree IRState::makeTemp (tree t) { tree type = TREE_TYPE (t); if (TREE_CODE (type) != ARRAY_TYPE && !TREE_ADDRESSABLE (type)) return save_expr (t); return stabilize_reference (t); } So the generated code is now: *SAVE_EXPR <test.Date.this (&((void) (__ctmp971 = _D4test4Date6__initZ);, __ctmp971), 0)>

quickest. ;-)

Indeed. But what if the example is slightly adjusted to define a destructor or postblit instead of the constructor? Does the backend know about those or would it still try to pass Date in registers?

Backend doesn't know of those, and yes it would pass it in registers because it will always see structs as a value type rather than a reference (though passing round 'this' should always be done in memory). Regards Iain. --047d7b6dc3ac08724804d5a277ae Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p><br> On Feb 13, 2013 6:55 PM, &quot;Johannes Pfau&quot; &lt;<a href=3D"mailto:no= spam example.com">nospam example.com</a>&gt; wrote:<br> &gt;<br> &gt; Am Wed, 13 Feb 2013 17:17:06 +0000<br> &gt; schrieb Iain Buclaw &lt;<a href=3D"mailto:ibuclaw ubuntu.com">ibuclaw = ubuntu.com</a>&gt;:<br> &gt;<br> &gt; &gt; On 13 February 2013 15:20, Iain Buclaw &lt;<a href=3D"mailto:ibuc= law ubuntu.com">ibuclaw ubuntu.com</a>&gt; wrote:<br> &gt; &gt;<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt; Complete test case:<br> &gt; &gt; &gt;&gt; <a href=3D"https://gist.github.com/jpf91/4944999">https:= //gist.github.com/jpf91/4944999</a><br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt; -----<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt; ../../objdir-4.7/x86_64-unknown-linux-gnu/libphobos/dm-t= est.reduced/datetime2.d:22:<br> &gt; &gt; &gt;&gt; internal compiler error: in create_tmp_var, at gimplify.= c:479<br> &gt; &gt; &gt;&gt; 0x804509 -----<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;&gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; Ahh, that&#39;s because of this piece of codegen:<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; SAVE_EXPR &lt;*test.Date.this (&amp;((void) (__ctmp971 =3D<b= r> &gt; &gt; &gt; _D4test4Date6__initZ);, __ctmp971), 0)&gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; Gimple doesn&#39;t like the dereference in SAVE_EXPR. =A0Thi= s should work.<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; tree<br> &gt; &gt; &gt; IRState::makeTemp (tree t)<br> &gt; &gt; &gt; {<br> &gt; &gt; &gt; =A0 tree type =3D TREE_TYPE (t);<br> &gt; &gt; &gt; =A0 if (TREE_CODE (type) !=3D ARRAY_TYPE &amp;&amp; !TREE_AD= DRESSABLE (type))<br> &gt; &gt; &gt; =A0 =A0 return save_expr (t);<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; =A0 return stabilize_reference (t);<br> &gt; &gt; &gt; }<br> &gt; &gt; &gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; So the generated code is now:<br> &gt; &gt; &gt;<br> &gt; &gt; &gt; *SAVE_EXPR &lt;test.Date.this (&amp;((void) (__ctmp971 =3D<b= r> &gt; &gt; &gt; _D4test4Date6__initZ);, __ctmp971), 0)&gt;<br> &gt; &gt; &gt;<br> &gt; &gt; &gt;<br> &gt; &gt; After some more playing about, David&#39;s suggestion would be th= e<br> &gt; &gt; quickest. ;-)<br> &gt; &gt;<br> &gt;<br> &gt; Indeed. But what if the example is slightly adjusted to define a<br> &gt; destructor or postblit instead of the constructor? Does the backend<br=

&gt;</p> <p>Backend doesn&#39;t know of those, and yes it would pass it in registers= because it will always see structs as a value type rather than a reference= (though passing round &#39;this&#39; should always be done in memory).</p> <p>Regards<br> Iain. </p> --047d7b6dc3ac08724804d5a277ae--
Feb 13 2013