[libc-commits] [libc] [libc][c23] add memset_explicit (PR #83577)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Wed Mar 6 09:03:46 PST 2024


================
@@ -0,0 +1,25 @@
+//===-- Implementation of memset_explicit ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/string/memset_explicit.h"
+#include "src/__support/common.h"
+#include "src/string/memory_utils/inline_memset.h"
+
+namespace LIBC_NAMESPACE {
+
+[[gnu::noinline]] LLVM_LIBC_FUNCTION(void *, memset_explicit,
+                                     (void *dst, int value, size_t count)) {
+  // Use the inline memset function to set the memory.
+  inline_memset<true>(dst, static_cast<uint8_t>(value), count);
+  // avoid dead store elimination
+  // The asm itself should also be sufficient to behave as a compiler barrier.
+  asm volatile("" : : "r"(dst) : "memory");
----------------
nickdesaulniers wrote:

remove volatile. It's implicit for `asm goto` and `asm` statements without outputs.

https://github.com/llvm/llvm-project/pull/83577


More information about the libc-commits mailing list