[libc-commits] [libc] [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (PR #73469)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Sun Nov 26 19:36:14 PST 2023


================
@@ -0,0 +1,72 @@
+//===-- Memory Size ---------------------------------------------*- C++ -*-===//
+//
+// 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/__support/CPP/limits.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/bit.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/optimization.h"
+
+namespace LIBC_NAMESPACE {
+namespace internal {
+template <class T> LIBC_INLINE static bool mul_overflow(T a, T b, T *res) {
+#if defined(__has_builtin) && __has_builtin(__builtin_mul_overflow)
+  return __builtin_mul_overflow(a, b, res);
+#else
+  T max = cpp::numeric_limits<T>::max();
+  T min = cpp::numeric_limits<T>::min();
+  bool overflow = (b > 0 && (a > max / b || a < min / b)) ||
----------------
SchrodingerZhu wrote:

This does not generate the same code as the built-in. Is there a better way to do a signed overflow check when built-in is not available?

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


More information about the libc-commits mailing list