From patchwork Mon Jun 4 19:10:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 925203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-479048-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VGD0MPwn"; dkim-atps=neutral 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 4104Jn0bvVz9rvt for ; Tue, 5 Jun 2018 05:10:30 +1000 (AEST) 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=cqCf/ZINx0tFQjMMa5TJoKVC0mu6sDFA2o0PZKrzJthbq2 NfIdnZYgAi9Dv9V0eSMfcQJBrSP7aU6XA11mbdGeEL33sKFQjpoUhQ2eSJ5cDBt6 YlAj5qDv/Bc7PaL0pUJG6sjeR9df94Nd7JeR5mgH2VJaKLx6eDg3LRs+Ymyu4= 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:from:date:message-id:subject:to:content-type; s= default; bh=FMgyUbiEl/8wdvnPCdKw/uwrHqs=; b=VGD0MPwnc76BNfEJsGMM EWxi5/WV4ODRNKjSabcOYPt2okwa4K7u3kUHN3HaIb9MNxe9gtO217vOd5v4sNbD t7UNq+o/XemCjKEmBUKMkac7mUYyAvWG5ru/0scHIBD4njk+DpqZTABFRbRlckpJ 0sccf1db3E2mkLdDQeyaYyw= Received: (qmail 92045 invoked by alias); 4 Jun 2018 19:10:23 -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 92030 invoked by uid 89); 4 Jun 2018 19:10:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:f8-v6mr, H*r:sk:v131-v6, 261041, Than X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Jun 2018 19:10:20 +0000 Received: by mail-wm0-f50.google.com with SMTP id v131-v6so402064wma.1 for ; Mon, 04 Jun 2018 12:10:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=M1AS6Rtjaemval7L6+Gru3s4L5lyBhOx1W1xXYjFJ4o=; b=aUefSyWl0zmN2T2py4C7wMkLmB8/kNvDYM342IzDsddsBduCQ/MmoONu+XRtnG14P2 ADr/S8tXDC9i9tJdmDeRk8ubnKQFR9W5x7l2+Czn61vu+UoIirPfgXO4Maeguax5QOti c3eO5MFFImtaAybpYHtNllcbupDZUSMjS6aaV/bjZLBHqBBsaSfduUjVkkreDNcvTKJO JCRbXZP7N9XofT2bjUVZo69ok+q/jw17vgTYevZBYKPQSAiEjmUXicmKYMnkLQfTkgRq pgiXCgNVswbil8CN/uCN3A+FH2xEc8imfjP06IoLbNv/mwRwO37tnTQhITEacq0klkh/ +E2A== X-Gm-Message-State: ALKqPwcCHBRo8WLGHPH7RSylAzNXst8lc8Rop4cdunSHrApo9E/ZIVdC eiQyd/FdnxIkWskE8nzh1HMbxOFcpk6f1EHqYx+ZgXIs X-Google-Smtp-Source: ADUXVKJjA0w0CljwQqode4hJ5yUPmP9aNZFn+jydrOUvyVp8DVw2rcNd9un/Wm3bH8pRH5NkQuX7W2X++ASPruOtzow= X-Received: by 2002:a50:aec8:: with SMTP id f8-v6mr25266840edd.72.1528139417817; Mon, 04 Jun 2018 12:10:17 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:9147:0:0:0:0:0 with HTTP; Mon, 4 Jun 2018 12:10:17 -0700 (PDT) From: Ian Lance Taylor Date: Mon, 4 Jun 2018 12:10:17 -0700 Message-ID: Subject: Go patch committed: Don't crash on cyclic var/type dependencies To: gcc-patches , gofrontend-dev@googlegroups.com This patch by Than McIntosh fixes type traversal in the Go frontend to avoid compiler crashes for test cases where a type T includes an expression that refers back to the type without actually explicitly mentioning T. Examples include: var x [uintptr(unsafe.Sizeof(&x))]byte var a [len(a)]int The fix involves expanding the set of types that the traversal code "remembers" (to avoid cycles) to include array types, and introducing an additional guard in Builtin_call_expression::do_is_constant to catch cyclic type constructs. Fixes https://golang.org/issue/{25299,25679,25315,25680}. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 261041) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -79eca4fd642724d89e9bec8f79889451f6632a46 +8e74a218e11ef6eaaf7014a3ad1cd0b13359c607 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 261041) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -8061,9 +8061,13 @@ Builtin_call_expression::do_is_constant( arg_type = arg_type->points_to(); if (arg_type->array_type() != NULL - && arg_type->array_type()->length() != NULL - && Builtin_call_expression::array_len_is_constant(arg)) - return true; + && arg_type->array_type()->length() != NULL) + { + this->seen_ = true; + bool ret = Builtin_call_expression::array_len_is_constant(arg); + this->seen_ = false; + return ret; + } if (this->code_ == BUILTIN_LEN && arg_type->is_string_type()) { Index: gcc/go/gofrontend/gogo.cc =================================================================== --- gcc/go/gofrontend/gogo.cc (revision 261041) +++ gcc/go/gofrontend/gogo.cc (working copy) @@ -8258,8 +8258,16 @@ Traverse::remember_type(const Type* type // We mostly only have to remember named types. But it turns out // that an interface type can refer to itself without using a name // by relying on interface inheritance, as in - // type I interface { F() interface{I} } + // + // type I interface { F() interface{I} } + // + // Similarly it is possible for array types to refer to themselves + // without a name, e.g. + // + // var x [uintptr(unsafe.Sizeof(&x))]byte + // if (type->classification() != Type::TYPE_NAMED + && type->classification() != Type::TYPE_ARRAY && type->classification() != Type::TYPE_INTERFACE) return false; if (this->types_seen_ == NULL)