From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E38B52BE39 for ; Sun, 14 Oct 2018 19:17:30 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vJRf0nyt8NRp for ; Sun, 14 Oct 2018 19:17:30 -0400 (EDT) Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 9F1132BE07 for ; Sun, 14 Oct 2018 19:17:30 -0400 (EDT) From: Alexander Turenko Subject: [tarantool-patches] [PATCH v2 1/3] test: prevent guard-breaker optimization with LTO Date: Mon, 15 Oct 2018 02:17:29 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: Georgy Kirichenko Cc: AKhatskevich , tarantool-patches@freelists.org From: AKhatskevich 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 231b44c7d..3d42fee31 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; -- 2.19.1