diff mbox series

[3/3] c++/modules: Propagate hidden flag on decls from partitions

Message ID 6618832b.630a0220.8e0f.544a@mx.google.com
State New
Headers show
Series c++/modules: Fix some small issues with exported using-decls | expand

Commit Message

Nathaniel Shead April 12, 2024, 12:41 a.m. UTC
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

While working on some other fixes I noticed that the partition handling
code used the wrong flag to propagate OVL_HIDDEN_P on exported bindings
from partitions. This patch fixes that, and renames the flag to be
clearer.

gcc/cp/ChangeLog:

	* name-lookup.cc (walk_module_binding): Use the
	partition-specific hidden flag instead of the top-level
	decl_hidden.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/using-16_a.C: New test.
	* g++.dg/modules/using-16_b.C: New test.
	* g++.dg/modules/using-16_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/name-lookup.cc                     | 10 +++++-----
 gcc/testsuite/g++.dg/modules/using-16_a.C | 11 +++++++++++
 gcc/testsuite/g++.dg/modules/using-16_b.C | 12 ++++++++++++
 gcc/testsuite/g++.dg/modules/using-16_c.C | 11 +++++++++++
 4 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/using-16_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/using-16_b.C
 create mode 100644 gcc/testsuite/g++.dg/modules/using-16_c.C

Comments

Jason Merrill April 12, 2024, 5:53 p.m. UTC | #1
On 4/11/24 20:41, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

OK.

> -- >8 --
> 
> While working on some other fixes I noticed that the partition handling
> code used the wrong flag to propagate OVL_HIDDEN_P on exported bindings
> from partitions. This patch fixes that, and renames the flag to be
> clearer.
> 
> gcc/cp/ChangeLog:
> 
> 	* name-lookup.cc (walk_module_binding): Use the
> 	partition-specific hidden flag instead of the top-level
> 	decl_hidden.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/modules/using-16_a.C: New test.
> 	* g++.dg/modules/using-16_b.C: New test.
> 	* g++.dg/modules/using-16_c.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>   gcc/cp/name-lookup.cc                     | 10 +++++-----
>   gcc/testsuite/g++.dg/modules/using-16_a.C | 11 +++++++++++
>   gcc/testsuite/g++.dg/modules/using-16_b.C | 12 ++++++++++++
>   gcc/testsuite/g++.dg/modules/using-16_c.C | 11 +++++++++++
>   4 files changed, 39 insertions(+), 5 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/modules/using-16_a.C
>   create mode 100644 gcc/testsuite/g++.dg/modules/using-16_b.C
>   create mode 100644 gcc/testsuite/g++.dg/modules/using-16_c.C
> 
> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
> index 7af7f00e34c..b7746938e1b 100644
> --- a/gcc/cp/name-lookup.cc
> +++ b/gcc/cp/name-lookup.cc
> @@ -4274,19 +4274,19 @@ walk_module_binding (tree binding, bitmap partitions,
>   
>   			count += callback (btype, flags, data);
>   		      }
> -		    bool hidden = STAT_DECL_HIDDEN_P (bind);
> +		    bool part_hidden = STAT_DECL_HIDDEN_P (bind);
>   		    for (ovl_iterator iter (MAYBE_STAT_DECL (STAT_DECL (bind)));
>   			 iter; ++iter)
>   		      {
>   			if (iter.hidden_p ())
> -			  hidden = true;
> +			  part_hidden = true;
>   			gcc_checking_assert
> -			  (!(hidden && DECL_IS_UNDECLARED_BUILTIN (*iter)));
> +			  (!(part_hidden && DECL_IS_UNDECLARED_BUILTIN (*iter)));
>   
>   			WMB_Flags flags = WMB_None;
>   			if (maybe_dups)
>   			  flags = WMB_Flags (flags | WMB_Dups);
> -			if (decl_hidden)
> +			if (part_hidden)
>   			  flags = WMB_Flags (flags | WMB_Hidden);
>   			if (iter.using_p ())
>   			  {
> @@ -4295,7 +4295,7 @@ walk_module_binding (tree binding, bitmap partitions,
>   			      flags = WMB_Flags (flags | WMB_Export);
>   			  }
>   			count += callback (*iter, flags, data);
> -			hidden = false;
> +			part_hidden = false;
>   		      }
>   		  }
>   	      }
> diff --git a/gcc/testsuite/g++.dg/modules/using-16_a.C b/gcc/testsuite/g++.dg/modules/using-16_a.C
> new file mode 100644
> index 00000000000..25d8bca5d1c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/using-16_a.C
> @@ -0,0 +1,11 @@
> +// { dg-additional-options "-fmodules-ts" }
> +// { dg-module-cmi M:S }
> +
> +export module M:S;
> +
> +namespace foo {
> +  // propagate hidden from partitions
> +  export struct S {
> +    friend void f(S);
> +  };
> +};
> diff --git a/gcc/testsuite/g++.dg/modules/using-16_b.C b/gcc/testsuite/g++.dg/modules/using-16_b.C
> new file mode 100644
> index 00000000000..3f704a913f4
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/using-16_b.C
> @@ -0,0 +1,12 @@
> +// { dg-additional-options "-fmodules-ts -Wno-global-module" }
> +// { dg-module-cmi M }
> +
> +module;
> +namespace bar {
> +  void f(int);
> +}
> +export module M;
> +export import :S;
> +namespace foo {
> +  export using bar::f;
> +}
> diff --git a/gcc/testsuite/g++.dg/modules/using-16_c.C b/gcc/testsuite/g++.dg/modules/using-16_c.C
> new file mode 100644
> index 00000000000..5e46cd16013
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/using-16_c.C
> @@ -0,0 +1,11 @@
> +// { dg-additional-options "-fmodules-ts" }
> +import M;
> +
> +int main() {
> +  // this should be hidden and fail
> +  foo::f(foo::S{});  // { dg-error "cannot convert" }
> +
> +  // but these should be legal
> +  foo::f(10);
> +  f(foo::S{});
> +}
diff mbox series

