diff --git a/libstdc++-v3/testsuite/23_containers/deque/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/deque/allocator/default_init.cc
index ce8c6ba8114039746f14ef30a79630eef43145ce..63ada98d048e97346ca1a24695b3b7c8bdb48446 100644
--- a/libstdc++-v3/testsuite/23_containers/deque/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -34,7 +35,7 @@ void test01()
   typedef std::deque<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -49,7 +50,7 @@ void test02()
   typedef std::deque<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/default_init.cc
index 1865e39a885f0ef9faca0f519387b841aef3e7d1..d8a8bdf05a9384670c94a190c8ccf8474034ce69 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -34,7 +35,7 @@ void test01()
   typedef std::forward_list<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -49,7 +50,7 @@ void test02()
   typedef std::forward_list<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc
index ab19ca7070cc8ad40a37cab0c7907eca0b735ed7..cffad227bc0cc77333ef2db5c3e5461d12bc3b4f 100644
--- a/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/list/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -34,7 +35,7 @@ void test01()
   typedef std::list<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   VERIFY( buf._M_ptr()->get_allocator().state != 0 );
 
@@ -51,7 +52,7 @@ void test02()
   typedef std::list<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   VERIFY( buf._M_ptr()->get_allocator().state != 0 );
 
diff --git a/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc
index 15fa1bfcf9206d1ee0fccf0912bce747726500e6..6b34227a5d0f81ef678a36fa3edf5b5a272c5196 100644
--- a/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -34,7 +35,7 @@ void test01()
   typedef std::map<T, T, std::less<T>, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -49,7 +50,7 @@ void test02()
   typedef std::map<T, T, std::less<T>, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc
index 553a93422c0c08e60fc7b4cc956dc84ac860894b..1976bed445ad84e22e5450868ba2db0e5f0d1dc9 100644
--- a/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -34,7 +35,7 @@ void test01()
   typedef std::set<T, std::less<T>, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -49,7 +50,7 @@ void test02()
   typedef std::set<T, std::less<T>, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/default_init.cc
index d86d2537a160b4aa093c0f51dfa4fd3e2074bcf9..eb3c177f2b49613d826e2b2f579bf4ea21c963ea 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -35,7 +36,7 @@ void test01()
 			     alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -51,7 +52,7 @@ void test02()
 			     alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/default_init.cc
index a86eb987e577595ba3436a8cd08224dd1c7b154b..cff8d74a8b29d9153bdf534ae4ada431045f5588 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -35,7 +36,7 @@ void test01()
 			     alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -51,7 +52,7 @@ void test02()
 			     alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/default_init.cc
index 1e69f6382c448c0b2d56f7b8410c656c20c30d19..ae631da13a4836e339e0891689f630d6ebef3e7b 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = int;
@@ -34,7 +35,7 @@ void test01()
   typedef std::vector<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -49,7 +50,7 @@ void test02()
   typedef std::vector<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/default_init.cc
index 5c4d60990e154a0fc2d993fc45ffccaeb8b88288..1bd69f25685465f211314c29f9c542eabfbc85f8 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/default_init.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/default_init.cc
@@ -22,6 +22,7 @@
 #include <testsuite_hooks.h>
 #include <testsuite_allocator.h>
 
+#include <cstring>
 #include <ext/aligned_buffer.h>
 
 using T = bool;
@@ -34,7 +35,7 @@ void test01()
   typedef std::vector<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type;
 
@@ -49,7 +50,7 @@ void test02()
   typedef std::vector<T, alloc_type> test_type;
 
   __gnu_cxx::__aligned_buffer<test_type> buf;
-  __builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
+  std::memset(buf._M_addr(), ~0, sizeof(test_type));
 
   test_type *tmp = ::new(buf._M_addr()) test_type();
 
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
index 859629e625f8704ed8a5da94967dc04166ce2ba8..2f18d426e7f7eb384b5d495d9352baa54e727f48 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
@@ -3,6 +3,7 @@
 // { dg-add-options libatomic }
 
 #include <atomic>
+#include <cstring>
 
 #include <testsuite_hooks.h>
 
@@ -10,11 +11,11 @@ struct S { char c; short s; };
 
 void __attribute__((noinline,noipa))
 fill_struct(S& s)
-{ __builtin_memset(&s, 0xff, sizeof(S)); }
+{ std::memset(&s, 0xff, sizeof(S)); }
 
 bool
 compare_struct(const S& a, const S& b)
-{ return __builtin_memcmp(&a, &b, sizeof(S)) == 0; }
+{ return std::memcmp(&a, &b, sizeof(S)) == 0; }
 
 int
 main ()
diff --git a/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h b/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h
index eb8901137138cd938e6aadab82016cb61646b752..9e96d3cd1bd57166530c97862b1794697d421017 100644
--- a/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h
+++ b/libstdc++-v3/testsuite/util/atomic/wait_notify_util.h
@@ -21,11 +21,10 @@
 #include <concepts>
 #include <mutex>
 #include <thread>
+#include <cstring>
 
 #include <testsuite_hooks.h>
 
-#include <iostream>
-
 template<typename Tp>
 Tp check_wait_notify(Tp val1, Tp val2)
   requires std::equality_comparable<Tp>
@@ -76,7 +75,7 @@ Tp check_wait_notify(Tp val1, Tp val2)
 		  a.wait(val1);
 		  auto v = a.load();
 		  // TODO this needs to zero padding bits when we can do that
-		  if (__builtin_memcmp(&v, &val2, sizeof(Tp)) != 0)
+		  if (std::memcmp(&v, &val2, sizeof(Tp)) != 0)
 		    a = val1;
 		});
   cv.wait(l);
@@ -137,7 +136,7 @@ Tp check_atomic_wait_notify(Tp val1, Tp val2)
 		  std::atomic_wait(&a, val1);
 		  auto v = a.load();
 		  // TODO this needs to zero padding bits when we can do that
-		  if (__builtin_memcmp(&v, &val2, sizeof(Tp)) != 0)
+		  if (std::memcmp(&v, &val2, sizeof(Tp)) != 0)
 		    a = val1;
 		});
   cv.wait(l);
@@ -163,13 +162,13 @@ struct check
       {
 	// TODO this needs to zero padding bits when we can do that
 	auto v = check_wait_notify(a, b);
-	VERIFY( __builtin_memcmp(&v, &b, sizeof(Tp)) == 0 );
+	VERIFY( std::memcmp(&v, &b, sizeof(Tp)) == 0 );
       }
 
       {
 	// TODO this needs to zero padding bits when we can do that
 	auto v = check_atomic_wait_notify(a, b);
-	VERIFY( __builtin_memcmp(&v, &b, sizeof(Tp)) == 0);
+	VERIFY( std::memcmp(&v, &b, sizeof(Tp)) == 0);
       }
     }
   }