<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Return value is garbage after call</title>
		<link>http://www.allegro.cc/forums/view/616911</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 30 May 2017 05:02:54 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>Problem:</b> Method <span class="source-code">Model::get_color</span>, from my library Kvre, returns a <span class="source-code">glm::vec4</span>. In a different library, Chomsky, which calls the method in Kvre, the return value is correct. In an application, Zeitgeist, which also calls the method in Kvre, the return value is garbage.</p><ol><li><p>There is no memory corruption. I&#39;ve run the program through Valgrind.
</p></li><li><p>The value is correct before being returned. In other words, if I print the value from <span class="source-code">Model::get_color</span> prior to returning, it&#39;s correct, but in Zeitgeist, it&#39;s not.
</p></li><li><p>An identical function in Chomsky and Zeitgiest--to print the color value--compiles differently.
</p></li><li><p>If the method returns a <span class="source-code">glm::vec3</span>, the result is correct.
</p></li><li><p>Zeitgeist depends on Chomsky and Kvre. Chomsky depends on Kvre.
</p></li><li><p><tt>glm::vec4</tt> is from the <a href="http://glm.g-truc.net/0.9.8/index.html">OpenGL Mathematics</a> library. As far as I know, it&#39;s internally an SSE vector type on my platform.</p></li></ol><p>I cannot produce a simple test case independent on my large code base, so bear with me.</p><p>Here&#39;s the functions:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="c">// in Kvre</span>
<span class="number">  2</span>glm::vec4 kvre::Model::get_color<span class="k2">(</span>std::size_t <a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a><span class="k2">)</span> <span class="k1">const</span>
<span class="number">  3</span><span class="k2">{</span>
<span class="number">  4</span>  <span class="k1">if</span> <span class="k2">(</span>this-&gt;colors.empty<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  5</span>  <span class="k2">{</span>
<span class="number">  6</span>    std::size_t num_vertices <span class="k3">=</span> this-&gt;get_num_vertices<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>    this-&gt;colors.resize<span class="k2">(</span>this-&gt;get_num_vertices<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>    <span class="k1">for</span> <span class="k2">(</span>std::size_t i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> num_vertices<span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span>
<span class="number">  9</span>    <span class="k2">{</span>
<span class="number"> 10</span>      this-&gt;colors<span class="k2">[</span>i<span class="k2">]</span> <span class="k3">=</span> this-&gt;profile-&gt;get_model_vertex_color<span class="k2">(</span>
<span class="number"> 11</span>        <span class="k3">*</span>this-&gt;colors_fetcher, i<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    <span class="k2">}</span>
<span class="number"> 13</span>  <span class="k2">}</span>
<span class="number"> 14</span>
<span class="number"> 15</span>  <span class="k1">if</span> <span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a> <span class="k3">=</span><span class="k3">=</span> <span class="n">0xffffffff</span><span class="k2">)</span>
<span class="number"> 16</span>  <span class="k2">{</span>
<span class="number"> 17</span>    <span class="k1">auto</span> result <span class="k3">=</span> this-&gt;colors<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">;</span>
<span class="number"> 18</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span>
<span class="number"> 19</span>      <span class="s">"result: %f %f %f %f\n"</span>,
<span class="number"> 20</span>      result.x, result.y, result.z, result.w<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>    <span class="k1">return</span> result<span class="k2">;</span>
<span class="number"> 22</span>  <span class="k2">}</span>
<span class="number"> 23</span>
<span class="number"> 24</span>  <span class="k1">return</span> this-&gt;colors<span class="k2">[</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_470.html" target="_blank">index</a><span class="k2">]</span><span class="k2">;</span>
<span class="number"> 25</span><span class="k2">}</span>
<span class="number"> 26</span>
<span class="number"> 27</span><span class="c">// in Zeitgeist/Chomsky</span>
<span class="number"> 28</span><span class="k1">static</span> <span class="k1">void</span> print_model_color<span class="k2">(</span><span class="k1">const</span> kvre::Model<span class="k3">*</span> model<span class="k2">)</span>
<span class="number"> 29</span><span class="k2">{</span>
<span class="number"> 30</span>  glm::vec4 color <span class="k3">=</span> model-&gt;get_color<span class="k2">(</span><span class="n">0xffffffff</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%p color: %f %f %f %f\n"</span>, model, color.r, color.g, color.b, color.a<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span><span class="k2">}</span>
</div></div><p>

(The check is for debugging. My code processes hundreds of thousands of vertices, so printing each one is unwise.)</p><p>Here&#39;s the disassembly of the <span class="source-code">print_model_color</span> from Zeitgeist:</p><pre>
zeitgeist`print_model_color:
    0x41d740 &lt;+0&gt;:  pushq  %rbp
    0x41d741 &lt;+1&gt;:  movq   %rsp, %rbp
    0x41d744 &lt;+4&gt;:  subq   $0x20, %rsp
    0x41d748 &lt;+8&gt;:  movl   $0xffffffff, %eax         ; imm = 0xFFFFFFFF 
    0x41d74d &lt;+13&gt;: movl   %eax, %esi
    0x41d74f &lt;+15&gt;: movq   %rdi, -0x8(%rbp)
-&gt;  0x41d753 &lt;+19&gt;: movq   -0x8(%rbp), %rdi
    0x41d757 &lt;+23&gt;: callq  0x418664                  ; symbol stub for: kvre::Model::get_color(unsigned long) const
    0x41d75c &lt;+28&gt;: movabsq $0x4ba912, %rdi           ; imm = 0x4BA912 
    0x41d766 &lt;+38&gt;: movq   %rax, -0x18(%rbp)
    0x41d76a &lt;+42&gt;: movq   %rdx, -0x10(%rbp)
    0x41d76e &lt;+46&gt;: movq   -0x8(%rbp), %rsi
    0x41d772 &lt;+50&gt;: cvtss2sd -0x18(%rbp), %xmm0
    0x41d777 &lt;+55&gt;: cvtss2sd -0x14(%rbp), %xmm1
    0x41d77c &lt;+60&gt;: cvtss2sd -0x10(%rbp), %xmm2
    0x41d781 &lt;+65&gt;: cvtss2sd -0xc(%rbp), %xmm3
    0x41d786 &lt;+70&gt;: movb   $0x4, %al
    0x41d788 &lt;+72&gt;: callq  0x4186d4                  ; symbol stub for: printf
    0x41d78d &lt;+77&gt;: movl   %eax, -0x1c(%rbp)
    0x41d790 &lt;+80&gt;: addq   $0x20, %rsp
    0x41d794 &lt;+84&gt;: popq   %rbp
    0x41d795 &lt;+85&gt;: retq
</pre><p>

And here&#39;s the disassembly of the method from Chomsky:</p><pre>
libChomsky.so`print_model_color:
    0x801096d00 &lt;+0&gt;:  pushq  %rbp
    0x801096d01 &lt;+1&gt;:  movq   %rsp, %rbp
    0x801096d04 &lt;+4&gt;:  subq   $0x30, %rsp
    0x801096d08 &lt;+8&gt;:  leaq   0x50fc1(%rip), %rax
    0x801096d0f &lt;+15&gt;: movq   %rdi, -0x8(%rbp)
-&gt;  0x801096d13 &lt;+19&gt;: movl   $0xffffffff, %ecx         ; imm = 0xFFFFFFFF 
    0x801096d18 &lt;+24&gt;: movl   %ecx, %esi
    0x801096d1a &lt;+26&gt;: movq   %rax, -0x20(%rbp)
    0x801096d1e &lt;+30&gt;: callq  0x801084f0c               ; symbol stub for: kvre::Model::get_color(unsigned long) const
    0x801096d23 &lt;+35&gt;: movlps %xmm0, -0x18(%rbp)
    0x801096d27 &lt;+39&gt;: movlps %xmm1, -0x10(%rbp)
    0x801096d2b &lt;+43&gt;: movq   -0x8(%rbp), %rsi
    0x801096d2f &lt;+47&gt;: cvtss2sd -0x18(%rbp), %xmm0
    0x801096d34 &lt;+52&gt;: cvtss2sd -0x14(%rbp), %xmm1
    0x801096d39 &lt;+57&gt;: cvtss2sd -0x10(%rbp), %xmm2
    0x801096d3e &lt;+62&gt;: cvtss2sd -0xc(%rbp), %xmm3
    0x801096d43 &lt;+67&gt;: movq   -0x20(%rbp), %rdi
    0x801096d47 &lt;+71&gt;: movb   $0x4, %al
    0x801096d49 &lt;+73&gt;: callq  0x801084dec               ; symbol stub for: printf
    0x801096d4e &lt;+78&gt;: movl   %eax, -0x24(%rbp)
    0x801096d51 &lt;+81&gt;: addq   $0x30, %rsp
    0x801096d55 &lt;+85&gt;: popq   %rbp
    0x801096d56 &lt;+86&gt;: retq
</pre><p>

I know little about x86 assembly, but I can tell there&#39;s a difference in how the return value is stored.</p><p>Results of first few calls from Chomsky:</p><pre>
result: 0.133333 0.156863 0.211765 1.000000
0x80cf39700 color: 0.133333 0.156863 0.211765 1.000000
result: 0.070588 0.066667 0.066667 1.000000
0x80cf39800 color: 0.070588 0.066667 0.066667 1.000000
result: 0.211765 0.176471 0.133333 1.000000
0x80cf39900 color: 0.211765 0.176471 0.133333 1.000000
</pre><p>

And from Zeitgeist:</p><pre>
result: 0.133333 0.156863 0.211765 1.000000
0x80cf39700 color: 0.000000 0.000000 0.000000 0.000000
result: 0.070588 0.066667 0.066667 1.000000
0x80cf39800 color: 0.000000 0.000000 0.000000 0.000000
result: 0.211765 0.176471 0.133333 1.000000
0x80cf39900 color: 0.000000 0.000000 0.000000 0.000000
</pre><p>

The models are identical (see the pointer), but the return value is not.</p><p>Why is the method returning garbage in Zeitgeist but not Chomsky?</p><p>I have a hunch it&#39;s to do with some compiler or linker settings causing incorrect code generation, but I&#39;ve tried various permutations and exhausted those options I&#39;m aware of.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Sat, 27 May 2017 21:13:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you&#39;re suspecting such low level bugs, it&#39;s worthwhile to try out other compilers (and compiler versions).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 27 May 2017 21:48:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you post the assembly for the get_color functions produced by each of those? The disassembly for the print_color looks fine on it&#39;s own, so I&#39;d have to see what the get_color function is setting the values to. If you want a rundown of the print_color assembly I can do that for you, just let me know.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (someone972)</author>
		<pubDate>Sat, 27 May 2017 22:50:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616911/1030616#target">SiegeLord</a> said:</div><div class="quote"><p> If you&#39;re suspecting such low level bugs, it&#39;s worthwhile to try out other compilers (and compiler versions). </p></div></div><p>Tested it with clang 3.8 and 5.0 without any difference. Will switch to Ubuntu and test it with GCC 6 soon.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616911/1030617#target">someone972</a> said:</div><div class="quote"><p> Can you post the assembly for the get_color functions produced by each of those? The disassembly for the print_color looks fine on it&#39;s own, so I&#39;d have to see what the get_color function is setting the values to. If you want a rundown of the print_color assembly I can do that for you, just let me know. </p></div></div><p>Sure thing:</p><pre>
libKvre.so`kvre::Model::get_color:
    0x801cbcbd0 &lt;+0&gt;:   pushq  %rbp
    0x801cbcbd1 &lt;+1&gt;:   movq   %rsp, %rbp
    0x801cbcbd4 &lt;+4&gt;:   subq   $0xa0, %rsp
    0x801cbcbdb &lt;+11&gt;:  movq   %rdi, -0x50(%rbp)
    0x801cbcbdf &lt;+15&gt;:  movq   %rsi, -0x58(%rbp)
    0x801cbcbe3 &lt;+19&gt;:  movq   -0x50(%rbp), %rsi
-&gt;  0x801cbcbe7 &lt;+23&gt;:  movq   %rsi, %rdi
    0x801cbcbea &lt;+26&gt;:  addq   $0x90, %rdi
    0x801cbcbf1 &lt;+33&gt;:  movq   %rdi, -0x38(%rbp)
    0x801cbcbf5 &lt;+37&gt;:  movq   -0x38(%rbp), %rdi
    0x801cbcbf9 &lt;+41&gt;:  movq   (%rdi), %rax
    0x801cbcbfc &lt;+44&gt;:  cmpq   0x8(%rdi), %rax
    0x801cbcc00 &lt;+48&gt;:  movq   %rsi, -0x80(%rbp)
    0x801cbcc04 &lt;+52&gt;:  jne    0x801cbcce3               ; &lt;+275&gt; at model.cpp:86
    0x801cbcc0a &lt;+58&gt;:  movq   -0x80(%rbp), %rdi
    0x801cbcc0e &lt;+62&gt;:  callq  0x801cbb484               ; symbol stub for: kvre::Model::get_num_vertices() const
    0x801cbcc13 &lt;+67&gt;:  movq   %rax, -0x60(%rbp)
    0x801cbcc17 &lt;+71&gt;:  movq   -0x80(%rbp), %rax
    0x801cbcc1b &lt;+75&gt;:  addq   $0x90, %rax
    0x801cbcc21 &lt;+81&gt;:  movq   -0x80(%rbp), %rdi
    0x801cbcc25 &lt;+85&gt;:  movq   %rax, -0x88(%rbp)
    0x801cbcc2c &lt;+92&gt;:  callq  0x801cbb484               ; symbol stub for: kvre::Model::get_num_vertices() const
    0x801cbcc31 &lt;+97&gt;:  movq   -0x88(%rbp), %rdi
    0x801cbcc38 &lt;+104&gt;: movq   %rax, %rsi
    0x801cbcc3b &lt;+107&gt;: callq  0x801cbb0a4               ; symbol stub for: std::__1::vector&lt;glm::tvec4&lt;float, (glm::precision)0&gt;, std::__1::allocator&lt;glm::tvec4&lt;float, (glm::precision)0&gt; &gt; &gt;::resize(unsigned long)
    0x801cbcc40 &lt;+112&gt;: movq   $0x0, -0x68(%rbp)
    0x801cbcc48 &lt;+120&gt;: movq   -0x68(%rbp), %rax
    0x801cbcc4c &lt;+124&gt;: cmpq   -0x60(%rbp), %rax
    0x801cbcc50 &lt;+128&gt;: jae    0x801cbccde               ; &lt;+270&gt; at model.cpp:86
    0x801cbcc56 &lt;+134&gt;: movq   -0x80(%rbp), %rax
    0x801cbcc5a &lt;+138&gt;: addq   $0x90, %rax
    0x801cbcc60 &lt;+144&gt;: movq   -0x68(%rbp), %rcx
    0x801cbcc64 &lt;+148&gt;: movq   %rax, -0x8(%rbp)
    0x801cbcc68 &lt;+152&gt;: movq   %rcx, -0x10(%rbp)
    0x801cbcc6c &lt;+156&gt;: movq   -0x8(%rbp), %rax
    0x801cbcc70 &lt;+160&gt;: movq   (%rax), %rax
    0x801cbcc73 &lt;+163&gt;: shlq   $0x4, %rcx
    0x801cbcc77 &lt;+167&gt;: addq   %rcx, %rax
    0x801cbcc7a &lt;+170&gt;: movq   -0x80(%rbp), %rcx
    0x801cbcc7e &lt;+174&gt;: movq   0x30(%rcx), %rdx
    0x801cbcc82 &lt;+178&gt;: movq   0x48(%rcx), %rsi
    0x801cbcc86 &lt;+182&gt;: movq   (%rdx), %rdi
    0x801cbcc89 &lt;+185&gt;: movq   0x30(%rdi), %rdi
    0x801cbcc8d &lt;+189&gt;: movq   -0x68(%rbp), %r8
    0x801cbcc91 &lt;+193&gt;: movq   %rdi, -0x90(%rbp)
    0x801cbcc98 &lt;+200&gt;: movq   %rdx, %rdi
    0x801cbcc9b &lt;+203&gt;: movq   %r8, %rdx
    0x801cbcc9e &lt;+206&gt;: movq   -0x90(%rbp), %r8
    0x801cbcca5 &lt;+213&gt;: movq   %rax, -0x98(%rbp)
    0x801cbccac &lt;+220&gt;: callq  *%r8
    0x801cbccaf &lt;+223&gt;: movlps %xmm0, -0x78(%rbp)
    0x801cbccb3 &lt;+227&gt;: movlps %xmm1, -0x70(%rbp)
    0x801cbccb7 &lt;+231&gt;: movq   -0x78(%rbp), %rax
    0x801cbccbb &lt;+235&gt;: movq   -0x98(%rbp), %rcx
    0x801cbccc2 &lt;+242&gt;: movq   %rax, (%rcx)
    0x801cbccc5 &lt;+245&gt;: movq   -0x70(%rbp), %rax
    0x801cbccc9 &lt;+249&gt;: movq   %rax, 0x8(%rcx)
    0x801cbcccd &lt;+253&gt;: movq   -0x68(%rbp), %rax
    0x801cbccd1 &lt;+257&gt;: addq   $0x1, %rax
    0x801cbccd5 &lt;+261&gt;: movq   %rax, -0x68(%rbp)
    0x801cbccd9 &lt;+265&gt;: jmp    0x801cbcc48               ; &lt;+120&gt; at model.cpp:81
    0x801cbccde &lt;+270&gt;: jmp    0x801cbcce3               ; &lt;+275&gt; at model.cpp:86
    0x801cbcce3 &lt;+275&gt;: movl   $0xffffffff, %eax         ; imm = 0xFFFFFFFF 
    0x801cbcce8 &lt;+280&gt;: movl   %eax, %ecx
    0x801cbccea &lt;+282&gt;: cmpq   %rcx, -0x58(%rbp)
    0x801cbccee &lt;+286&gt;: jne    0x801cbcd55               ; &lt;+389&gt; at model.cpp:97
    0x801cbccf4 &lt;+292&gt;: leaq   0xeb26(%rip), %rdi        ;  + 545
    0x801cbccfb &lt;+299&gt;: movq   -0x80(%rbp), %rax
    0x801cbccff &lt;+303&gt;: addq   $0x90, %rax
    0x801cbcd05 &lt;+309&gt;: movq   %rax, -0x18(%rbp)
    0x801cbcd09 &lt;+313&gt;: movq   $0x0, -0x20(%rbp)
    0x801cbcd11 &lt;+321&gt;: movq   -0x18(%rbp), %rax
    0x801cbcd15 &lt;+325&gt;: movq   -0x20(%rbp), %rcx
    0x801cbcd19 &lt;+329&gt;: shlq   $0x4, %rcx
    0x801cbcd1d &lt;+333&gt;: addq   (%rax), %rcx
    0x801cbcd20 &lt;+336&gt;: movq   (%rcx), %rax
    0x801cbcd23 &lt;+339&gt;: movq   %rax, -0x48(%rbp)
    0x801cbcd27 &lt;+343&gt;: movq   0x8(%rcx), %rax
    0x801cbcd2b &lt;+347&gt;: movq   %rax, -0x40(%rbp)
    0x801cbcd2f &lt;+351&gt;: cvtss2sd -0x48(%rbp), %xmm0
    0x801cbcd34 &lt;+356&gt;: cvtss2sd -0x44(%rbp), %xmm1
    0x801cbcd39 &lt;+361&gt;: cvtss2sd -0x40(%rbp), %xmm2
    0x801cbcd3e &lt;+366&gt;: cvtss2sd -0x3c(%rbp), %xmm3
    0x801cbcd43 &lt;+371&gt;: movb   $0x4, %al
    0x801cbcd45 &lt;+373&gt;: callq  0x801cbb004               ; symbol stub for: printf
    0x801cbcd4a &lt;+378&gt;: movl   %eax, -0x9c(%rbp)
    0x801cbcd50 &lt;+384&gt;: jmp    0x801cbcd89               ; &lt;+441&gt; at model.cpp:98
    0x801cbcd55 &lt;+389&gt;: movq   -0x80(%rbp), %rax
    0x801cbcd59 &lt;+393&gt;: addq   $0x90, %rax
    0x801cbcd5f &lt;+399&gt;: movq   -0x58(%rbp), %rcx
    0x801cbcd63 &lt;+403&gt;: movq   %rax, -0x28(%rbp)
    0x801cbcd67 &lt;+407&gt;: movq   %rcx, -0x30(%rbp)
    0x801cbcd6b &lt;+411&gt;: movq   -0x28(%rbp), %rax
    0x801cbcd6f &lt;+415&gt;: movq   -0x30(%rbp), %rcx
    0x801cbcd73 &lt;+419&gt;: shlq   $0x4, %rcx
    0x801cbcd77 &lt;+423&gt;: addq   (%rax), %rcx
    0x801cbcd7a &lt;+426&gt;: movq   (%rcx), %rax
    0x801cbcd7d &lt;+429&gt;: movq   %rax, -0x48(%rbp)
    0x801cbcd81 &lt;+433&gt;: movq   0x8(%rcx), %rax
    0x801cbcd85 &lt;+437&gt;: movq   %rax, -0x40(%rbp)
    0x801cbcd89 &lt;+441&gt;: movq   -0x48(%rbp), %xmm0        ; xmm0 = mem[0],zero 
    0x801cbcd8e &lt;+446&gt;: movq   -0x40(%rbp), %xmm1        ; xmm1 = mem[0],zero 
    0x801cbcd93 &lt;+451&gt;: addq   $0xa0, %rsp
    0x801cbcd9a &lt;+458&gt;: popq   %rbp
    0x801cbcd9b &lt;+459&gt;: retq 
</pre><p>

Both Chomsky and Zeitgeist call this same method.</p><p>(<tt>kvre::Model::get_color</tt> starts on line 75, if that helps mapping lines to instructions.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Sat, 27 May 2017 23:18:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What compiler are you using for the get_color library, and which one are you using for each of the other two functions? It looks like you need to explicitly state the calling convention because the one that&#39;s printing zeros looks to be using System V AMD64 ABI (standard for linux?). Not sure what the get_color convention is, but since it&#39;s returning in xmm0/1 it&#39;s not the same.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (someone972)</author>
		<pubDate>Sat, 27 May 2017 23:34:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m using the same compiler for everything (Chomsky, Zeitgeist, and Kvre): Clang 3.8 on FreeBSD 11. The build commands all use <tt>/usr/bin/CC</tt>.</p><p>I wonder if I&#39;m screwing something up with CMake, but... With absolutely no changes it compiles and works just fine on Ubuntu with GCC 6-something.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Sat, 27 May 2017 23:46:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you tried using Clang&#39;s static analyzer? (a simple command line switch) </p><p>[edit]</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616911/1030615#target">Aaron Bolyard</a> said:</div><div class="quote"><p>
There is no memory corruption. I&#39;ve run the program through Valgrind.
</p></div></div><p>
Valgrind does not guarantee there is no corruption. Have you tried the hundreds of additional flags/checks that can be turned on with Valgrind?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sun, 28 May 2017 03:27:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>someone972, I tried compiling Kvre manually (instead of using CMake) and it produces different code, which works:</p><pre>
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x50(%rbp)
movq %rsi, -0x58(%rbp)
movq -0x50(%rbp), %rsi
movq %rsi, %rdi
addq $0x90, %rdi
movq %rdi, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
cmpq 0x8(%rdi), %rax
movq %rsi, -0x80(%rbp)
jne 0x801cbcce3 ; &lt;+275&gt; at model.cpp:86
movq -0x80(%rbp), %rdi
callq 0x801cbb484 ; symbol stub for: kvre::Model::get_num_vertices() const
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq -0x80(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x801cbb484 ; symbol stub for: kvre::Model::get_num_vertices() const
movq -0x88(%rbp), %rdi
movq %rax, %rsi
resize(unsigned long)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x801cbccde ; &lt;+270&gt; at model.cpp:86
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq -0x68(%rbp), %rcx
movq %rax, -0x8(%rbp)
movq %rcx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x80(%rbp), %rcx
movq 0x30(%rcx), %rdx
movq 0x48(%rcx), %rsi
movq (%rdx), %rdi
movq 0x30(%rdi), %rdi
movq -0x68(%rbp), %r8
movq %rdi, -0x90(%rbp)
movq %rdx, %rdi
movq %r8, %rdx
movq -0x90(%rbp), %r8
movq %rax, -0x98(%rbp)
callq *%r8
movlps %xmm0, -0x78(%rbp)
movlps %xmm1, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rax, (%rcx)
movq -0x70(%rbp), %rax
movq %rax, 0x8(%rcx)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x801cbcc48 ; &lt;+120&gt; at model.cpp:81
jmp 0x801cbcce3 ; &lt;+275&gt; at model.cpp:86
movl $0xffffffff, %eax ; imm = 0xFFFFFFFF 
movl %eax, %ecx
cmpq %rcx, -0x58(%rbp)
jne 0x801cbcd55 ; &lt;+389&gt; at model.cpp:97
leaq 0xeb26(%rip), %rdi ; + 545
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq (%rax), %rcx
movq (%rcx), %rax
movq %rax, -0x48(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x40(%rbp)
cvtss2sd -0x48(%rbp), %xmm0
cvtss2sd -0x44(%rbp), %xmm1
cvtss2sd -0x40(%rbp), %xmm2
cvtss2sd -0x3c(%rbp), %xmm3
movb $0x4, %al
callq 0x801cbb004 ; symbol stub for: printf
movl %eax, -0x9c(%rbp)
jmp 0x801cbcd89 ; &lt;+441&gt; at model.cpp:98
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq -0x58(%rbp), %rcx
movq %rax, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq (%rax), %rcx
movq (%rcx), %rax
movq %rax, -0x48(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %xmm0 ; xmm0 = mem[0],zero 
movq -0x40(%rbp), %xmm1 ; xmm1 = mem[0],zero 
addq $0xa0, %rsp
popq %rbp
retq
</pre><p>

(The old, formatted the same, for reference):</p><div class="spoiler"><p>
</p><pre>
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x50(%rbp)
movq %rsi, -0x58(%rbp)
movq -0x50(%rbp), %rsi
movq %rsi, %rdi
addq $0x90, %rdi
movq %rdi, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
cmpq 0x8(%rdi), %rax
movq %rsi, -0x80(%rbp)
jne 0x801cbc885 ; &lt;+293&gt; at model.cpp:86
movq -0x80(%rbp), %rdi
callq 0x801cbb3cc ; symbol stub for: kvre::Model::get_num_vertices() const
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq -0x80(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x801cbb3cc ; symbol stub for: kvre::Model::get_num_vertices() const
movq -0x88(%rbp), %rdi
movq %rax, %rsi
resize(unsigned long)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x801cbc880 ; &lt;+288&gt; at model.cpp:86
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq -0x68(%rbp), %rcx
movq %rax, -0x8(%rbp)
movq %rcx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq (%rax), %rcx
movq -0x80(%rbp), %rax
movq 0x30(%rax), %rdx
movq (%rdx), %rsi
movq 0x30(%rsi), %rsi
movq 0x48(%rax), %rdi
movq -0x68(%rbp), %r8
movq %rdi, -0x90(%rbp)
movq %rdx, %rdi
movq -0x90(%rbp), %rdx
movq %rsi, -0x98(%rbp)
movq %rdx, %rsi
movq %r8, %rdx
movq -0x98(%rbp), %r8
movq %rcx, -0xa0(%rbp)
callq *%r8
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rax, (%rcx)
movq -0x70(%rbp), %rax
movq %rax, 0x8(%rcx)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x801cbc7d8 ; &lt;+120&gt; at model.cpp:81
jmp 0x801cbc885 ; &lt;+293&gt; at model.cpp:86
movl $0xffffffff, %eax ; imm = 0xFFFFFFFF 
movl %eax, %ecx
cmpq %rcx, -0x58(%rbp)
jne 0x801cbc8f7 ; &lt;+407&gt; at model.cpp:97
leaq 0xedc0(%rip), %rdi ; + 413
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq (%rax), %rcx
movq (%rcx), %rax
movq %rax, -0x48(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x40(%rbp)
cvtss2sd -0x48(%rbp), %xmm0
cvtss2sd -0x44(%rbp), %xmm1
cvtss2sd -0x40(%rbp), %xmm2
cvtss2sd -0x3c(%rbp), %xmm3
movb $0x4, %al
callq 0x801cbaf5c ; symbol stub for: printf
movl %eax, -0xa4(%rbp)
jmp 0x801cbc92b ; &lt;+459&gt; at model.cpp:98
movq -0x80(%rbp), %rax
addq $0x90, %rax
movq -0x58(%rbp), %rcx
movq %rax, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq (%rax), %rcx
movq (%rcx), %rax
movq %rax, -0x48(%rbp)
movq 0x8(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rdx
addq $0xb0, %rsp
popq %rbp
retq
</pre><p>
</p></div><p>

I ran a diff and it appears to be handling return values differently, but I wouldn&#39;t even say I have a crude understanding of x86 assembly, so I&#39;m not certain.</p><p>I&#39;m not sure why CMake is making Clang generate bad code, but I&#39;m going to switch to a different build system regardless. I want to generate reproducible builds, for defensive reasons, so I&#39;m going to test Bazle first. If that fails, back to Premake...</p><p>At least I can make a working build, though:</p><p><span class="remote-thumbnail"><span class="json">{"name":"610904","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/4\/84d6aa90839758934758e79e747c5eb3.png","w":1290,"h":749,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/4\/84d6aa90839758934758e79e747c5eb3"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/8/4/84d6aa90839758934758e79e747c5eb3-240.jpg" alt="610904" width="240" height="139" /></span></p><p>(I&#39;m trying to make a utility that allows users to customize an online game&#39;s [RuneScape] drawing behavior. For example, making certain obnoxious MTX creatures render at 50% translucency or changing the GUI colors.)</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616911/1030622#target">Chris Katko</a> said:</div><div class="quote"><p> Have you tried using Clang&#39;s static analyzer? (a simple command line switch) </p></div></div><p>Using LLVM 5.0&#39;s static analyzer across my entire suite of libraries under the KOMPROMAT module, there were a whopping half-a-dozen minor errors, none of them related to my problem. I&#39;m surprised there were so few--I either ran the tool wrong or I&#39;m the best. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>  Valgrind does not guarantee there is no corruption. Have you tried the hundreds of additional flags/checks that can be turned on with Valgrind? </p></div></div><p>To be honest, no, but after I narrowed it down to a code generation problem, I stopped pursuing possible memory corruption. I make extensive use of modern C++ semantics like shared pointers, as well as using C++ containers whenever possible, so the scope of memory corruption is limited to a few specific places (marshaling graphics data, mostly).</p><p><b>edit:</b> I switched to Bazel and the code is generated correctly now. Cookies.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Mon, 29 May 2017 04:27:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Glad you were able to get something working. I&#39;ve not used clang, so I&#39;m not familiar with what makes it choose one calling convention over another in certain situations. Looks like a cool utility!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (someone972)</author>
		<pubDate>Tue, 30 May 2017 02:33:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you! I&#39;m going to do a write-up on it once I finish the thing.</p><p>There&#39;s so many interesting problems I&#39;ve had to solve. Not to mention the technical achievements born out of laziness...</p><p>For example, most of my development and testing is done snapshots of the OpenGL commands emitted by the game. I rarely run the game, yet I&#39;m able to rapidly test my changes by instantly loading a specific OpenGL draw state!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Erin Maus)</author>
		<pubDate>Tue, 30 May 2017 05:02:54 +0000</pubDate>
	</item>
</rss>
