Declare proto2::internal::Allocate always_inline and malloc
Clang provides the AllocToken feature [1], which enables transparently augmenting standard allocation API calls with type-derived tokens resulting in use of the alloc-token ABI, a different allocator ABI. This can be used for heap hardening strategies such as heap partitioning. While for syntactically typed allocations (`new T`) the compiler can simply derive the token from `T`, for syntactically *untyped* allocations (`malloc(size)`, `::operator new(size)`), the compiler does best-effort analysis to determine the type from the size-expression. Allocation wrappers of syntactically untyped allocations are a currently known gap, because the compiler cannot infer any allocated type from the inner standard allocation call. `proto2::internal::Allocate()` is one such allocation wrapper. To solve, Clang 23 is adding support to propagate inferred types from wrapper call-sites to the inner allocation when inlined [2]. For Clang to infer allocations through `proto2::internal::Allocate()`, add the `always_inline` and `malloc` attributes (the former ensures inlining, the latter tells the compiler it's an allocation function). [1] https://clang.llvm.org/docs/AllocToken.html [2] https://github.com/llvm/llvm-project/pull/198535 PiperOrigin-RevId: 922768652
P
Protobuf Team Bot committed
1eee6a6b02b7b5a22645abd9e1c9293e4cb825bb
Parent: ae1faee
Committed by Copybara-Service <copybara-worker@google.com>
on 5/28/2026, 2:50:35 PM