[clang] [clang] Add `clang::behaves_like_std(...)` attribute (PR #76596)

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 30 04:17:29 PST 2023


https://github.com/philnik777 commented:

While I disagree with the reasoning for not just using `std` (@MaxEW707 I think having a chat about this informally would be nice.), I do think it makes sense to add the ability to declare some functions as builtins. There are a few cases inside the standard library itself:
- simply allowing the same optimizations to be done with `-ffreestanding`
- there are quite a few more functions which behave just like builtins, but are currently not recognized as such by the compiler. e.g. `identity::operator()`
- library-internal functionality which would have to be handled by the compiler for every implementation, like `__identity::operator()` in libc++

The above ones are all handled by what is currently proposed, but there is also functionality which doesn't work with this proposal. For example:
- allowing the declaration of non-`std` builtins, like `char_traits<char>::find()`, which could be declared as equivalent to `__builtin_memchr`.
- other functions which are essentially casts, but take their arguments by-value, like `to_underlying`
- Functions that are essentially builtin operations, like `char_traits<char>::eq`

I don't know whether all of these things should be handled with the same attribute, or whether they should be handled at all, but they should definitely be considered when designing this attribute.


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


More information about the cfe-commits mailing list