From patchwork Sat Jan 11 07:33:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 104570 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B8983857BB3 for ; Sat, 11 Jan 2025 07:36:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B8983857BB3 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Dgu2/yoF X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 36677385828B for ; Sat, 11 Jan 2025 07:34:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36677385828B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36677385828B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736580867; cv=none; b=trdjA5GBB2wQmCR0mD6GPkNiyhbghe+LEjmNQWh+G7NbdGq0EUHzO1ITRJIikRDu8iCw9GaotV8nZN/I0tFPvXt6hf+di+97QqsWfdYgq07iMpGKRYgsp23O247KfVvGRJv35LKW/tnNKHF6gYj5D3oWz73yWzq0Qpz+sx7wDzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736580867; c=relaxed/simple; bh=uF6Gs4orpYGN3ITarAwowYhBC2Nt/0tvyPwRwXObaIY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wRHCxjh8mlToCNdGbhjPYKCnHKOpiDKHJRwk0/jT8JaSyGV6C8z5nBT3KVlOY02YBwOFXJw0YhctTVosfTXVrkSrDleuODWPWMq5GJklMIgRRdE6UsNkFsgYZY7tjo4TYNNDc1MT6tYAVEpvTw+u6i0euGVPl9yieADqOI6FLTc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36677385828B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736580867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j825aGqD0Iz6fTIr8/dCw/LjT0bAXtWWYcI59/IY4aE=; b=Dgu2/yoFtaSt2O9ivcNYPLeM8dMLhNDHfxHLWoGOH4xZRojOtyrS43zGdm+cJKql4Iw/Wo dS7Mztp/NHJ6LrXgjaQuFmdErvCqhWvNTNlzSYTptqef0+uzxt/fhPBSmNGgPwc5zzVy9r uqEVM7qEiu2We40/PZkHsq7kJc6g3SI= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-i0wmyuZtMeGK0r2jSGSkZg-1; Sat, 11 Jan 2025 02:34:18 -0500 X-MC-Unique: i0wmyuZtMeGK0r2jSGSkZg-1 X-Mimecast-MFC-AGG-ID: i0wmyuZtMeGK0r2jSGSkZg Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6d8f51b49e5so51338816d6.1 for ; Fri, 10 Jan 2025 23:34:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736580857; x=1737185657; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j825aGqD0Iz6fTIr8/dCw/LjT0bAXtWWYcI59/IY4aE=; b=KC/+xiOcZpJonMRE48W6KStJW/EW2sSyXI1uUFuaw6ArmSIjBBK4dI5zkhbfcyrjUj epwBEa3OzL5MYmeU10ItYs03XOQcU6BCR3njdQPvFegrR2Jm8uieXU0c3E3ZAWtsCX5F pH/6bjwbQQ7mxueBOND/9CczZqQuZN/9Ul0OJrzXMlpA0FmUXBRXY6PHJYyB+T3e86gr BZh7ind8jCwGJyDM4kx6xb23EQVFrVRws1/CZsVxaE5p9wBmXGVb1T/e4FZ1T32OW6vf XAnZslg8Lk4nln+uzCUjzFVFHaimaLh9zDZ4VJoV71evRl8TzXSbNnpr4jgG8fW/fPKc 2yLQ== X-Gm-Message-State: AOJu0YxJBsGLowNkHGVOya3rRes9MBkVREtrbiHffBhipdh71hsfKeYy 03dq4SpkIfXeOeKIh7DyjEddSgIcZno+LuGIvfPYK7mMIEg/2OUPVXCpBimZWMhm3WDjyUeNmpe Bu1q27leiFpHqWGAgNXh3Q0vhdJ4JO4LtvKB/wwiZyoMtrzfvzc4m4QU2AgAmxu+Pt8rTb5+tys PBHHHJrkAW6y9w0xS1ioudnLK4KgNkGBkdhtC0Bg== X-Gm-Gg: ASbGncs62wyt9fGdlXhHO48S5qMLQl5GNYv7osmDxiYebpdDgN/XDp5gTnxYRBXADDm 2n9regfkWYj7PYT49ljsM6sW3APpoAvsByYo3DEA8Wng8wnBAWiL71P+epEyvjk3TBkMMvEbQWU rKyOo2jkYsjeeTraZTRKZBC3pLsWRstiqaQdKYHxPEp85doUYihrlS8kvE7gndbySIGEcfltLQQ hPPqbFynl893qfj8tPbIB7BJ0MvsnYkwRl4d7MycfaRjNb6wFTQmgPdx9cWhLmCsNVxJEAuVXqJ EbLgLXG96bQeJUAwlG9lkdCswNIK15L5aBlTYcw/MaJv3iD2TZVvvafYgMa8PJFjwTn9kzEqDSy rrqBRVztprA== X-Received: by 2002:ad4:5ca1:0:b0:6d8:9b7b:14c9 with SMTP id 6a1803df08f44-6df9b1b5254mr160258916d6.8.1736580856957; Fri, 10 Jan 2025 23:34:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGZXzvhihdldkbcjJiH9W5V9uwq5tAvpEBBCRyuwo4ZJ9VO+k6xjiQLkp60AmoJNfEiHO07g== X-Received: by 2002:ad4:5ca1:0:b0:6d8:9b7b:14c9 with SMTP id 6a1803df08f44-6df9b1b5254mr160258706d6.8.1736580856537; Fri, 10 Jan 2025 23:34:16 -0800 (PST) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dfad88e2eesm17562076d6.33.2025.01.10.23.34.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 23:34:15 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed 1/2] c++: modules and class attributes Date: Sat, 11 Jan 2025 02:33:44 -0500 Message-ID: <20250111073412.190565-1-jason@redhat.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: e10SSrgO0ubb7PipNhu8C90wTZ9Jxe4Il_RDxiGN-8M_1736580858 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- std/time/traits/is_clock.cc was getting a warning about applying the deprecated attribute to a variant of auto_ptr, which was wrong because it's on the primary type. This turned out to be because we were ignoring the attributes on the definition of auto_ptr because the forward declaration in unique_ptr.h has no attributes. We need to merge attributes as usual in a redeclaration. gcc/cp/ChangeLog: * module.cc (trees_in::decl_value): Merge attributes. gcc/testsuite/ChangeLog: * g++.dg/modules/attrib-1_a.C: New test. * g++.dg/modules/attrib-1_b.C: New test. --- gcc/cp/module.cc | 4 ++++ gcc/testsuite/g++.dg/modules/attrib-1_a.C | 13 +++++++++++++ gcc/testsuite/g++.dg/modules/attrib-1_b.C | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/attrib-1_a.C create mode 100644 gcc/testsuite/g++.dg/modules/attrib-1_b.C base-commit: f30423ea8c2152dcee91056e75a4f3736cce6a6e diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 4fbe522264b..321d4164a6a 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -8637,6 +8637,10 @@ trees_in::decl_value () TYPE_STUB_DECL (type) = stub_decl ? stub_decl : inner; if (stub_decl) TREE_TYPE (stub_decl) = type; + + /* Handle separate declarations with different attributes. */ + tree &eattr = TYPE_ATTRIBUTES (TREE_TYPE (existing)); + eattr = merge_attributes (eattr, TYPE_ATTRIBUTES (type)); } if (inner_tag) diff --git a/gcc/testsuite/g++.dg/modules/attrib-1_a.C b/gcc/testsuite/g++.dg/modules/attrib-1_a.C new file mode 100644 index 00000000000..d5f89d0c068 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/attrib-1_a.C @@ -0,0 +1,13 @@ +// { dg-additional-options "-fmodules -Wno-global-module" } +// { dg-module-cmi M } + +module; + +template struct A { + void f() const { } +} __attribute__ ((deprecated ("y tho"))); + +export module M; + +export template +A a; // { dg-warning "deprecated" } diff --git a/gcc/testsuite/g++.dg/modules/attrib-1_b.C b/gcc/testsuite/g++.dg/modules/attrib-1_b.C new file mode 100644 index 00000000000..48ac751b03d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/attrib-1_b.C @@ -0,0 +1,10 @@ +// { dg-additional-options -fmodules } + +template struct A; + +import M; + +int main() +{ + a.f(); +} From patchwork Sat Jan 11 07:33:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 104569 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADFF5385780D for ; Sat, 11 Jan 2025 07:35:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADFF5385780D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OdLjv8IB X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 69DCA3858401 for ; Sat, 11 Jan 2025 07:34:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69DCA3858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 69DCA3858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736580864; cv=none; b=gjJum4aPMM0ZjCVHJ93OakCAyOrm4sj6KLuurDma9oo7FMTTEb+pkBCrHjLmbOgCT/z/8BMchYAbtKxyOYeCMda9yGLz6XfDqaIgvmG1sp+YvJZD8B3XiNeje1DytN+R52Yy/JTfgcUAHZzH4JJPjIpQ5M95uKECMzxUeuiwEFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736580864; c=relaxed/simple; bh=9s/UTLxQVgbri3XKQ53L/PZeP6hBI1i4X+SUL6MwyTU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=e7NNRHyersEdygn+gnyvIn4sH+Lwi5vsJzc5plquKy2olPbO3mFxV1klHSMO41qQJXFcWibkB9rDYbzopkYXrZKaYBVxVRYYe4KafmueyISYMPYcJSEiVcuNUeEizDV+gIqaQ+fsJvodm+04ZlrQ4UnRdwXCAc+C6Ca1satKHXg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69DCA3858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736580864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xrdE58Mls2Gyi+KMu+TYu8CFIYf/Y7KUAxJ0yqCXoPM=; b=OdLjv8IBoVqq7GOnJopiVZlReZ1Ggb4W+kRcuMjq7qBdTGyaWKVhs5RoSPC/QMukkOPDXP yD/Dmgbssz/mV1GeHpDZrebnvcCCqHvXDhWLuRCmTlBmxMP6w2rCtivapilbaP85X9j3Ai JA2dHs0bA8TPdjlPpLVquAMC5xJFf2Y= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-vH3fmEFKPYOwbmXWDFrlew-1; Sat, 11 Jan 2025 02:34:21 -0500 X-MC-Unique: vH3fmEFKPYOwbmXWDFrlew-1 X-Mimecast-MFC-AGG-ID: vH3fmEFKPYOwbmXWDFrlew Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4678b42cbfeso53214871cf.3 for ; Fri, 10 Jan 2025 23:34:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736580859; x=1737185659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xrdE58Mls2Gyi+KMu+TYu8CFIYf/Y7KUAxJ0yqCXoPM=; b=qlGRzB0k7AGDozUm12Yvyy5jmi2eKxQAV6FNKp8sSUS3lvQsz6bRGLD3jcYcR8B8UQ pJRkCknFIYorSm1xFTSYAhnb1NojQ1UmXzSV9WEkBtx9gkgiDoFZ3C4fyIBlH8G1xAXY I5BkoRvxAmKEyIP5SIqlxujSBBXiwoIRqIJ1GxZQpReO5vfjrMWjjQzIBsJ92BzfXFxf jdW/x+XMXtd3NKgI11VrVuyyRbDEc2s/1DcVMDI8UXDI2MZGWdw4efl2eX/jgwTnN759 GWrKwtRN4SE2Wd0OE+5g+JygqoU/7L6sC9zbQiqkv0J73TEZQjgDEXYV5uGmBhCMuCRb 1kzg== X-Gm-Message-State: AOJu0YwlK5+/YkW9xCBLvf8aYP1Ir7tLQIR5pdHrjZxCbip3a+gblk8G ukCPC6ydLeB6j9nTr9pGe7qfXhHmZE/eMllzT8d2NQYE71ayPM8HqdXRIdGBRyusYS0WP01rj0U x91MQfb5afm7GTNE4Ri2As+/0YJfjQM1P3wgrEG7+6Q5scpZp6XuoOIXZQeVLZm7W7NzyFEu++4 aSiEZyC1fQIxnT+Yv4m4PWeO+1WsVeRMGvPP/xlA== X-Gm-Gg: ASbGncsNhR+cE1rmXmoPJCAZkC/p9J6sdJVnKPbEJ7VrL73XbiRWAhmKu4y0C6wDLWK MlC45R4L6XQp2RWBwyLPMToiUCWZvgxfjPgDsVay6lvvzosNi10HDgfHc5AQhzFzdvuF1zRTeVf jz3XPO9pHPFeLJHSTfNXpxI5S1Rf7Lgyv5BMC+kXgr3cXKNHj4JUBqda0Y47oQaTUSXZIJyONHj dY+Wo1cEamU46KGxlMmowMSQeEDmPESJATw4zyAh7mCPCxd5JIH/ISgWbx/O4udaBP4ja17Hx5z cPLBFy+2y9Bf5RvojHRFrv+q3qPL13wIEr5p28X1/LSsokG01Kc8KXWDZKzjNrr2iZ3Sw0/W9YT qSgCgba5CkA== X-Received: by 2002:ac8:58cf:0:b0:467:4fc5:9d71 with SMTP id d75a77b69052e-46c7102c2dcmr217930071cf.28.1736580859679; Fri, 10 Jan 2025 23:34:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IECcwSSro5E+dDxTa2bExdzL+lqyClUp6Fy3vQkqNiP8tVUxY5lQp6vlhzJm6eStdr8PL6E9Q== X-Received: by 2002:ac8:58cf:0:b0:467:4fc5:9d71 with SMTP id d75a77b69052e-46c7102c2dcmr217929821cf.28.1736580859250; Fri, 10 Jan 2025 23:34:19 -0800 (PST) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dfad88e2eesm17562076d6.33.2025.01.10.23.34.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 23:34:17 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed 2/2] c++: modules and function attributes Date: Sat, 11 Jan 2025 02:33:45 -0500 Message-ID: <20250111073412.190565-2-jason@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250111073412.190565-1-jason@redhat.com> References: <20250111073412.190565-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2Pt357gbIlGPTBK4sqjIT_4mjjkSTaAa7BSxTYi8SYo_1736580861 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK, URI_HEX autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- 30_threads/stop_token/stop_source/109339.cc was failing because we weren't representing attribute access on the METHOD_TYPE for _Stop_state_ref. The modules code expected attributes to appear on tt_variant_type and not on tt_derived_type, but that's backwards since build_type_attribute_variant gives a type with attributes its own TYPE_MAIN_VARIANT. gcc/cp/ChangeLog: * module.cc (trees_out::type_node): Write attributes for tt_derived_type, not tt_variant_type. (trees_in::tree_node): Likewise for reading. gcc/testsuite/ChangeLog: * g++.dg/modules/attrib-2_a.C: New test. * g++.dg/modules/attrib-2_b.C: New test. --- gcc/cp/module.cc | 17 +++++++++++++---- gcc/testsuite/g++.dg/modules/attrib-2_a.C | 12 ++++++++++++ gcc/testsuite/g++.dg/modules/attrib-2_b.C | 9 +++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/attrib-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/attrib-2_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 321d4164a6a..c932c4d0a90 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -9189,7 +9189,10 @@ trees_out::type_node (tree type) tree_node (raises); } - tree_node (TYPE_ATTRIBUTES (type)); + /* build_type_attribute_variant creates a new TYPE_MAIN_VARIANT, so + variants should all have the same set of attributes. */ + gcc_checking_assert (TYPE_ATTRIBUTES (type) + == TYPE_ATTRIBUTES (TYPE_MAIN_VARIANT (type))); if (streaming_p ()) { @@ -9406,6 +9409,8 @@ trees_out::type_node (tree type) break; } + tree_node (TYPE_ATTRIBUTES (type)); + /* We may have met the type during emitting the above. */ if (ref_node (type) != WK_none) { @@ -10090,6 +10095,13 @@ trees_in::tree_node (bool is_use) break; } + /* In the exporting TU, a derived type with attributes was built by + build_type_attribute_variant as a distinct copy, with itself as + TYPE_MAIN_VARIANT. We repeat that on import to get the version + without attributes as TYPE_CANONICAL. */ + if (tree attribs = tree_node ()) + res = cp_build_type_attribute_variant (res, attribs); + int tag = i (); if (!tag) { @@ -10133,9 +10145,6 @@ trees_in::tree_node (bool is_use) TYPE_USER_ALIGN (res) = true; } - if (tree attribs = tree_node ()) - res = cp_build_type_attribute_variant (res, attribs); - int quals = i (); if (quals >= 0 && !get_overrun ()) res = cp_build_qualified_type (res, quals); diff --git a/gcc/testsuite/g++.dg/modules/attrib-2_a.C b/gcc/testsuite/g++.dg/modules/attrib-2_a.C new file mode 100644 index 00000000000..96f667ceec8 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/attrib-2_a.C @@ -0,0 +1,12 @@ +// { dg-additional-options "-fmodules -Wno-global-module" } +// { dg-module-cmi M } + +export module M; + +export +{ + struct A { int i; }; + + __attribute ((access (none, 1))) + void f(const A&); +} diff --git a/gcc/testsuite/g++.dg/modules/attrib-2_b.C b/gcc/testsuite/g++.dg/modules/attrib-2_b.C new file mode 100644 index 00000000000..c12ad117ce4 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/attrib-2_b.C @@ -0,0 +1,9 @@ +// { dg-additional-options "-fmodules -Wmaybe-uninitialized" } + +import M; + +int main() +{ + A a; + f(a); +}