f10ed928e2
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.
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
// Copyright (C) 2020 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING3. If not see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
// { dg-options "-std=gnu++2a" }
|
|
// { dg-do compile { target c++2a } }
|
|
|
|
#include <memory>
|
|
|
|
// PR libstdc++/97132 - assume_aligned is not constexpr
|
|
|
|
constexpr bool test01()
|
|
{
|
|
struct alignas(32) S { int i; };
|
|
S s{42};
|
|
int* p = std::assume_aligned<32>(&s.i);
|
|
*p = 48;
|
|
return s.i == 48;
|
|
}
|
|
|
|
static_assert( test01() );
|