Skip to content

Commit

Permalink
PR libstdc++/84773 use aligned alloc functions for FreeBSD and MinGW …
Browse files Browse the repository at this point in the history
…cross-compilers

	PR libstdc++/84773
	PR libstdc++/83662
	* crossconfig.m4: Check for aligned_alloc etc. on freebsd and mingw32.
	* configure: Regenerate.
	* include/c_global/cstdlib [_GLIBCXX_HAVE_ALIGNED_ALLOC]
	(aligned_alloc): Add using-declaration.
	* testsuite/18_support/aligned_alloc/aligned_alloc.cc: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258468 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
redi committed Mar 12, 2018
1 parent 7d966c3 commit 147fd74
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libstdc++-v3/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2018-03-12 Jonathan Wakely <jwakely@redhat.com>

PR libstdc++/84773
PR libstdc++/83662
* crossconfig.m4: Check for aligned_alloc etc. on freebsd and mingw32.
* configure: Regenerate.
* include/c_global/cstdlib [_GLIBCXX_HAVE_ALIGNED_ALLOC]
(aligned_alloc): Add using-declaration.
* testsuite/18_support/aligned_alloc/aligned_alloc.cc: New test.

2018-03-09 François Dumont <fdumont@gcc.gnu.org>

* python/libstdcxx/v6/printers.py (build_libstdcxx_dictionary):
Expand Down
26 changes: 26 additions & 0 deletions libstdc++-v3/configure
Original file line number Diff line number Diff line change
Expand Up @@ -53347,6 +53347,19 @@ if test "x$ac_cv_func___cxa_thread_atexit" = x""yes; then :
#define HAVE___CXA_THREAD_ATEXIT 1
_ACEOF

fi
done

for ac_func in aligned_alloc posix_memalign memalign _aligned_malloc
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
eval as_val=\$$as_ac_var
if test "x$as_val" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
done

Expand Down Expand Up @@ -66100,6 +66113,19 @@ done

CXXFLAGS="$ac_save_CXXFLAGS"

for ac_func in aligned_alloc posix_memalign memalign _aligned_malloc
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
eval as_val=\$$as_ac_var
if test "x$as_val" = x""yes; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
done

;;
*-netbsd*)
SECTION_FLAGS='-ffunction-sections -fdata-sections'
Expand Down
2 changes: 2 additions & 0 deletions libstdc++-v3/crossconfig.m4
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ case "${host}" in
AC_DEFINE(HAVE_ISNANL)
fi
AC_CHECK_FUNCS(__cxa_thread_atexit)
AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
;;
*-fuchsia*)
Expand Down Expand Up @@ -197,6 +198,7 @@ case "${host}" in
GLIBCXX_CHECK_LINKER_FEATURES
GLIBCXX_CHECK_MATH_SUPPORT
GLIBCXX_CHECK_STDLIB_SUPPORT
AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
;;
*-netbsd*)
SECTION_FLAGS='-ffunction-sections -fdata-sections'
Expand Down
6 changes: 6 additions & 0 deletions libstdc++-v3/include/c_global/cstdlib
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace std

// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
#undef abort
#if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
# undef aligned_alloc
#endif
#undef atexit
#if __cplusplus >= 201103L
# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
Expand Down Expand Up @@ -125,6 +128,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using ::ldiv_t;

using ::abort;
#if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)
using ::aligned_alloc;
#endif
using ::atexit;
#if __cplusplus >= 201103L
# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
Expand Down
42 changes: 42 additions & 0 deletions libstdc++-v3/testsuite/18_support/aligned_alloc/aligned_alloc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2018 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++17" }
// { dg-do run { target c++17 } }

#include <cstdlib>
#include <cstdint>
#include <testsuite_hooks.h>

void
test01()
{
#ifdef _GLIBCXX_HAVE_ALIGNED_ALLOC
void* p = std::aligned_alloc(256, 1);
if (p)
{
VERIFY( (reinterpret_cast<std::uintptr_t>(p) % 256) == 0 );
std::free(p);
}
#endif
}

int
main()
{
test01();
}

0 comments on commit 147fd74

Please sign in to comment.