Add DoNotOptimize and use it in tests.
Bug: http://b/148307629
Test: treehugger
Change-Id: I3b1726ae55116f6553ea38fe163abdde179c21f0
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 43d50f8..41ca8b4 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -676,14 +676,10 @@
ASSERT_NE(static_cast<uint64_t>(parent_tid), reinterpret_cast<uint64_t>(result));
}
-static void optimization_barrier(void* arg) {
- asm volatile("" : : "r"(arg) : "memory");
-}
-
__attribute__((noinline)) static void HwasanVforkTestChild() {
// Allocate a tagged region on stack and leave it there.
char x[10000];
- optimization_barrier(x);
+ DoNotOptimize(x);
_exit(0);
}
@@ -700,7 +696,7 @@
// Allocate a region on stack, but don't tag it (see the function attribute).
// This depends on unallocated stack space at current function entry being untagged.
char x[10000];
- optimization_barrier(x);
+ DoNotOptimize(x);
// Verify that contents of x[] are untagged.
HwasanReadMemory(x, sizeof(x));
}