<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 2, 2015 at 2:20 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>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:1px solid rgb(204,204,204);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></span><div>I think the closest entity for this sort of thing is LLVM's ConstantExpr::getOffsetOf.</div></div></div></div></blockquote><div><br></div><div>Certainly, but I think this requires either making `offsetof` a first-class operation in the source language, or handling the folding of <span><pointer deref>-<field select>-<get-address-of></span> combo in the front-end.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>







<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);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></span><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></div></blockquote><div><br></div><div> So it handles all const expression evaluation in the front-end?  <br><br></div></div></div></div>