From patchwork Tue Feb 9 16:16:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1438469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=r782H5ch; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DZp150P9Qz9sSC for ; Wed, 10 Feb 2021 03:16:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A1AB3938C27; Tue, 9 Feb 2021 16:16:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 1F2043874C38 for ; Tue, 9 Feb 2021 16:16:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1F2043874C38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x731.google.com with SMTP id a19so18511330qka.2 for ; Tue, 09 Feb 2021 08:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=UzUgFxYv+mIn5NGzxtqQ5pKJ2wnAYomK/A2GhH2K7Zk=; b=r782H5chkva0SO8xcGHM1oJZpICkt8SCFml3ySjUImxyCxtV5U1JOjnv98nFSToKPO IHACAuzLs9Itc+vWSIMq8hQxkJhikkDyW3F3FuynY9b4673s/BudazZI2BIpxRYJ74ab EIBEU9XqA2ZtmPTQwFLKjkl2yG82wzIBnml4hBB9o9MEQyChbMMQa4IfAvzl2I0ItyDD 6E3mLFYcOiOb7AUZZtvY776v1wbPT7/AUKWYz/QiFYd3iKiKtZE2XTfEaarVDYuFKWB+ P9wSku1uTOQiQ90u6hWwhdQsgZv/CaF4dl5bNYhCY61+tfk2hd9XuA+UlTm0V6b63wjF Mt8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=UzUgFxYv+mIn5NGzxtqQ5pKJ2wnAYomK/A2GhH2K7Zk=; b=a35ZWZeuu2MdBPpvvSI/4l2KmDl7HMm7HunPET8HSLu4m2DaEmf9yM3w8oJBYMBtZK MCpU+OA6ToMQ/T5OZWi+t9nB1T/H8ydAclfC+sHGfBEkavZh8GjAJ4p2f7b66yLxiAw1 sjwzrxvH5dsUI9YLIYczUvuYaqYlT1IXDfRsLaR0Lx6PViStSBm+k3DPaENHhcbbmY+B UY7b2EGf8h4aDeGbNQSWEdSBz6zbMGA1TZdiik6VGYAA6M4b5dqDQsRcHFpEyBS7bS78 khohnq+fnEtoMcsl50zm4VV8tVSDRmgfLELA2KrasceVBtUkWglCRo0uX5OOOZYa/Wjr wlIQ== X-Gm-Message-State: AOAM531mLV4O4mtifb0PdY79ReqielIynoOGL3SOADlcKGi5mpZeANOS M5YvV2PNTaO07Z1z5YWc+Hs= X-Google-Smtp-Source: ABdhPJwPa5mJDTvHliXQSrQDpTOZNxv8Sxrxh3r80+AhhHfilFA1dlWqdNl63aFgRPjGDzyZ+LgyMw== X-Received: by 2002:a37:a8cc:: with SMTP id r195mr9676688qke.151.1612887378706; Tue, 09 Feb 2021 08:16:18 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:fd1c:601c:2f75:70e? ([2620:10d:c091:480::1:5700]) by smtp.googlemail.com with ESMTPSA id v5sm6472893qkg.47.2021.02.09.08.16.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Feb 2021 08:16:17 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Fix indirect partitions [PR 98944] Message-ID: Date: Tue, 9 Feb 2021 11:16:16 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The most recent reimplementation of module loading initialization changed the behaviour of setting an import's location, and broke some partition handling. PR c++/98944 gcc/cp/ * module.cc (module_state::is_rooted): Rename to ... (module_state::has_location): ... here. Adjust callers. (module_state::read_partitions): Adjust validity check. Don't overwrite a known location. gcc/testsuite/ * g++.dg/modules/pr98944_a.C: New. * g++.dg/modules/pr98944_b.C: New. * g++.dg/modules/pr98944_c.C: New. * g++.dg/modules/pr98944_d.C: New. diff --git c/gcc/cp/module.cc w/gcc/cp/module.cc index 41ce2011525..0749db8fe94 100644 --- c/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -3608,8 +3608,8 @@ class GTY((chain_next ("%h.parent"), for_user)) module_state { } public: - /* Is this not a real module? */ - bool is_rooted () const + /* Is this a real module? */ + bool has_location () const { return loc != UNKNOWN_LOCATION; } @@ -4416,7 +4416,7 @@ dumper::operator () (const char *format, ...) const char *str = "(none)"; if (module_state *m = va_arg (args, module_state *)) { - if (!m->is_rooted ()) + if (!m->has_location ()) str = "(detached)"; else str = m->get_flatname (); @@ -14441,16 +14441,17 @@ module_state::read_partitions (unsigned count) dump () && dump ("Reading elided partition %s (crc=%x)", name, crc); module_state *imp = get_module (name); - if (!imp || !imp->is_partition () || imp->is_rooted () - || get_primary (imp) != this) + if (!imp /* Partition should be ... */ + || !imp->is_partition () /* a partition ... */ + || imp->loadedness != ML_NONE /* that is not yet loaded ... */ + || get_primary (imp) != this) /* whose primary is this. */ { sec.set_overrun (); break; } - /* Attach the partition without loading it. We'll have to load - for real if it's indirectly imported. */ - imp->loc = floc; + if (!imp->has_location ()) + imp->loc = floc; imp->crc = crc; if (!imp->filename && fname[0]) imp->filename = xstrdup (fname); @@ -18857,7 +18858,7 @@ direct_import (module_state *import, cpp_reader *reader) timevar_start (TV_MODULE_IMPORT); unsigned n = dump.push (import); - gcc_checking_assert (import->is_direct () && import->is_rooted ()); + gcc_checking_assert (import->is_direct () && import->has_location ()); if (import->loadedness == ML_NONE) if (!import->do_import (reader, true)) gcc_unreachable (); @@ -18904,7 +18905,7 @@ import_module (module_state *import, location_t from_loc, bool exporting_p, linemap_module_reparent (line_table, import->loc, from_loc); } gcc_checking_assert (!import->module_p); - gcc_checking_assert (import->is_direct () && import->is_rooted ()); + gcc_checking_assert (import->is_direct () && import->has_location ()); direct_import (import, reader); } @@ -18934,7 +18935,7 @@ declare_module (module_state *module, location_t from_loc, bool exporting_p, } gcc_checking_assert (module->module_p); - gcc_checking_assert (module->is_direct () && module->is_rooted ()); + gcc_checking_assert (module->is_direct () && module->has_location ()); /* Yer a module, 'arry. */ module_kind &= ~MK_GLOBAL; diff --git c/gcc/testsuite/g++.dg/modules/pr98944_a.C w/gcc/testsuite/g++.dg/modules/pr98944_a.C new file mode 100644 index 00000000000..9475317dc82 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr98944_a.C @@ -0,0 +1,9 @@ +// PR 98944, the example in [module.unit]/4 +// { dg-additional-options -fmodules-ts } + +// tu3 + +module A:Internals; +// { dg-module-cmi A:Internals } + +int bar(); diff --git c/gcc/testsuite/g++.dg/modules/pr98944_b.C w/gcc/testsuite/g++.dg/modules/pr98944_b.C new file mode 100644 index 00000000000..209eafccc76 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr98944_b.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +// tu2 +export module A:Foo; +// { dg-module-cmi A:Foo } + +import :Internals; +export int foo() { return 2 * (bar() + 1); } diff --git c/gcc/testsuite/g++.dg/modules/pr98944_c.C w/gcc/testsuite/g++.dg/modules/pr98944_c.C new file mode 100644 index 00000000000..90be60f2629 --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr98944_c.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +// tu1 +export module A; +// { dg-module-cmi A } + +export import :Foo; +export int baz(); diff --git c/gcc/testsuite/g++.dg/modules/pr98944_d.C w/gcc/testsuite/g++.dg/modules/pr98944_d.C new file mode 100644 index 00000000000..25364ab9aae --- /dev/null +++ w/gcc/testsuite/g++.dg/modules/pr98944_d.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +// tu4 +module A; + +import :Internals; +int bar() { return baz() - 10; } +int baz() { return 30; }