[llvm] [llvm] Use LazyValueInfo to improve llvm.objectsize computation (PR #114673)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 07:16:59 PST 2024


serge-sans-paille wrote:

> The problem I hinted at in my previous comment turns out to be a problem already even without your PR. Consider something like
> 
> ```c++
> int f(int n) {
>   __builtin_assume(n >= 20);
>   int buf[n];
>   buf[10] = 0;
>   return buf[10];
> }
> 
> int main(void) {
>   return f(3);
> }
> ```
> 
> It is good that in recent versions of Clang, with `-fsanitize=undefined`, this prints "runtime error: assumption is violated during execution".

agreed.
 
> It is less good that without that `__builtin_assume`, we would also diagnose "runtime error: index 10 out of bounds for type 'int[n]'", but with that `__builtin_assume`, we do not, we still have an out of bounds access but we now ignore it.
> 
> I am not sure what the intended behaviour is here. Is this something we want to diagnose, or is this something we want to optimise away?

It's indeed tricky. From a strict `__builtin_object_size` point of view, it makes sense to always use these information as it improves its accuracy. The problem is that `__builtin_object_size` is often used to implement security feature, so there's a tension there.

I'll update the patch to *not* use assumptions, that's already a strict improvement.



https://github.com/llvm/llvm-project/pull/114673


More information about the llvm-commits mailing list