<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Yes..the assertions all passes..but granted, maybe we don't have full coverage. I can look at the frontend, or just make it so in the backend.<div><br></div><div><br></div><div>On further thought..by quick read..this M3x86.m3 code is questionable.</div><div>While in_proc is usually false for declare_local, I think it really goes both ways.</div><div>So it looks like size is sometimes rounded up to 4, sometimes left as zero.</div><div><br></div><div><br></div><div>But what does it mean?</div><div>Does a zero sized array get any storage?</div><div>In C and C++, two objects can't be at the same address, so, for example:</div><div>struct foo { } bar; is not legal C. It is legal C++, however:</div><div><br></div><div><br></div><div>struct foo { } a,b;</div><div>assert(&a != &b); will pass.</div><div><br></div><div><br></div><div>and</div><div>void* a = malloc(0);</div><div>void* b = malloc(0);</div><div>assert(a != b) will also pass in C and C++.</div><div><br></div><div><br></div><div>That is, size 0 struct is invalid in C. In C++ it is rounded up to at least 1.</div><div>malloc(0) is rounded up to at least 1.</div><div><span style="font-size: 12pt; ">No two "objects" can have the same address.</span></div><div><br></div><div><br></div><div>What is the meaning Modula-3?</div><div>Rounding up to 1 or alignment seems easy/decent.</div><div>Certainly these zero sized things are rare in our tree.</div><div><br></div><div><br></div><div> - Jay<br><div><br><br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">CC: m3devel@elegosoft.com<br>From: antony.hosking@gmail.com<br>Subject: Re: [M3devel] zero sized structs?<br>Date: Thu, 4 Oct 2012 09:21:28 -0400<br>To: jay.krell@cornell.edu<br><br><div>Try to respect alignment. <br><br>Sent from my iPad</div><div><br>On Oct 4, 2012, at 2:25 AM, Jay K <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:<br><br></div><div></div><blockquote><div>
<style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:12pt;font-family:Calibri;}
--></style>
<div dir="ltr"><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><span class="ecxApple-tab-span" style="white-space:pre"> </span>declare_local<span class="ecxApple-tab-span" style="white-space:pre"> </span> noArgs 0 8 Struct -1522787086 T F 50 v.318</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">and here is some relevant M3x86 code:</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> IF u.in_proc THEN</font></div><div><font face="Calibri, sans-serif"> v := get_temp_var (u, type, s, a, n);</font></div><div><font face="Calibri, sans-serif"> ELSE</font></div><div><font face="Calibri, sans-serif"> v := create_temp_var (u, type, s, a, n);</font></div><div><font face="Calibri, sans-serif"> END;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">PROCEDURE get_temp_var (u: U; type: Type; s: ByteSize; a: Alignment;</font></div><div><font face="Calibri, sans-serif"> n: Name := M3ID.NoID): x86Var =</font></div><div><font face="Calibri, sans-serif"> BEGIN</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> (* round size and alignment up to 4 *)</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> IF s < 4 THEN</font></div><div><font face="Calibri, sans-serif"> s := 4;</font></div><div><font face="Calibri, sans-serif"> END;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> IF a < 4 THEN</font></div><div><font face="Calibri, sans-serif"> a := 4;</font></div><div><font face="Calibri, sans-serif"> END;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">PROCEDURE create_temp_var (u: U; type: Type; s: ByteSize; a: Alignment;</font></div><div><font face="Calibri, sans-serif"> n: Name): x86Var =</font></div><div><font face="Calibri, sans-serif"> VAR v := NewVar(u, type, 0, s, a, n);</font></div><div><font face="Calibri, sans-serif"> BEGIN</font></div><div><font face="Calibri, sans-serif"> v.loc := VLoc.temp;</font></div><div><font face="Calibri, sans-serif"> v.parent := u.current_proc;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> u.current_proc.framesize := Word.And(u.current_proc.framesize + a - 1,</font></div><div><font face="Calibri, sans-serif"> Alignmask[a]);</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> INC(u.current_proc.framesize, s);</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> v.offset := -u.current_proc.framesize;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> RETURN v;</font></div><div><font face="Calibri, sans-serif"> END create_temp_var;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">which isn't clear by inspection...it actually looks like</font></div><div><font face="Calibri, sans-serif">zero size is allowed through commonly...in_proc is rare,</font></div><div><font face="Calibri, sans-serif">so create is common...assuming the frame is already aligned,</font></div><div><font face="Calibri, sans-serif">the size remains unchanged...</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">Relevant aside: I have been ignoring alignment.</font></div><div><font face="Calibri, sans-serif">I'm inclined to go with something like:</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><* ASSERT (size MOD alignment) = 0 *></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">If that ever fails, then I will change it to:</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">FUNCTION RoundUp(a, b: INTEGER): INTEGER =</font></div><div><font face="Calibri, sans-serif">BEGIN</font></div><div><font face="Calibri, sans-serif"> WITH c = a MOD b DO</font></div><div><font face="Calibri, sans-serif"> IF c # 0 THEN</font></div><div><font face="Calibri, sans-serif"> RETURN a + b - c;</font></div><div><font face="Calibri, sans-serif"> END;</font></div><div><font face="Calibri, sans-serif"> END;</font></div><div><font face="Calibri, sans-serif"> RETURN a;</font></div><div><font face="Calibri, sans-serif">END;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">size := RoundUp(size, alignment);</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">and then, more to the point, I'll go with:</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">IF size = 0 THEN</font></div><div><font face="Calibri, sans-serif"> size = 1;</font></div><div><font face="Calibri, sans-serif">END;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">I haven't dug into what the gcc backend would do here, too much</font></div><div><font face="Calibri, sans-serif">to dig through. :)</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">Thoughts?</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">I guess I should try both m3x86 and m3cc, and print the address</font></div><div><font face="Calibri, sans-serif">of these things????</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> - Jay</font></div><br><br><br><div style="font-family:Calibri, sans-serif;font-size:12pt"><div id="ecxSkyDrivePlaceholder"></div><hr id="ecxstopSpelling">From: <a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>To: <a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Date: Thu, 4 Oct 2012 06:13:28 +0000<br>Subject: [M3devel] zero sized structs?<br><br>
<style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:12pt;font-family:Calibri;}
--></style>
<div dir="ltr"><div><font face="Calibri, sans-serif">Building obliqrt I get:</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">***</font></div><div><font face="Calibri, sans-serif">*** runtime error:</font></div><div><font face="Calibri, sans-serif">*** <*ASSERT*> failed.</font></div><div><font face="Calibri, sans-serif">*** file "../src/M3C.m3", line 1768</font></div><div><font face="Calibri, sans-serif">***</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">PROCEDURE GetStructSizes_Declare(self: GetStructSizes_t; type: Type; byte_size: ByteSize): M3CG.Var =</font></div><div><font face="Calibri, sans-serif">BEGIN</font></div><div><font face="Calibri, sans-serif"> IF type = Type.Struct THEN</font></div><div><font face="Calibri, sans-serif"> <* ASSERT byte_size > 0 *></font></div><div><font face="Calibri, sans-serif"> self.sizes[self.count] := byte_size;</font></div><div><font face="Calibri, sans-serif"> INC(self.count);</font></div><div><font face="Calibri, sans-serif"> END;</font></div><div><font face="Calibri, sans-serif"> RETURN NIL;</font></div><div><font face="Calibri, sans-serif">END GetStructSizes_Declare;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">due to presumably:</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">PROCEDURE ApplyThreadClosure (self: ObliqThreadClosure): REFANY =</font></div><div><font face="Calibri, sans-serif"> VAR noArgs: ARRAY [0 .. -1] OF ObValue.Val;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">...</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">PROCEDURE HandleWork (self: ObliqWork) =</font></div><div><font face="Calibri, sans-serif"> VAR noArgs: ARRAY [0 .. -1] OF ObValue.Val;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">..</font></div><div><font face="Calibri, sans-serif">PROCEDURE EvalThread ( self : PackageThread;</font></div><div><font face="Calibri, sans-serif">...</font></div><div><font face="Calibri, sans-serif">noArgs : ARRAY [0 .. -1] OF ObValue.Val;</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif">What is the meaning of this?</font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"><br></font></div><div><font face="Calibri, sans-serif"> - Jay</font></div><br><br> </div></div> </div>
</div></blockquote></div></div></div> </div></body>
</html>