From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2110 invoked by alias); 4 Dec 2011 15:51:36 -0000 Received: (qmail 2102 invoked by uid 22791); 4 Dec 2011 15:51:34 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 04 Dec 2011 15:51:21 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/51392] Wrong code with -Os when __attribute__((__const__)) function returns structure Date: Sun, 04 Dec 2011 15:51:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Status Resolution Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-12/txt/msg00327.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51392 Richard Guenther changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #3 from Richard Guenther 2011-12-04 15:50:40 UTC --- __attribute__((__const__)) Vector3f pie_SurfaceNormal3fv(Vector3f a, Vector3f b) { return Vector3f(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); } I think it is illegal to use the const attribute when the C++ frontend may elide the return value copy to being passed by invisible reference. That way the middle-end sees a store to global memory which is a side-effect that the const attribute does not allow (similar for pure btw.). Note that the Vector3f() constructors are not const either but they are both called from pie_SurfaceNormal3fv.