<div dir="ltr"><div>Emitting calls to these functions (written in an .ll file linked in) works fine, and does the right thing.<br></div><div><div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">%Any = type { i8*, i32 }</font></div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">define dllexport void @setGlobal(%Any* %ptr, %Any %value) {</font></div><div><font face="monospace, monospace">  store %Any %value, %Any* %ptr</font></div><div><font face="monospace, monospace">  ret void</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">define dllexport %Any @getGlobal(%Any* %ptr) {</font></div><div><font face="monospace, monospace">  %val = load %Any, %Any* %ptr</font></div><div><font face="monospace, monospace">  ret %Any %val</font></div><div><font face="monospace, monospace">}</font></div></div><div><br>Trying to replace the setGlobal call with what should be equivalent</div><div><br></div><div><font face="monospace, monospace">builder.CreateStore(value, ptr)</font></div><div><br></div><div>results in what should end up in the second (i32) slot being stored in the first (i8*).</div><div><br></div><div>I've added ::dump() calls where the CreateStore is, and this is what I get:</div><div><br><font face="monospace, monospace">{ i8*, i32 } { i8* @FixnumClass, i32 32 } ; for value<br>@foo = external global { i8*, i32 } ; for ptr</font><br></div><div><br></div><div>Even more bizarrely trying to replace the getGlobal call with</div><div><br></div><div><font face="monospace, monospace">builder.CreateLoad(val)</font></div><div><br></div><div>results in what has been stored in the first (i8*) slot being loaded correctly, but the second (i32) getting garbage out despite the correct value being stored in memory. Dump call there reports the @foo pointer identically.<br><br><div><font face="arial, helvetica, sans-serif">This is using LLVM 4.0.0</font></div></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><span style="font-family:arial,helvetica,sans-serif">Just so I'm not leaving anything out, what follows are IR dumps of the sample functions using either the direct store / load, or the setGlobal getGlobal</span></div><div><span style="font-family:arial,helvetica,sans-serif">functions. As far as I can tell they should do exactly the same thing...<br><br></span></div><div><div><font face="monospace, monospace">; Does NOT do the right thing</font></div><div><div><font face="monospace, monospace">define { i8*, i32 } @"__anonToplevel/2"() {</font></div><div><font face="monospace, monospace">entry:</font></div><div><font face="monospace, monospace">  %.unpack = load i8*, i8** getelementptr inbounds ({ i8*, i32 }, { i8*, i32 }* @foo, i32 0, i32 0), align 4</font></div><div><font face="monospace, monospace">  %0 = insertvalue { i8*, i32 } undef, i8* %.unpack, 0</font></div><div><font face="monospace, monospace">  %.unpack1 = load i32, i32* getelementptr inbounds ({ i8*, i32 }, { i8*, i32 }* @foo, i32 0, i32 1), align 4</font></div><div><font face="monospace, monospace">  %1 = insertvalue { i8*, i32 } %0, i32 %.unpack1, 1</font></div><div><font face="monospace, monospace">  ret { i8*, i32 } %1</font></div><div><font face="monospace, monospace">}</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">; Does NOT do the right thing</font></div><div><div><font face="monospace, monospace">define { i8*, i32 } @"__anonToplevel/0"() {</font></div><div><font face="monospace, monospace">entry:</font></div><div><span style="font-family:monospace,monospace">  store i8* @FixnumClass, i8** getelementptr inbounds ({ i8*, i32 }, { i8*, i32 }* @foo, i32 0, i32 0), align 4</span><br></div><div><font face="monospace, monospace">  store i32 123, i32* getelementptr inbounds ({ i8*, i32 }, { i8*, i32 }* @foo, i32 0, i32 1), align 4</font></div><div><span style="font-family:monospace,monospace">  ret { i8*, i32 } { i8* @FixnumClass, i32 123 }</span><br></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div></div><div><font face="monospace, monospace">; DOES the right thing</font></div><div><font face="monospace, monospace"><div>define { i8*, i32 } @"__anonToplevel/0"() {</div><div>entry:</div><div>  call void @setGlobal({ i8*, i32 }* nonnull @foo, { i8*, i32 } { i8* @FixnumClass, i32 123 })<br></div><div>  ret { i8*, i32 } { i8* @FixnumClass, i32 123 }<br></div><div>}</div><div><br></div><div>; DOES the right thing</div><div><div><div>define { i8*, i32 } @"__anonToplevel/1"() {</div><div>entry:</div><div>  %0 = call { i8*, i32 } @getGlobal({ i8*, i32 }* nonnull @foo)</div><div>  ret { i8*, i32 } %0</div><div>}</div></div></div><div><br></div><div><div style="font-family:arial,sans-serif"><span style="font-family:arial,helvetica,sans-serif">I'm at my wit's end. Any hints as to what I might be messing up would be much appreciated. I expect it is something ridiculously obvious...</span><br style="font-family:arial,helvetica,sans-serif"></div></div><div><br></div></font></div><font face="arial, helvetica, sans-serif">Cheers,</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"> -- nikodemus</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><br></div></div></div>