From patchwork Wed Dec 10 00:56:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 419356 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6535714003E for ; Wed, 10 Dec 2014 11:56:15 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=KLu64rMve5NqMR5PG1HAVieo+bNlLcmIF/W7CHMhqJqQzq Qqch+h7MrVM1jO45JKtRblClVL96KZFGky1uI7J0aDXdzXNCW6kxZNZUOIiurqvn ym/UAtcIVju3clJitDV9i6g0+SbWH82AlyOoXsHeP01V2IdkozTxMHFsAQIzY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=uSzsJoetz2uvt8IewEMta5QYEW0=; b=mdF+qiZKwY4ovm+BMt/c XT5G7P5FZ1mxgnaiuNfWvjE262iUbq0R/bXKEBnvHedLZMgoOthyqxFRibp3alw6 9lc8arhNm0wde4xl0I8SXtiDtQEmLVdJ4spO96ml2v0uPc7bohYBB6/2RiHfip7R gZvlUTZ8+AHNIhkf9CAS+aQ= Received: (qmail 19953 invoked by alias); 10 Dec 2014 00:56:08 -0000 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 Received: (qmail 19841 invoked by uid 89); 10 Dec 2014 00:56:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yh0-f43.google.com Received: from mail-yh0-f43.google.com (HELO mail-yh0-f43.google.com) (209.85.213.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 10 Dec 2014 00:56:05 +0000 Received: by mail-yh0-f43.google.com with SMTP id z6so827062yhz.2 for ; Tue, 09 Dec 2014 16:56:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=DG1K6wfB7gSw0inoUog/0krH/bjVca6WYfz8FwQGZ1Q=; b=Xs9Dndwc7B7pEIyqAQZWpUQUnKLM/aWVxSn4dZbmDFer1j9PelYPUAlgXHi/+VO96x muzRdo1NM9bICkvBQa0yJNvkMfPV8lL31H5Qn8vJ8+/aqhiAzApL1iQKdQQ3UqoJaBo4 QyIn2TFaygaBaZqB+LsJmvO3EhqubZ3vFeIDiaiG8bU0zCQ0UgflSXnoDAvK8qzDeiYR G2Pxh5z6yBZt5Z0t/r/w4hDw12GNLhUJF3MokM0YUyz/DOVKq8YlJDqawTQ+F81Xkb0C L8/da5LuhWvzN+j8kakjGJSykOs3RD/thIS7WqR8zRP71yfZRgRajjA9EfbYApZpyawM AX7g== X-Gm-Message-State: ALoCoQm/bZOUc40XqIMA73x08uyGaK7Hhe2FzB+o6NRkD/yvJy7tOINd1gxQGti0HIw73mli5qIa MIME-Version: 1.0 X-Received: by 10.236.199.102 with SMTP id w66mr913941yhn.10.1418172963784; Tue, 09 Dec 2014 16:56:03 -0800 (PST) Received: by 10.170.57.196 with HTTP; Tue, 9 Dec 2014 16:56:03 -0800 (PST) Date: Tue, 9 Dec 2014 16:56:03 -0800 Message-ID: Subject: Go patch committed: Don't crash when using field tracking From: Ian Lance Taylor To: gcc-patches , "gofrontend-dev@googlegroups.com" This patch to the Go compiler fixes a crash when using field tracking. The code was failing to lower a function call added by the field tracking code. When called in a type equality function for a type that was not otherwise used, this could cause a crash as the type was never lowered. This patch fixes that problem. I also observed that it's entirely unnecessary to add field tracking information for a reference from a compiler generated equality function, so this patch also avoids doing that, thus fixing the compiler crash in a different way. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 5633f8241f0b go/expressions.cc --- a/go/expressions.cc Mon Dec 08 10:01:53 2014 -0800 +++ b/go/expressions.cc Tue Dec 09 16:41:41 2014 -0800 @@ -10729,6 +10729,10 @@ if (field->tag().find("go:\"track\"") == std::string::npos) return this; + // References from functions generated by the compiler don't count. + if (function->func_value()->is_type_specific_function()) + return this; + // We have found a reference to a tracked field. Build a call to // the runtime function __go_fieldtrack with a string that describes // the field. FIXME: We should only call this once per referenced @@ -10785,6 +10789,7 @@ e = Expression::make_unary(OPERATOR_AND, e, loc); Expression* call = Runtime::make_call(Runtime::FIELDTRACK, loc, 1, e); + gogo->lower_expression(function, inserter, &call); inserter->insert(Statement::make_statement(call, false)); // Put this function, and the global variable we just created, into diff -r 5633f8241f0b go/gogo.cc --- a/go/gogo.cc Mon Dec 08 10:01:53 2014 -0800 +++ b/go/gogo.cc Tue Dec 09 16:41:41 2014 -0800 @@ -4433,6 +4433,7 @@ is_sink_(false), results_are_named_(false), nointerface_(false), is_unnamed_type_stub_method_(false), calls_recover_(false), is_recover_thunk_(false), has_recover_thunk_(false), + calls_defer_retaddr_(false), is_type_specific_function_(false), in_unique_section_(false) { } diff -r 5633f8241f0b go/gogo.h --- a/go/gogo.h Mon Dec 08 10:01:53 2014 -0800 +++ b/go/gogo.h Tue Dec 09 16:41:41 2014 -0800 @@ -1071,6 +1071,18 @@ set_calls_defer_retaddr() { this->calls_defer_retaddr_ = true; } + // Whether this is a type hash or equality function created by the + // compiler. + bool + is_type_specific_function() + { return this->is_type_specific_function_; } + + // Record that this function is a type hash or equality function + // created by the compiler. + void + set_is_type_specific_function() + { this->is_type_specific_function_ = true; } + // Mark the function as going into a unique section. void set_in_unique_section() @@ -1199,6 +1211,9 @@ // True if this is a thunk built for a defer statement that calls // the __go_set_defer_retaddr runtime function. bool calls_defer_retaddr_ : 1; + // True if this is a function built by the compiler to as a hash or + // equality function for some type. + bool is_type_specific_function_ : 1; // True if this function should be put in a unique section. This is // turned on for field tracking. bool in_unique_section_ : 1; diff -r 5633f8241f0b go/types.cc --- a/go/types.cc Mon Dec 08 10:01:53 2014 -0800 +++ b/go/types.cc Tue Dec 09 16:41:41 2014 -0800 @@ -1805,6 +1805,7 @@ Named_object* hash_fn = gogo->start_function(hash_name, hash_fntype, false, bloc); + hash_fn->func_value()->set_is_type_specific_function(); gogo->start_block(bloc); if (name != NULL && name->real_type()->named_type() != NULL) @@ -1825,6 +1826,7 @@ Named_object *equal_fn = gogo->start_function(equal_name, equal_fntype, false, bloc); + equal_fn->func_value()->set_is_type_specific_function(); gogo->start_block(bloc); if (name != NULL && name->real_type()->named_type() != NULL)