libstdc++: Make std::assume_aligned a constexpr function [PR 97132]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 21 Sep 2020 13:28:58 +0000 (14:28 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 21 Sep 2020 13:28:58 +0000 (14:28 +0100)
commitf10ed928e2f8ecc2c859abff8f2f9296b11b8d95
tree0f741066ee5f536a96dd61d3f28e9a9ac83498df
parent5187b01a4fcbea82f52798240595a32ddf7e0fe5
libstdc++: Make std::assume_aligned a constexpr function [PR 97132]

The cast from void* to T* in std::assume_aligned is not valid in a
constexpr function. The optimization hint is redundant during constant
evaluation anyway (the compiler can see the object and knows its
alignment). Simply return the original pointer without applying the
__builtin_assume_aligned hint to it when doing constant evaluation.

This change also removes the preprocessor branch that works around
uintptr_t not being available. We already assume that type is present
elsewhere in the library.

libstdc++-v3/ChangeLog:

PR libstdc++/97132
* include/bits/align.h (align) [!_GLIBCXX_USE_C99_STDINT_TR1]:
Remove unused code.
(assume_aligned): Do not use __builtin_assume_aligned during
constant evaluation.
* testsuite/20_util/assume_aligned/1.cc: Improve test.
* testsuite/20_util/assume_aligned/97132.cc: New test.
libstdc++-v3/include/bits/align.h
libstdc++-v3/testsuite/20_util/assume_aligned/1.cc
libstdc++-v3/testsuite/20_util/assume_aligned/97132.cc [new file with mode: 0644]