<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 2, 2015 at 1:58 AM, Vadim Chugunov <span dir="ltr"><<a href="mailto:vadimcn@gmail.com" target="_blank">vadimcn@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>Hi!<br></div>LLVM has a class, ConstantExpr, that is very handy for compile-time evaluation of const expressions.   Unfortunately I cannot find any methods in it that would be helpful in evaluation of expressions similar to this: (uintptr_t)(&(*(TYPE*)0).FIELD), which is basically the implementation of the offsetof(TYPE, FIELD) macro.</div></div></blockquote><div><br></div><div>I think the closest entity for this sort of thing is LLVM's ConstantExpr::getOffsetOf.</div>







<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Specifically, there seem to be no provisions for dereferencing a pointer.<br><br></div>Does LLVM have any facilities (that I missed), that would help language front-ends in dealing with this sort of expressions?<br>Obviously, clang does it somehow, but  so far I was not able to locate the relevant bit of code.  Any pointers would be appreciated!</div></blockquote><div><br></div><div>Clang handles record types in a very abstract way, it doesn't rely on LLVM IR at any level. An ASTRecordLayout is built for a record type and the ASTRecordLayout::getFieldIndex method is used to determine the offset for a particular field.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><span><font color="#888888"><br><br><div><div>Vadim<br></div></div></font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">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></div>