From patchwork Wed Dec 28 00:06:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 133369 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 410A4B6FEC for ; Wed, 28 Dec 2011 11:06:34 +1100 (EST) Received: (qmail 17972 invoked by alias); 28 Dec 2011 00:06:29 -0000 Received: (qmail 17964 invoked by uid 22791); 28 Dec 2011 00:06:28 -0000 X-SWARE-Spam-Status: No, hits=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Dec 2011 00:06:15 +0000 Received: by iakh37 with SMTP id h37so18642874iak.20 for ; Tue, 27 Dec 2011 16:06:14 -0800 (PST) Received: by 10.42.151.195 with SMTP id f3mr31047985icw.19.1325030774738; Tue, 27 Dec 2011 16:06:14 -0800 (PST) Received: by 10.42.151.195 with SMTP id f3mr31047972icw.19.1325030774601; Tue, 27 Dec 2011 16:06:14 -0800 (PST) Received: from coign.google.com ([2620:0:1000:2301:f2de:f1ff:fe40:72a8]) by mx.google.com with ESMTPS id d19sm95542241ibh.8.2011.12.27.16.06.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Dec 2011 16:06:13 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Tweak debug info Date: Tue, 27 Dec 2011 16:06:12 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes 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 patch to the gcc-specific part of the Go frontend tweaks the debug info in a couple of ways. For a named struct or array type, this uses build_distinct_type_copy rather than build_variant_type_copy. Using build_variant_type_copy caused trouble because it wound up causing the main variant to be named while the copy was unnamed. The effect was to cause gcc to emit a typedef defined as itself, which was not useful. The middle-end currently expects all basic types to have a name. If they don't, it uses the name __unknown__, which is not helpful (see modified_type_die in dwarf2out.c). In Go all basic types will have a name anyhow. This patch ensures that the first time we see a named builtin basic type, we use that name rather than making a copy. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian 2011-12-27 Ian Lance Taylor * go-gcc.cc (Gcc_backend::set_placeholder_struct_type): Use build_distinct_type_copy rather than build_variant_type_copy. (Gcc_backend::set_placeholder_array_type): Likewise. (Gcc_backend::named_type): Add special handling for builtin basic types. Index: go-gcc.cc =================================================================== --- go-gcc.cc (revision 182696) +++ go-gcc.cc (working copy) @@ -663,7 +663,7 @@ Gcc_backend::set_placeholder_struct_type Btype* r = this->fill_in_struct(placeholder, fields); // Build the data structure gcc wants to see for a typedef. - tree copy = build_variant_type_copy(t); + tree copy = build_distinct_type_copy(t); TYPE_NAME(copy) = NULL_TREE; DECL_ORIGINAL_TYPE(TYPE_NAME(t)) = copy; @@ -696,7 +696,7 @@ Gcc_backend::set_placeholder_array_type( Btype* r = this->fill_in_array(placeholder, element_btype, length); // Build the data structure gcc wants to see for a typedef. - tree copy = build_variant_type_copy(t); + tree copy = build_distinct_type_copy(t); TYPE_NAME(copy) = NULL_TREE; DECL_ORIGINAL_TYPE(TYPE_NAME(t)) = copy; @@ -712,6 +712,24 @@ Gcc_backend::named_type(const std::strin tree type = btype->get_tree(); if (type == error_mark_node) return this->error_type(); + + // The middle-end expects a basic type to have a name. In Go every + // basic type will have a name. The first time we see a basic type, + // give it whatever Go name we have at this point. + if (TYPE_NAME(type) == NULL_TREE + && location.gcc_location() == BUILTINS_LOCATION + && (TREE_CODE(type) == INTEGER_TYPE + || TREE_CODE(type) == REAL_TYPE + || TREE_CODE(type) == COMPLEX_TYPE + || TREE_CODE(type) == BOOLEAN_TYPE)) + { + tree decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, + get_identifier_from_string(name), + type); + TYPE_NAME(type) = decl; + return this->make_type(type); + } + tree copy = build_variant_type_copy(type); tree decl = build_decl(location.gcc_location(), TYPE_DECL, get_identifier_from_string(name),