From owner-freebsd-questions@freebsd.org Sat Jun 10 22:24:04 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C4E93BF77FA for ; Sat, 10 Jun 2017 22:24:04 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from ns.mahan.org (23-24-207-145-static.hfc.comcastbusiness.net [23.24.207.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B0E8765074 for ; Sat, 10 Jun 2017 22:24:03 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from Cone-of-Silence.local (localhost [127.0.0.1]) by ns.mahan.org (8.14.9/8.14.9) with ESMTP id v5AMOFng001888; Sat, 10 Jun 2017 15:24:16 -0700 (PDT) (envelope-from mahan@mahan.org) Subject: Re: -O2 flag To: FreeBSD Mailing List , serpent7776@gmail.com References: <593C4679.5010104@gmail.com> <20170610230928.581e3cf9@DaemONX> From: Patrick Mahan Message-ID: Date: Sat, 10 Jun 2017 15:24:01 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20170610230928.581e3cf9@DaemONX> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Jun 2017 22:24:04 -0000 On 6/10/17 2:09 PM, Serpent7776 wrote: > On Sat, 10 Jun 2017 16:20:25 -0300 > Friedrich Locke wrote: > >> Hi folks, >> >> i am trying compile a program with cc on freebsd 11. >> When i use -O2 compilation flag, the compiled code is giving error on >> execution, but with i omit -O2 everything works ok. >> >> Have anybody already faced such problem ? > Yes, a few times in the past. Your code may have hidden bug which is triggered > only with optimizations enabled. It might be relying on some kind of undefined > behaviour. > Unfortunately, I don't have any helpful advices on how to find this error - > try enabling all compiler warnings flags. > I'd suspect a bug in your code rather than a bug in compiler, but the latter is > not impossible. > This is especially noticeable when you use uninitialized stack variables in a function. Non-optimized generally gets you a cleaner stack. But I've seen code that assumes a stack variable always has a certain value. Patrick