================
@@ -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 {
----------------
philnik777 wrote:

We have `DoNotOptimize` already in `test_macros.h`(!?). I think we should use 
that version instead, since it properly clobbers things and works for more 
compilers. We'll have to make it `constexpr` though. 

https://github.com/llvm/llvm-project/pull/68753
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to