Skip to content
Snippets Groups Projects
Commit 664bd76a authored by Jason Merrill's avatar Jason Merrill
Browse files

c++: modules and function attributes

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.
parent fdabd93c
No related branches found
No related tags found
No related merge requests found
...@@ -9189,7 +9189,10 @@ trees_out::type_node (tree type) ...@@ -9189,7 +9189,10 @@ trees_out::type_node (tree type)
tree_node (raises); 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 ()) if (streaming_p ())
{ {
...@@ -9406,6 +9409,8 @@ trees_out::type_node (tree type) ...@@ -9406,6 +9409,8 @@ trees_out::type_node (tree type)
break; break;
} }
   
tree_node (TYPE_ATTRIBUTES (type));
/* We may have met the type during emitting the above. */ /* We may have met the type during emitting the above. */
if (ref_node (type) != WK_none) if (ref_node (type) != WK_none)
{ {
...@@ -10090,6 +10095,13 @@ trees_in::tree_node (bool is_use) ...@@ -10090,6 +10095,13 @@ trees_in::tree_node (bool is_use)
break; 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 (); int tag = i ();
if (!tag) if (!tag)
{ {
...@@ -10133,9 +10145,6 @@ trees_in::tree_node (bool is_use) ...@@ -10133,9 +10145,6 @@ trees_in::tree_node (bool is_use)
TYPE_USER_ALIGN (res) = true; TYPE_USER_ALIGN (res) = true;
} }
   
if (tree attribs = tree_node ())
res = cp_build_type_attribute_variant (res, attribs);
int quals = i (); int quals = i ();
if (quals >= 0 && !get_overrun ()) if (quals >= 0 && !get_overrun ())
res = cp_build_qualified_type (res, quals); res = cp_build_qualified_type (res, quals);
......
// { 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&);
}
// { dg-additional-options "-fmodules -Wmaybe-uninitialized" }
import M;
int main()
{
A a;
f(a);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment