[PATCH] D93015: Fold comparison of __builtin_object_size expression with -1 for non-const size

Siddhesh Poyarekar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 02:21:35 PST 2020


siddhesh added a comment.

In D93015#2454403 <https://reviews.llvm.org/D93015#2454403>, @serge-sans-paille wrote:

>> When __builtin_dynamic_object_size returns a non-constant expression, it cannot be -1 since that is an invalid return value for object size
>
> I disagree with that statement. For instance
>
>   void copy_into_buffer(char* buffer) {
>      __builtin___strlcpy_chk(buffer, "some string", strlen("some string"), __builtin_dynamic_object_size(buffer, 0))
>    }
>
> In that case, `__builtin_dynamic_object_size` may return -1, e.g. if `copy_into_buffer` has external linkage, and thus no information on `buffer` is available

Ah sorry I should have been more specific: if `__builtin_dynamic_object_size` returns a non-constant expression, that expression returning -1 is undefined because none of the object allocators would return -1.  In your example above, `__builtin_dynamic_object_size` evaluates to a constant -1.

Would you agree with that?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93015/new/

https://reviews.llvm.org/D93015



More information about the llvm-commits mailing list