Patch

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7af7f00e34c..b7746938e1b 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -4274,19 +4274,19 @@  walk_module_binding (tree binding, bitmap partitions,
 
 			count += callback (btype, flags, data);
 		      }
-		    bool hidden = STAT_DECL_HIDDEN_P (bind);
+		    bool part_hidden = STAT_DECL_HIDDEN_P (bind);
 		    for (ovl_iterator iter (MAYBE_STAT_DECL (STAT_DECL (bind)));
 			 iter; ++iter)
 		      {
 			if (iter.hidden_p ())
-			  hidden = true;
+			  part_hidden = true;
 			gcc_checking_assert
-			  (!(hidden && DECL_IS_UNDECLARED_BUILTIN (*iter)));
+			  (!(part_hidden && DECL_IS_UNDECLARED_BUILTIN (*iter)));
 
 			WMB_Flags flags = WMB_None;
 			if (maybe_dups)
 			  flags = WMB_Flags (flags | WMB_Dups);
-			if (decl_hidden)
+			if (part_hidden)
 			  flags = WMB_Flags (flags | WMB_Hidden);
 			if (iter.using_p ())
 			  {
@@ -4295,7 +4295,7 @@  walk_module_binding (tree binding, bitmap partitions,
 			      flags = WMB_Flags (flags | WMB_Export);
 			  }
 			count += callback (*iter, flags, data);
-			hidden = false;
+			part_hidden = false;
 		      }
 		  }
 	      }
diff --git a/gcc/testsuite/g++.dg/modules/using-16_a.C b/gcc/testsuite/g++.dg/modules/using-16_a.C
new file mode 100644
index 00000000000..25d8bca5d1c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-16_a.C
@@ -0,0 +1,11 @@ 
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi M:S }
+
+export module M:S;
+
+namespace foo {
+  // propagate hidden from partitions
+  export struct S {
+    friend void f(S);
+  };
+};
diff --git a/gcc/testsuite/g++.dg/modules/using-16_b.C b/gcc/testsuite/g++.dg/modules/using-16_b.C
new file mode 100644
index 00000000000..3f704a913f4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-16_b.C
@@ -0,0 +1,12 @@ 
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+// { dg-module-cmi M }
+
+module;
+namespace bar {
+  void f(int);
+}
+export module M;
+export import :S;
+namespace foo {
+  export using bar::f;
+}
diff --git a/gcc/testsuite/g++.dg/modules/using-16_c.C b/gcc/testsuite/g++.dg/modules/using-16_c.C
new file mode 100644
index 00000000000..5e46cd16013
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/using-16_c.C
@@ -0,0 +1,11 @@ 
+// { dg-additional-options "-fmodules-ts" }
+import M;
+
+int main() {
+  // this should be hidden and fail
+  foo::f(foo::S{});  // { dg-error "cannot convert" }
+
+  // but these should be legal
+  foo::f(10);
+  f(foo::S{});
+}