From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 90F53385841C for ; Mon, 13 May 2024 02:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90F53385841C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 90F53385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715569126; cv=none; b=JewHBwU0F72CcMs5QwYjp9ujg8rSYuWzBe8dhUh7kAQtT+kZDa+gSeDAaBkrqWKJdljepRIokV1fW2+X+IKNCwOhPlInJrY6jHMCC1+1Jx3qbNMIFPnhdvgnrr4bkNwXIlL0p8+VBIRRY+UmKXsKcZwQbbmGtP4fA0kY3/5K2gA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715569126; c=relaxed/simple; bh=FBg4p/NYsVm6MRTOrYEbvMjkNGKbsokKEgyfoxks4ok=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=pQt1DpsKmg6if7SovdQ6AoLHjCl6Mlil8vSe4r6GhukfghUPsrUesk8YlNVrSwKGMpa67uFU7nGYUqt2hJNj2+BHfprVRcQ7yq4pHjkHiw9DY0a/Q0qZqPCbjrD4G7WuflZFYaxq6PlrhF/mRsgw7ZgyklLGKdEGPLKsQxScpUo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6f4e59191a1so1746737b3a.1 for ; Sun, 12 May 2024 19:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715569123; x=1716173923; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=337okQRzEDFw9ce8Q3QKb2mCBFkAV8QoifYUEntM2Rk=; b=a+lCGpCPgCLsymdxxecPw2qVbRao0RKw9G95qOrtBBiHgM1nnSRsHVm/yxAi5jXq+v M06Qzpz48CtlMg2ZepWWVMgNbgCLtjcqF1c25QDrMMYiY420W2XsEuiPE8FjJzqlRLqQ CEwVm9DPcbBeLABDR7AMwDdYK9/gZB2TITMD5AOfJWI4EV9Qsb/d2MF9pEJZHgM0tMDW GLeVLwoUK53cVlRbI7bnQDoPJ5Roo86XPi0sZt0Vx7m0l0GVOr58KqYzDlEWQO3Vvx5D Bdfy37fyrBnDZZgOQ70Xgxx4KdkqMxhqbs0riJfe/NgzTXx5A7SBvSvtrm1hH7U1bXxp T+Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715569123; x=1716173923; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=337okQRzEDFw9ce8Q3QKb2mCBFkAV8QoifYUEntM2Rk=; b=rhfYMgMaAn3cs7JkXfcdJUy0Syv9YimYvARnB45VsWF34ThpMQdeNGzKJ21VLYLrue xUgfo1ctXEkJMtcrusrTCY3td+4FF7HEr1UF5Jvn8XW8X5UgslLeNgz0EGm+g2kbVjJg buwY5wk/noesTm8usxfPuDw6H6P+vJ3j3Fyig1Oz2TXxesJYfpplmsa2RKJ9kmGlHSRf 7MH27riBV6BpyxtWO8N9K+sgM3HDJDfz2ra3vO+fp+utug3IqhCoMQ7Rl6GLT/zM5rGq yxkG332tsRngPJ2KodNBmJa3el9q56aoH8k0j6WZDcoSB+LfjyI/aAj8svyfH79NPqsA MWCA== X-Gm-Message-State: AOJu0YwmxrzvdDMWNnQWBCq0Q1TrfHWm5heqp9ERn4LRXPvVIk4nk+PM K78eti1gIYpabhV5FPxZU5+RurH6oRtP9uRpGI+hslMogbjrXsr3CBvtIQ== X-Google-Smtp-Source: AGHT+IH2W9kMZ+88lyoElAiiJSbPDUpxq/wm3eTV8A8a8NhNGR7WYA61B5HFVKO31oDQ+1wRxiY1lQ== X-Received: by 2002:a05:6a00:3d54:b0:6f4:4850:428b with SMTP id d2e1a72fcca58-6f4e0355dacmr10068184b3a.22.1715569123313; Sun, 12 May 2024 19:58:43 -0700 (PDT) Received: from Thaum. (14-200-72-253.tpgi.com.au. [14.200.72.253]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6341180dc5csm5754807a12.93.2024.05.12.19.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 19:58:42 -0700 (PDT) Message-ID: <664181e2.650a0220.dbfd8.e3d5@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 13 May 2024 12:58:38 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Remember that header units have CMIs MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- This appears to be an oversight in the definition of module_has_cmi_p; this comes up transitively in other functions used for e.g. determining whether a name could potentially be accessed in a different translation unit. This change will allow us to use the function directly in more places that need to additional work only if generating a module CMI in the future. gcc/cp/ChangeLog: * cp-tree.h (module_has_cmi_p): Also true for header units. gcc/testsuite/ChangeLog: * g++.dg/modules/linkage-3_a.H: New test. * g++.dg/modules/linkage-3_b.C: New test. * g++.dg/modules/linkage-3_c.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/cp-tree.h | 2 +- gcc/testsuite/g++.dg/modules/linkage-3_a.H | 19 +++++++++++++++++++ gcc/testsuite/g++.dg/modules/linkage-3_b.C | 9 +++++++++ gcc/testsuite/g++.dg/modules/linkage-3_c.C | 10 ++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/linkage-3_a.H create mode 100644 gcc/testsuite/g++.dg/modules/linkage-3_b.C create mode 100644 gcc/testsuite/g++.dg/modules/linkage-3_c.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index db098c32f2d..609904918ba 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7379,7 +7379,7 @@ inline bool module_interface_p () inline bool module_partition_p () { return module_kind & MK_PARTITION; } inline bool module_has_cmi_p () -{ return module_kind & (MK_INTERFACE | MK_PARTITION); } +{ return module_kind & (MK_INTERFACE | MK_PARTITION | MK_HEADER); } inline bool module_purview_p () { return module_kind & MK_PURVIEW; } diff --git a/gcc/testsuite/g++.dg/modules/linkage-3_a.H b/gcc/testsuite/g++.dg/modules/linkage-3_a.H new file mode 100644 index 00000000000..1e0ebd927e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/linkage-3_a.H @@ -0,0 +1,19 @@ +// { dg-additional-options "-fmodule-header -Wno-error=c++20-extensions" } +// { dg-module-cmi {} } + +// Like linkage-1, but for header units. + +// External linkage definitions must be declared as 'inline' to satisfy +// [module.import] p6, so we don't need to care about voldemort types in +// function definitions. + +// Strictly speaking this is not required to be supported: +// [module.import] p5 says that when two different TUs import header-names +// identifying the same header or source file, it is unspecified whether +// they import the same header unit, and thus 's' could be a different entity +// in each TU. But with out current implementation this seems to reasonable to +// allow (and it does currently work). + +struct { int y; } s; +decltype(s) f(); // { dg-warning "used but not defined" "" { target c++17_down } } +inline auto x = f(); diff --git a/gcc/testsuite/g++.dg/modules/linkage-3_b.C b/gcc/testsuite/g++.dg/modules/linkage-3_b.C new file mode 100644 index 00000000000..935ef6150ec --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/linkage-3_b.C @@ -0,0 +1,9 @@ +// { dg-additional-options "-fmodules-ts" } + +struct {} unrelated; + +import "linkage-3_a.H"; + +decltype(s) f() { + return { 123 }; +} diff --git a/gcc/testsuite/g++.dg/modules/linkage-3_c.C b/gcc/testsuite/g++.dg/modules/linkage-3_c.C new file mode 100644 index 00000000000..be527ff552d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/linkage-3_c.C @@ -0,0 +1,10 @@ +// { dg-module-do run } +// { dg-additional-options "-fmodules-ts" } + +import "linkage-3_a.H"; + +int main() { + auto a = x.y; + if (a != 123) + __builtin_abort(); +} -- 2.43.2