From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fencepost.gnu.org (fencepost.gnu.org [IPv6:2001:470:142:3::e]) by sourceware.org (Postfix) with ESMTPS id A8AF43870842 for ; Thu, 17 Dec 2020 04:59:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A8AF43870842 Received: from eggs.gnu.org ([2001:470:142:3::10]:34870) by fencepost.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kplOC-0004GB-K8 for gcc-patches@gnu.org; Wed, 16 Dec 2020 23:59:46 -0500 Received: from mail-qk1-x72d.google.com ([2607:f8b0:4864:20::72d]:43505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kplO9-0005I9-VK for gcc-patches@gnu.org; Wed, 16 Dec 2020 23:59:44 -0500 Received: by mail-qk1-x72d.google.com with SMTP id 143so25342359qke.10 for ; Wed, 16 Dec 2020 20:59:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=9i/17mQtbsNCOcl3V1tGwLob8TOPeYVzmM5wtl4mYr0=; b=UG/+32SqNzKvKPHhMbCmh/5IPyHg7QfTgy9PaX2Dux6QvYq6MH/R2ACrWplhUmDQD3 bOwOAC1iVn8TZP03cc0G5uUq99sbAhZyZeIQfB9dx01kYlA5+Pb1/HSt1G4YaBbQrFBo Q+BgqGXH1HZEx1aLaYDYNYS6ZILQivNtx3qMXWBx76EbOQcficWH/JHBdGbk0ThZzr/r t4v136oiy232NfKrSDvCa0RkMv+6ObAiy8E8CQwjmdiQ5dUnsoOJaAtGWENlYoZUQQVi BK26U2vPyg+Bt96q7AnBwsY76RME+vv2E3CIGPspOQk7Mu75jF0ttbHPdSzvs9x7riyu KEmQ== X-Gm-Message-State: AOAM5308L/XKo5jdpzxmGK2ODSQBruTdVBoiJV3589MncT8LS/UBzod6 qdMWY8tn3KHQ2+/t3yVtV3A= X-Google-Smtp-Source: ABdhPJzSXTwk6+rhelJgrQa5GZV4H1q8Lh6zN+n3xtmXt23JnEQ5V/+0wJYLKkWyForU4UEMy4XmLw== X-Received: by 2002:a37:4c16:: with SMTP id z22mr27606106qka.22.1608181180515; Wed, 16 Dec 2020 20:59:40 -0800 (PST) Received: from langur.local (pool-108-21-192-156.nycmny.fios.verizon.net. [108.21.192.156]) by smtp.gmail.com with ESMTPSA id 141sm2800272qkn.53.2020.12.16.20.59.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Dec 2020 20:59:39 -0800 (PST) Subject: Re: [PATCH] Correct -fdump-go-spec's handling of incomplete types From: Nikhil Benesch To: Rainer Orth Cc: Ian Lance Taylor , gcc-patches , gofrontend-dev References: <52818e83-3ff8-31b3-f444-eb21e3931a82@gmail.com> <2913efa6-53ed-d5c1-fa04-7d14539dfbd9@gmail.com> <4b48e0a9-cac4-9df1-8cbe-ce499284f8b0@gmail.com> <3ea15d6f-20d1-69e5-aecf-003f51a385ff@gmail.com> Message-ID: Date: Wed, 16 Dec 2020 23:59:38 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <3ea15d6f-20d1-69e5-aecf-003f51a385ff@gmail.com> Content-Type: multipart/mixed; boundary="------------9E01B829C6AC27C82C304C15" Content-Language: en-US Received-SPF: pass client-ip=2607:f8b0:4864:20::72d; envelope-from=nikhil.benesch@gmail.com; helo=mail-qk1-x72d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2020 04:59:50 -0000 This is a multi-part message in MIME format. --------------9E01B829C6AC27C82C304C15 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 12/16/20 3:13 PM, Nikhil Benesch wrote: > On 12/16/20 2:20 PM, Rainer Orth wrote: >> Hi Nikhil, >> >>> On 12/15/20 3:00 AM, Nikhil Benesch wrote: >>>> If this patch looks good, I'll submit it upstream tomorrow. >>> >>> Assuming no news is good news, I sent >>> https://go-review.googlesource.com/c/gofrontend/+/278672. >> >> sorry for the delay, but unfortunately news is not so good: I get >> >> runtime_sysinfo.go:315:18: error: use of undefined type '_ucontext' >> 315 | type _ucontext_t _ucontext >> | ^ > > No problem, Rainer. I figured there would be some hiccups. The somewhat good news > is that this error appears to be independent of the patch I sent upstream. > > I suspect what is happening here is that godump sees "typedef ucontext_t struct > ucontext" and outputs the typedef immediately. Only later does it observe that > "struct ucontext" is invalid. At that point it is too late to comment out the > typedef for _ucontext_t. Oh, wait, Rainer, did you apply *both* solaris-godump.patch and invalid-dummy.patch? I think if you apply only the former (i.e., only solaris-godump.patch), which is the only bit I've submitted upstream, all will be well. For good measure, I've also fixed the issue in invalid-dummy.patch and attached a new version. But I'm still not sure whether it is a worthwhile change, and it's something we can discuss separately from solaris-godump.patch. Nikhil --------------9E01B829C6AC27C82C304C15 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="invalid-dummy-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="invalid-dummy-2.patch" diff --git a/gcc/godump.c b/gcc/godump.c index ff3a4a9c52c..b4cbdf275f2 100644 --- a/gcc/godump.c +++ b/gcc/godump.c @@ -670,6 +670,8 @@ go_force_record_alignment (struct obstack *ob, const char *type_string, return index; } +static void go_output_typedef (class godump_container *container, tree decl); + /* Write the Go version of TYPE to CONTAINER->TYPE_OBSTACK. USE_TYPE_NAME is true if we can simply use a type name here without needing to define it. IS_FUNC_OK is true if we can output a func @@ -705,6 +707,7 @@ go_format_type (class godump_container *container, tree type, { tree name; void **slot; + void **islot; /* References to complex builtin types cannot be translated to Go. */ @@ -714,10 +717,32 @@ go_format_type (class godump_container *container, tree type, name = TYPE_IDENTIFIER (type); - slot = htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (name), + + slot = htab_find_slot (container->type_hash, IDENTIFIER_POINTER (name), NO_INSERT); - if (slot != NULL) - ret = false; + islot = htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (name), + NO_INSERT); + if (islot != NULL) + { + /* The named type is known to be invalid. */ + ret = false; + } + else if (slot == NULL) + { + size_t pos; + + /* The named type is not known to be either valid or invalid. + Check to see if the named type is valid. Doing so requires + formatting the type and throwing away the result, which is + a bit silly. */ + + pos = obstack_object_size (ob); + + if (!go_format_type (container, type, false, false, NULL, false)) + ret = false; + + ob->next_free = ob->object_base + pos; + } /* References to incomplete structs are permitted in many contexts, like behind a pointer or inside of a typedef. So @@ -1351,11 +1376,9 @@ find_dummy_types (const char *const &ptr, godump_container *adata) class godump_container *data = (class godump_container *) adata; const char *type = (const char *) ptr; void **slot; - void **islot; slot = htab_find_slot (data->type_hash, type, NO_INSERT); - islot = htab_find_slot (data->invalid_hash, type, NO_INSERT); - if (slot == NULL || islot != NULL) + if (slot == NULL) fprintf (go_dump_file, "type _%s struct {}\n", type); return true; } diff --git a/gcc/testsuite/gcc.misc-tests/godump-1.c b/gcc/testsuite/gcc.misc-tests/godump-1.c index d37ab0b5af4..4492a6e4887 100644 --- a/gcc/testsuite/gcc.misc-tests/godump-1.c +++ b/gcc/testsuite/gcc.misc-tests/godump-1.c @@ -304,6 +304,13 @@ long double ld_v1; ld_t ld_v2; /* { dg-final { scan-file godump-1.out "(?n)^// var _ld_v2 INVALID-float-\[0-9\]*$" } } */ +typedef struct ld_s ld_s_t1; +typedef struct ld_s { long double ld_s_f; } ld_s_t2; +/* { dg-final { scan-file godump-1.out "(?n)^// type _ld_s_t1 _ld_s$" } } * +/* { dg-final { scan-file godump-1.out "(?n)^// type _ld_s struct \{ ld_s_f INVALID-float-\[0-9\]*; \}$" } } */ +/* { dg-final { scan-file godump-1.out "(?n)^// type _ld_s_t2 _ld_s$" } } * +/* { dg-final { scan-file-not godump-1.out "(?n)^type _ld_s struct \{\}$" } } */ + /*** complex types ***/ typedef _Complex cx_t; /* { dg-final { scan-file godump-1.out "(?n)^type _cx_t complex\[0-9\]*$" } } */ @@ -476,6 +483,8 @@ struct { double d; uint8_t : 0; } sd_not_equiv; /* { dg-final { scan-file godump-1.out "(?n)^var _sd_not_equiv struct \{ d float\[0-9\]*; \}$" } } */ typedef struct s_undef_t s_undef_t2; +/* { dg-final { scan-file godump-1.out "(?n)^type _s_undef_t2 _s_undef_t$" } } */ +/* { dg-final { scan-file godump-1.out "(?n)^type _s_undef_t struct \{\}$" } } */ typedef struct s_fwd *s_fwd_p; /* { dg-final { scan-file godump-1.out "(?n)^type _s_fwd_p \\*_s_fwd$" } } */ @@ -816,6 +825,8 @@ union { uint64_t : 1; uint8_t ca[5]; } u2_size; /* { dg-final { scan-file godump-1.out "(?n)^var _u2_size struct \{ ca \\\[4\\+1\\\]uint8; \}$" } } */ typedef union u_undef_t u_undef_t2; +/* { dg-final { scan-file godump-1.out "(?n)^type _u_undef_t2 _u_undef_t$" } } */ +/* { dg-final { scan-file godump-1.out "(?n)^type _u_undef_t struct \{\}$" } } */ typedef union { uint64_t b : 1; uint8_t ca[5]; } tu3_size; /* { dg-final { scan-file godump-1.out "(?n)^type _tu3_size struct \{ ca \\\[4\\+1\\\]uint8; Godump_0_pad \\\[.\\\]byte; Godump_1_align \\\[0\\\]u?int64; \}$" } } */ --------------9E01B829C6AC27C82C304C15--