On 1/23/19 3:40 AM, Jonathan Wakely wrote: > There's a patch to add __builtin_dynamic_object_size to clang: > https://reviews.llvm.org/D56760 > > It was suggested that this could be done via a new flag bit for > __builtin_object_size, but only if GCC would support that too > (otherwise it would be done as a separate builtin). > > Is there any interest in adding that as an option to __builtin_object_size? > > I know Jakub is concerned about arbitrarily complex expressions, when > __builtin_object_size is supposed to always be efficient and always > evaluate at compile time (which would imply the dynamic behaviour > should be a separate builtin, if it exists at all). I am very interested in doing something like that and handling at least the simple cases (with minimum runtime overhead). I haven't thought about it hard enough to have a clear idea whether it needs a new built-in or whether the current one can be extended to handle non-constant cases as well (perhaps by adding a new bit) but I would certainly want the existing libc infrastructure to make use of the non-constant sizes without having to change. The overhead of handling the more complex cases that Jakub is concerned about could be controlled by some customizable parameter so I don't think that should stand in the way. Besides handling non-constant object sizes I would also like GCC to get better about detecting and preventing subobject overflow (such as in strcpy (s.m, "foobar") where GCC transforms the strcpy call to memcpy which is allowed to overwrite whatever follows s.m). Martin