From 7df89506de26a5c3f7a555b1c45a5f8cd1195c23 Mon Sep 17 00:00:00 2001
From: AKhatskevich <avkhatskevich@tarantool.org>
Date: Tue, 7 Aug 2018 16:47:39 +0300
Subject: [PATCH] test: prevent guard-breaker optimization with LTO

In case of very aggressive optimizations the compiler can
optimize guard-breaker function away and the `unit/guard`
test would fail.
---
 test/unit/guard.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/test/unit/guard.cc b/test/unit/guard.cc
index 231b44c7df..3d42fee31b 100644
--- a/test/unit/guard.cc
+++ b/test/unit/guard.cc
@@ -13,7 +13,11 @@ static int __attribute__((noinline))
 stack_break_f(char *ptr)
 {
 	char block[2048];
-	char sum = 0;
+	/*
+	 * Make sum volatile to prevent a compiler from
+	 * optimizing away call to this function.
+	 */
+	volatile char sum = 0;
 	memset(block, 0xff, 2048);
 	sum += block[block[4]];
 	ptrdiff_t stack_diff = ptr > block ? ptr - block : block - ptr;
-- 
GitLab