Revert^3 "Use DoNotOptimize rather than rely on a volatile."
This reverts commit aad7abbd31a93a43da3163331d5ceb02d7c09fcb.
Reason for revert: DroidMonitor: Potential culprit for http://b/370545152 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted
Change-Id: Id35ba5d9c986d83357d4acff9dc17ce67049439a
diff --git a/tests/DoNotOptimize.h b/tests/DoNotOptimize.h
deleted file mode 100644
index 711d339..0000000
--- a/tests/DoNotOptimize.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-// From <benchmark/benchmark.h>.
-template <class Tp>
-static inline void DoNotOptimize(Tp const& value) {
- asm volatile("" : : "r,m"(value) : "memory");
-}
-template <class Tp>
-static inline void DoNotOptimize(Tp& value) {
- asm volatile("" : "+r,m"(value) : : "memory");
-}
diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp
index ea111c9..105c261 100644
--- a/tests/clang_fortify_tests.cpp
+++ b/tests/clang_fortify_tests.cpp
@@ -95,8 +95,6 @@
#include <android-base/silent_death_test.h>
#include <gtest/gtest.h>
-#include "DoNotOptimize.h"
-
#define CONCAT2(x, y) x##y
#define CONCAT(x, y) CONCAT2(x, y)
#define FORTIFY_TEST_NAME CONCAT(CONCAT(clang_fortify_test_, _FORTIFY_SOURCE), _DeathTest)
@@ -148,7 +146,8 @@
for (char& c : contents) {
c ^= always_zero;
}
- DoNotOptimize(strlen(&contents.front()));
+ // Store in a volatile, so the strlen itself cannot be optimized out.
+ volatile size_t _strlen_result = strlen(&contents.front());
};
EXPECT_NO_DEATH(run_strlen_with_contents({'f', 'o', '\0'}));
diff --git a/tests/fenv_test.cpp b/tests/fenv_test.cpp
index bbf339f..9cf9d98 100644
--- a/tests/fenv_test.cpp
+++ b/tests/fenv_test.cpp
@@ -16,7 +16,6 @@
#include <gtest/gtest.h>
-#include "DoNotOptimize.h"
#include "utils.h"
#include <fenv.h>
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 3f1ba79..813f348 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -47,7 +47,6 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
-#include "DoNotOptimize.h"
#include "utils.h"
#if defined(__BIONIC__)
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 9ad3b6d..78b55c1 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -16,7 +16,6 @@
#include <gtest/gtest.h>
-#include "DoNotOptimize.h"
#include "SignalUtils.h"
#include "utils.h"
diff --git a/tests/utils.h b/tests/utils.h
index 4740e59..3c83b73 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -295,6 +295,16 @@
size_t start_count_ = CountOpenFds();
};
+// From <benchmark/benchmark.h>.
+template <class Tp>
+static inline void DoNotOptimize(Tp const& value) {
+ asm volatile("" : : "r,m"(value) : "memory");
+}
+template <class Tp>
+static inline void DoNotOptimize(Tp& value) {
+ asm volatile("" : "+r,m"(value) : : "memory");
+}
+
static inline bool running_with_mte() {
#ifdef __aarch64__
int level = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0);