<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 6, 2017 at 2:06 PM, Kaylor, Andrew via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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="#0563C1" vlink="#954F72">
<div class="m_8381347372558589288WordSection1">
<p class="MsoNormal">I've got a problem that I would like some input on. The problem basically boils down to a program that I am compiling, whose source I don't control, doing something like this:<br></p><p class="MsoNormal"><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> p = (char*)0 + n<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">where 'n' is an intptr_t-sized value that the program knows is actually a valid address for a pointer.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">clang translates this as<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> %p = getelementptr inbounds i8, i8* null, i64 %n<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So far, so good. The problem is that while LLVM seems to consider the above IR to be valid, we officially do not allow dereferencing a pointer constructed in this way (if I’m reading the rules correctly). Consequently, if this GEP ever
gets close enough to a load using the pointer, InstCombine will eliminate the GEP and the load.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I've been told that the '(char*)0 + n' construct is invalid according to the C standard. However, this pattern appears in the glibc malloc implementation, so I'd like to be able to handle it anyway.</p></div></div></blockquote><div><br></div><div>glibc does accept patches...or are you talking about two separate instances of this problem, both in glibc and something else?</div><div><br></div><div><br></div></div></div></div>