In pursuit of fixing https://llvm.org/bugs/show_bug.cgi?id=23277, we'd like @llvm.objectsize to treat null pointers as opaque/unknown pointers, rather than treating them as pointers to 0 bytes of memory. This patch adds an argument to @llvm.objectsize that lets us control how @llvm.objectsize treats null.
As Sanjoy noted in http://lists.llvm.org/pipermail/llvm-dev/2017-January/108623.html, we can also make a backwards-incompatible change that just makes @llvm.objectsize adopt this null-is-unknown-size behavior in all cases. I dunno what the better option is here, but we could easily do that by throwing basically half of this patch out (all except for the changes to MemoryBuiltins).
If we want the absolutely-minimal patch, we could cut the changes to MemoryBuiltins.cpp down to a few lines (just returning unknown() in ObjectSizeOffsetVisitor::visitConstantPointerNull). Doing so would cause us to delay lowering the calls to @llvm.objectsize as much as possible, which may inhibit some optimizations.
There's a handful of tests with @llvm.objectsize in them that this patch doesn't update, since they don't CHECK for objectsize with a specific set of arguments. If we want, I'm happy to update them to use the three-arg version, as well.
I wasn't entirely sure who to poke with this, since I can't find a code owner for intrinsics. :)