<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 6, 2020, at 22:14, Krzysztof Parzyszek <<a href="mailto:kparzysz@quicinc.com" class="">kparzysz@quicinc.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><blockquote type="cite" class="">-----Original Message-----<br class=""><br class="">Thanks for the help. I’m thinking the same way. Now I’m stuck with how to<br class="">create a struct; I know how to create a llvm::StructType but I’m not clear of<br class="">how to create a Value whose type is struct). It seems that llvm disallowed<br class="">directly create a Value object; all Values are created from one of its<br class="">numerous descendants. Can you give me some guidance here?<br class=""></blockquote><br class="">The "trick" is to start with "undef" (which always exists for any type).<br class=""></div></div></blockquote><div><br class=""></div>Thanks very much for the direction. This UndefValue method works for me.</div><div><br class=""></div><div>For anyone who’s interested in more details, here is the code snippet that</div><div>“cast” a struct of type {i8*, i64} to a struct of type {some_struct*, i64}:</div><div><br class=""></div><div>// V is a struct of type {i8*, i64}, and RetIRTy is type {some_struct*, i64}.</div><div><div><font face="Menlo" class="">llvm::UndefValue *newRet = llvm::UndefValue::get(RetIRTy);        </font></div><div><font face="Menlo" class="">llvm::Value *genericPtr = Builder.CreateExtractValue(V, 0);       </font></div><div><font face="Menlo" class="">llvm::Value *ID = Builder.CreateExtractValue(V, 1);               </font></div><div><font face="Menlo" class="">llvm::Value *concretePtr = Builder.CreateBitCast                  </font></div><div><font face="Menlo" class="">  (genericPtr, cast<llvm::StructType>(RetIRTy)->getElementType(0));</font></div><div><font face="Menlo" class="">llvm::Value *insertPtr = Builder.CreateInsertValue(newRet, concretePtr, 0);</font></div><div><font face="Menlo" class="">V = Builder.CreateInsertValue(insertPtr, ID, 1);</font></div><div><font face="Menlo" class=""><br class=""></font></div><div>- Jie</div><blockquote type="cite" class=""><div class=""><div class=""><br class="">-Krzysztof<br class=""><br class=""></div></div></blockquote></div><br class=""></body></html>