<div dir="ltr">Previously it was impossible to create an alias with an offset into a global. It appears you've found a way to workaround the check in the verifier, and that understandably crashes LLVM.<div><br></div><div>
Rafael recently relaxed this restriction in trunk LLVM, so aliases can now be arbitrary constant expressions. It should support your example. It is now possible to represent some aliases in LLVM that cannot be compiled, so be careful.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 16, 2014 at 2:57 AM, sebastien deldon (PGI) <span dir="ltr"><<a href="mailto:sebastien.deldon@pgroup.com" target="_blank">sebastien.deldon@pgroup.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="color:#1f497d">Hi all,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">Given assert code in alias detection I’ve opted for a simplification in expressing field address :<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"<u></u><u></u></span></p>
<div class=""><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">%struct._dpowk_16 = type < { [32 x [32 x double]], [32 x [32 x double]], [32 x [32 x i64]] } ><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p></div><p class="MsoNormal"><span style="color:#1f497d">@_dpowk_16 = common global %struct._dpowk_16 zeroinitializer, align 16<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">@r_d_field = alias [32 x [32 x double]] * getelementptr (%struct._dpowk_16 * @_dpowk_16, i32 0, i32 1)<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">Now I’ve got following error from opt :<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">opt -O2 -S gblmod2.ll -o gblmod2.opt.ll<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">opt: /home/sdeldon/tools/llvm/3.2/llvm-3.2.src/include/llvm/Support/Casting.h:208: typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X = llvm::GlobalValue, Y = llvm::Value*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.<u></u><u></u></span></p>
<div class=""><p class="MsoNormal"><span style="color:#1f497d">0 opt 0x00000000010e3abf<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">1 opt 0x00000000010e5a22<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">2 libpthread.so.0 0x0000003dd0a0f710<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">3 libc.so.6 0x0000003dd0232925 gsignal + 53<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">4 libc.so.6 0x0000003dd0234105 abort + 373<u></u><u></u></span></p></div><p class="MsoNormal"><span style="color:#1f497d">5 libc.so.6 0x0000003dd022ba4e<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">6 libc.so.6 0x0000003dd022bb10 __assert_perror_fail + 0<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">7 opt 0x0000000000bf238f<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">8 opt 0x0000000001083af1 llvm::MPPassManager::runOnModule(llvm::Module&) + 497<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">9 opt 0x0000000001083c6b llvm::PassManagerImpl::run(llvm::Module&) + 171<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">10 opt 0x000000000053b307 main + 6999<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">11 libc.so.6 0x0000003dd021ed1d __libc_start_main + 253<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">12 opt 0x000000000052c5c9<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">Stack dump:<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">0. Program arguments: opt -O2 -S gblmod2.ll -o gblmod2.opt.ll <u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">1. Running pass 'Global Variable Optimizer' on module 'gblmod2.ll'.<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d">Is it a BUG ?<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d">Seb<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> sebastien deldon (PGI) <br>
<b>Sent:</b> Friday, June 13, 2014 11:05 AM<br><b>To:</b> llvmdev<br><b>Subject:</b> Is it possible to create a variable that aliases a field in a struct ?<u></u><u></u></span></p></div></div><div><div class="h5"><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">Hi all,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I would like to create a variable that aliases a field in a struct like :<u></u><u></u></p><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">%struct._dpowk_16 = type < { [32 x [32 x double]], [32 x [32 x double]], [32 x [32 x i64]] } ><u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">@_dpowk_16 = common addrspace(1) global %struct._dpowk_16 zeroinitializer, align 16<u></u><u></u></p>
<p class="MsoNormal">@r_d_alias = alias [32 x [32 x double]] addrspace(1) * bitcast (i8 addrspace(1) * getelementptr (i8 addrspace(1) * bitcast (%struct._dpowk_16 addrspace(1)* @_dpowk_16 to i8 addrspace(1) *), i64 8192) to [32 x [32 x double]] addrspace(1) * )<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">When I use opt I got following message :<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Aliasee should be either GlobalValue or bitcast of GlobalValue<u></u><u></u></p>
<p class="MsoNormal">[32 x [32 x double]] addrspace(1)* @r_d_alias<u></u><u></u></p><p class="MsoNormal">Broken module found, compilation aborted!<u></u><u></u></p><p class="MsoNormal">0 opt 0x00000000010e3abf<u></u><u></u></p>
<p class="MsoNormal">1 opt 0x00000000010e5a22<u></u><u></u></p><p class="MsoNormal">2 libpthread.so.0 0x0000003dd0a0f710<u></u><u></u></p><p class="MsoNormal">3 libc.so.6 0x0000003dd0232925 gsignal + 53<u></u><u></u></p>
<p class="MsoNormal">4 libc.so.6 0x0000003dd0234105 abort + 373<u></u><u></u></p><p class="MsoNormal">5 opt 0x00000000010a3e8a<u></u><u></u></p><p class="MsoNormal">6 opt 0x000000000107c654 llvm::FPPassManager::doFinalization(llvm::Module&) + 84<u></u><u></u></p>
<p class="MsoNormal">7 opt 0x000000000107df79 llvm::FunctionPassManagerImpl::doFinalization(llvm::Module&) + 105<u></u><u></u></p><p class="MsoNormal">8 opt 0x000000000053b25d main + 6829<u></u><u></u></p>
<p class="MsoNormal">9 libc.so.6 0x0000003dd021ed1d __libc_start_main + 253<u></u><u></u></p><p class="MsoNormal">10 opt 0x000000000052c5c9<u></u><u></u></p><p class="MsoNormal">Stack dump:<u></u><u></u></p>
<p style="margin-left:.75in"><u></u><span>0.<span style="font:7.0pt "Times New Roman""> </span></span><u></u>Program arguments: opt -O2 -S gblmod.ll -o gblmod.opt.ll<u></u><u></u></p><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">Is there a way to have a global value that reflects a field in a struct ?<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thanks for your answers<u></u><u></u></p>
<p class="MsoNormal">Seb<u></u><u></u></p></div></div></div><div><div class="h5">
<div>
<hr>
</div>
<div>This email message is for the sole use of the intended recipient(s) and may
contain confidential information. Any unauthorized review, use, disclosure
or distribution is prohibited. If you are not the intended recipient,
please contact the sender by reply email and destroy all copies of the original
message. </div>
<div>
<hr>
</div>
</div></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>