From patchwork Mon Oct 15 18:08:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 191621 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 E943B2C00A7 for ; Tue, 16 Oct 2012 05:12:00 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1350929521; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=H1qfnLKvvrtrFMLHM0tfhebIi5M=; b=PvBKpoQi3h8IRxxQ2Mi3hFI5UbwcU43wtMYJKSkgVrmy0lGzltqBO03tTVWz6F DENxrV+ZqISFGS2WzP3zbgpno33n7GNy1Ev2CQEZ+0phonSGI93fscQ8KsqW1BYS fAY1hArw39RgSw/St12b4jVnVRIsW8RmdAPjYF1I//Sao= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=szJK61COBV+PyFNM4GbNAxCQjsRsEXi6K7iyMwfVtqj1f2P2LDkJvVPyk2GR2b dPPx8HvqCJXNhKmW88p1dCWcd+wLZA0HyzQN9z6zKQZ6FLrZAUnuHKQfYcj9hqxQ 0Zef4U3Ywel5HlBP+59HfgX9yYwAME9pdVzAnaa1pJs58=; Received: (qmail 8481 invoked by alias); 15 Oct 2012 18:11:47 -0000 Received: (qmail 8468 invoked by uid 22791); 15 Oct 2012 18:11:46 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 15 Oct 2012 18:11:40 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 0729629000F; Mon, 15 Oct 2012 20:11:52 +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 2RuF3gCmlIvM; Mon, 15 Oct 2012 20:11:51 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id BCCDB29000D; Mon, 15 Oct 2012 20:11:51 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Cc: "Joseph S. Myers" Subject: [c-family] Fix -fdump-ada-spec buglet in C++ Date: Mon, 15 Oct 2012 20:08:22 +0200 Message-ID: <1967969.xFf7Crz380@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.16-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 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 Hi, since the sizetype change, we generate invalid Ada for flexible array members with -fdump-ada-spec in C++. The attached patch fixes this issue and also partially revamps the code to polish some rough edges. Tested on x86_64-suse-linux, OK for mainline? 2012-10-15 Eric Botcazou c-family/ * c-ada-spec.c (ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX): Define. (dump_generic_ada_node) : Deal with sizetype specially. Remove POINTER_TYPE handling, add large unsigned handling and use ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX for big numbers. 2012-10-15 Eric Botcazou * g++.dg/other/dump-ada-spec-2.C: New test. Index: c-ada-spec.c =================================================================== --- c-ada-spec.c (revision 192447) +++ c-ada-spec.c (working copy) @@ -30,6 +30,21 @@ along with GCC; see the file COPYING3. #include "c-pragma.h" #include "cpp-id-data.h" +/* Adapted from hwint.h to use the Ada prefix. */ +#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG +# if HOST_BITS_PER_WIDE_INT == 64 +# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \ + "16#%" HOST_LONG_FORMAT "x%016" HOST_LONG_FORMAT "x#" +# else +# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \ + "16#%" HOST_LONG_FORMAT "x%08" HOST_LONG_FORMAT "x#" +# endif +#else + /* We can assume that 'long long' is at least 64 bits. */ +# define ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX \ + "16#%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x#" +#endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */ + /* Local functions, macros and variables. */ static int dump_generic_ada_node (pretty_printer *, tree, tree, int (*)(tree, cpp_operation), int, int, bool); @@ -2175,12 +2190,16 @@ dump_generic_ada_node (pretty_printer *b break; case INTEGER_CST: - if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE) - { - pp_wide_integer (buffer, TREE_INT_CST_LOW (node)); - pp_string (buffer, "B"); /* pseudo-unit */ - } - else if (!host_integerp (node, 0)) + /* We treat the upper half of the sizetype range as negative. This + is consistent with the internal treatment and makes it possible + to generate the (0 .. -1) range for flexible array members. */ + if (TREE_TYPE (node) == sizetype) + node = fold_convert (ssizetype, node); + if (host_integerp (node, 0)) + pp_wide_integer (buffer, TREE_INT_CST_LOW (node)); + else if (host_integerp (node, 1)) + pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node)); + else { tree val = node; unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val); @@ -2193,12 +2212,10 @@ dump_generic_ada_node (pretty_printer *b low = -low; } sprintf (pp_buffer (buffer)->digit_buffer, - HOST_WIDE_INT_PRINT_DOUBLE_HEX, - (unsigned HOST_WIDE_INT) high, low); + ADA_HOST_WIDE_INT_PRINT_DOUBLE_HEX, + (unsigned HOST_WIDE_INT) high, low); pp_string (buffer, pp_buffer (buffer)->digit_buffer); } - else - pp_wide_integer (buffer, TREE_INT_CST_LOW (node)); break; case REAL_CST: