Changing @llvm.objectsize(i8*, i1)

Hello friends!

I’m currently working on trying to improve __builtin_object_size support in Clang and LLVM. After a few more patches on Clang land, I plan on modifying LLVM a bit.

For those unfamiliar with the C intrinsic __builtin_object_size, here’s a high-level overview of it: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html

We have an LLVM intrinsic known as @llvm.objectsize(i8* Ptr, i1 Min). Clang lowers calls of __builtin_object_size(ptr, type) to this intrinsic if it can’t accurately determine an answer on its own. This works well for (type & 1) == 0, but is broken in a few ways when the low bit is set.

If type==1, we (LLVM) give the ideal answer at best, and a conservatively correct answer at worst.
If type==3, LLVM can give nothing but 0 (cannot determine), because we need a lower bound, and we don’t know subobject information.

In order to fix this, I plan on doing the following:

Thanks,
George