[cfe-dev] Clang builtins for C++20 STL features
Roman Lebedev via cfe-dev
cfe-dev at lists.llvm.org
Thu Nov 29 22:13:09 PST 2018
On Fri, Nov 30, 2018 at 5:53 AM Richard Smith via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> On Thu, 29 Nov 2018 at 17:55, Stephan T. Lavavej via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>> * P1007R3 std::assume_aligned()
>> MSVC supports a general __assume() although I'm unsure if it's applicable/desirable here. Should there be a dedicated builtin?
>
>
> Well, Clang already supports __assume() for MSVC compatibility (only in MS mode) and __builtin_assume() (our preferred spelling, available in general). But a general assume intrinsic is probably not the best choice here.
Whatever it ends up being, *please* *don't* just use generic
__builtin_assume(), but a special standalone builtin.
It's better for sanitization reasons.
> Clang and GCC also already have:
>
> void *__builtin_assume_aligned(const void *p, size_t align, size_t offset_from_aligned = 0)
> See https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
>
> That's not ideal because it's not const-correct.
>
> Even for library wording, the spec is weak on specifying when a call to std::assume_aligned is allowed in constant expressions. For Clang at least, we treat a call to __builtin_assume_aligned as non-constant if we cannot prove the object is suitably aligned (that is, if the complete object's alignment and the offset within it don't result in a suitable alignment) even if we happen to know that (for instance) a global variable will typically be aligned to 16 bytes in practice.
Roman.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list