<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Hi,</div><div><br class="webkit-block-placeholder"></div><div>On 2008-01-14, at 09:30, <a href="mailto:ac@tml.hut.fi">ac@tml.hut.fi</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello,<br>I'm trying to translate part of Java code in LLVM code. I have some problems with the "opaque type", I think because I did not understand how to use.<br>So, the java code is:<br><br>int[] ai;<br>....<br>ai = new int[1];<br></blockquote><div><br class="webkit-block-placeholder"></div><div>BTW, if the size of the array is not knowable at compile time, you'll want to type <font class="Apple-style-span" face="Courier">ai</font> as <font class="Apple-style-span" face="Courier">i32*</font> rather than <font class="Apple-style-span" face="Courier">[</font><i><font class="Apple-style-span" face="Courier">n</font></i><font class="Apple-style-span" face="Courier"> x i32]*</font>. Doing so will avoid abstract type wrangling.</div><br><blockquote type="cite">I am using LLVM API in this way:<br><br>//I create a pointer of Opaque type, because I don't know yet the array size!<br>OpaqueType* ot =  OpaqueType::get();<br>AllocaInst* ptr_addrOP = new AllocaInst(ot, "ai_addr", label_entry);<br><br>//I create pointer of Array type when it is initialized<br>ArrayType* art = ArrayType::get(Type::IntTy, 1);<br>AllocaInst* ptr_addrAr = new AllocaInst(art, "ai_addr", label_entry);<br><br>//I try to make concrete the abstract pointer<br>((PointerType*)ptr_addrOP -> getType()) ->  <br>typeBecameConcrete(ptr_addrAr-> getType());<br></blockquote><div><br class="webkit-block-placeholder"></div><div>The method you used is somewhat an implementation detail. You want to use this method to invoke the complete algorithm:</div><div><br class="webkit-block-placeholder"></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><a href="http://llvm.org/docs/ProgrammersManual.html#refineAbstractTypeTo">http://llvm.org/docs/ProgrammersManual.html#refineAbstractTypeTo</a></blockquote><div><br><blockquote type="cite">But "ptr_addrOP" type is still abstract and nothing changed, in the SymbolTable there are still both the pointers.<br></blockquote><div><br class="webkit-block-placeholder"></div><div>To avoid a dangling pointer, you'll need to use a <font class="Apple-style-span" face="Courier">PATypeHolder</font> (PA for <span class="Apple-style-span" style="text-decoration: underline;">p</span>otentially <span class="Apple-style-span" style="text-decoration: underline;">a</span>bstract) to maintain reference to the opaque type across the call to <font class="Apple-style-span" face="Courier">refineAbstractTypeTo</font>. To understand why, recognize that the type is not updated in-place, but rather the concrete type is created, all uses of the opaque type are replaced by the concrete one, and then the opaque type is deleted. Unless your code participates in the replacement phase, your local variable will point into freed memory.</div><div><br class="webkit-block-placeholder"></div><div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">— Gordon</span></div></div><div apple-content-edited="true"> </div><br></body></html>