From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 7 21:00:00 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AE0A1106564A for ; Wed, 7 Dec 2011 21:00:00 +0000 (UTC) (envelope-from lacombar@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 4452B8FC0A for ; Wed, 7 Dec 2011 20:59:59 +0000 (UTC) Received: by wgbdr11 with SMTP id dr11so1929643wgb.31 for ; Wed, 07 Dec 2011 12:59:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=miDwTw8TXunWnUr1F0kGIowiE9o5VAlSTWGbb+2G37Y=; b=RFDQicIH32rSGQDqMjyBavLWYj6PGE9Ftif05YS29esxHZw0c0wQY5eDxnoEMvjgmC 85Bjgzy4/GQ1N1QltPQG0LOoP/n0tUC00WbKxwiEyCh3vvSmh8pzwYXs5fV4sFliDbPn SVcovLsL/rulfbux5z8iSDRkKTx8v67qYBs74= MIME-Version: 1.0 Received: by 10.216.1.68 with SMTP id 46mr14520wec.23.1323289713689; Wed, 07 Dec 2011 12:28:33 -0800 (PST) Received: by 10.180.94.2 with HTTP; Wed, 7 Dec 2011 12:28:33 -0800 (PST) In-Reply-To: <20111119100150.GA1560@reks> References: <20111119100150.GA1560@reks> Date: Wed, 7 Dec 2011 15:28:33 -0500 Message-ID: From: Arnaud Lacombe To: Gleb Kurtsou Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org, mdf@freebsd.org Subject: Re: gcc 4.2 miscompilation with -O2 -fno-omit-frame-pointer on amd64 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Dec 2011 21:00:00 -0000 Hi, On Sat, Nov 19, 2011 at 5:01 AM, Gleb Kurtsou wrote: > Hi, > > I was lucky to write a bit of code which gcc 4.2 fails to compile > correctly with -O2. Too keep long story short the code fails for gcc > from base system and last gcc 4.2 snapshot from ports. It works with gcc > 4.3, gcc 4.4 on FreeBSD and Linux. Clang from base is also good. -O and > -Os optimization levels are fine (I've tried with all -f* flags > mentioned in documentation) > > -O2 -fno-omit-frame-pointer combination is troublesome on amd64. I > presume i386 should be fine. These options are also used for > compilation of kernel (with debugging enabled) and modules. > > I'm not able to share the code, but have a test case reproducing the > bug. I've encountered the issue over a week ago and tried narrowing it down > to a simple test I could share but without much success. > > The code itself is very common: initialize two structs on stack, call a > function with pointers to those stucts as arguments. A number of inlined > assertion functions. gcc fails to correctly optimize struct assignments > with -fno-omit-frame-pointer, I have a number of small structs assigned, > gcc decides not to use data coping but to assign fields directly. I've > tried disabling sra, tweaking sra parameters -- no luck in forcing it > to copy data. Replacing one particular assignment with memcpy produces > correct code, but that's not a solution. > > -O2 -fno-omit-frame-pointer -fno-inline is buggy > -O2 -fno-omit-frame-pointer -frename-registers is buggy > > I found similar issue with gcc 4.6, but I'm not able to reproduce it > with gcc test case: > https://bugzilla.redhat.com/show_bug.cgi?id=679924 > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47893 > this PR seems highly irrelevant, the cause has been identified to a commit made in mid-2010, that's 3 years older than gcc in base. > I'll be glad to help debugging it and will be hanging on #bsddev during > weekend as glk. > at least, can you share the testcase and miscompilation details ? Thanks, - Arnaud