From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21539 invoked by alias); 27 Oct 2014 15:53:04 -0000 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 Received: (qmail 21477 invoked by uid 48); 27 Oct 2014 15:52:59 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/63645] Incorrect code generation Date: Mon, 27 Oct 2014 16:25: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-Version: 4.8.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-10/txt/msg02089.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63645 --- Comment #20 from Jakub Jelinek --- (In reply to joseph@codesourcery.com from comment #19) > Given > > GnmExprBinary res; > GnmExpr const *expr = (GnmExpr *)&res; Let's consider if in #c11 you change: GnmExprBinary *res = malloc (sizeof (GnmExprBinary)); res->oper = op; return (GnmExpr*)res; to: GnmExpr *res = malloc (sizeof (GnmExprBinary)); res->binary.oper = op; return res; is that also invalid? I think that pretty much models what GCC does in its sources, not allocating always the whole size of the union, but sometimes allocating fewer bytes and sometimes more, based on which field of the union is going to be used. Malloc returned pointer should be sufficiently aligned in this case, just will be smaller than the size of the whole union.