From patchwork Mon Aug 30 16:00:10 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 63065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 408A1B70F4 for ; Tue, 31 Aug 2010 02:00:41 +1000 (EST) Received: (qmail 1534 invoked by alias); 30 Aug 2010 16:00:33 -0000 Received: (qmail 1477 invoked by uid 22791); 30 Aug 2010 16:00:29 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 30 Aug 2010 16:00:22 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 559E7CB02B2 for ; Mon, 30 Aug 2010 18:00:20 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N8-rjImQh2Jf for ; Mon, 30 Aug 2010 18:00:20 +0200 (CEST) Received: from new-host-2.home (ADijon-552-1-128-98.w92-148.abo.wanadoo.fr [92.148.191.98]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 2A6A4CB01EF for ; Mon, 30 Aug 2010 18:00:20 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix wrong code with discriminated types at -gnatp Date: Mon, 30 Aug 2010 18:00:10 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201008301800.11089.ebotcazou@adacore.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This fixes a wrong code generation with -gnatp at any optimization level, a regression recently introduced on the mainline: we were assigning the max size when returning an aggregate of a discriminated record type with default discriminant. Tested on x86-64-suse-linux, applied on the mainline. 2010-08-30 Eric Botcazou * gcc-interface/trans.c (call_to_gnu): Also force the return slot opt for the call to a function whose return type was unconstrained. 2010-08-30 Thomas Quinot * gnat.dg/discr24.adb: New test. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 163646) +++ gcc-interface/trans.c (working copy) @@ -2992,6 +2992,7 @@ call_to_gnu (Node_Id gnat_node, tree *gn if (gnu_target) { Node_Id gnat_parent = Parent (gnat_node); + tree gnu_result_type = TREE_TYPE (gnu_subprog_type); enum tree_code op_code; /* If range check is needed, emit code to generate it. */ @@ -3002,11 +3003,15 @@ call_to_gnu (Node_Id gnat_node, tree *gn /* ??? If the return type has non-constant size, then force the return slot optimization as we would not be able to generate - a temporary. That's what has been done historically. */ - if (TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (gnu_subprog_type)))) - op_code = MODIFY_EXPR; - else + a temporary. Likewise if it was unconstrained as we would + copy too much data. That's what has been done historically. */ + if (!TREE_CONSTANT (TYPE_SIZE (gnu_result_type)) + || (TYPE_IS_PADDING_P (gnu_result_type) + && CONTAINS_PLACEHOLDER_P + (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_result_type)))))) op_code = INIT_EXPR; + else + op_code = MODIFY_EXPR; gnu_result = build_binary_op (op_code, NULL_TREE, gnu_target, gnu_result);