[libcxx] [libunwind] [llvm] [libc++] Allow running the test suite with optimizations (PR #68753)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 20 09:00:40 PST 2023


================
@@ -0,0 +1,28 @@
+// -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUPPORT_DO_NOT_OPTIMIZE_H
+#define SUPPORT_DO_NOT_OPTIMIZE_H
+
+#include "test_macros.h"
+
+namespace support {
+// This function can be used to hide some objects from compiler optimizations.
+//
+// For example, this is useful to hide the result of a call to `new` and ensure
+// that the compiler doesn't elide the call to new/delete. Otherwise, elliding
+// calls to new/delete is allowed by the Standard and compilers actually do it
+// when optimizations are enabled.
+template <class T>
+TEST_CONSTEXPR __attribute__((noinline)) T* do_not_optimize(T* ptr) TEST_NOEXCEPT {
----------------
ldionne wrote:

I must have missed that.

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


More information about the cfe-commits mailing list