diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 2de7accc..f8664566 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -13547,9 +13547,23 @@ canonicalize(type_base_sptr t)
 	// Add the canonical type to the set of canonical types
 	// belonging to its scope.
 	if (scope)
-	  scope->get_canonical_types().insert(canonical);
-	//else, if the type doesn't have a scope, it's doesn't meant
-	// to be emitted.  This can be the case for the result of the
+	  {
+	    if (is_type(scope))
+	      // The scope in question is itself a type (e.g, a class
+	      // or union).  Let's call that type ST.  We want to add
+	      // 'canonical' to the set of canonical types belonging
+	      // to ST.
+	      if (type_base_sptr c = is_type(scope)->get_canonical_type())
+		// We want to add 'canonical' to set of canonical
+		// types belonging to the canonical type of ST.  That
+		// way, just looking at the canonical type of ST is
+		// enough to get the types that belong to the scope of
+		// the class of equivalence of ST.
+		scope = is_scope_decl(is_decl(c)).get();
+	    scope->get_canonical_types().insert(canonical);
+	  }
+	// else, if the type doesn't have a scope, it's not meant to be
+	// emitted.  This can be the case for the result of the
 	// function strip_typedef, for instance.
       }
 
diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 03959bdc..3f3dfa9d 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -3843,7 +3843,11 @@ write_union_decl(const union_decl_sptr& d,
 	     decl->get_member_types().begin();
 	   ti != decl->get_member_types().end();
 	   ++ti)
-	write_member_type(*ti, ctxt, nb_ws);
+	if (!(*ti)->get_naked_canonical_type())
+	  write_member_type(*ti, ctxt, nb_ws);
+
+      write_canonical_types_of_scope(*decl, ctxt, nb_ws,
+				     /*is_member_type=*/true);
 
       for (union_decl::data_members::const_iterator data =
 	     decl->get_data_members().begin();
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index b3a4bbcd..154638fe 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -602,6 +602,7 @@ test-types-stability/pr19142-topo.o \
 test-types-stability/pr19204-libtcmalloc.so.4.2.6-xlc \
 test-types-stability/PR27165-libzmq.so.5.2.3 \
 test-types-stability/PR27165-libzmq.so.5.2.3.debug \
+test-types-stability/pr27980-libc.so \
 \
 test-diff-filter/test0-v0.cc		\
 test-diff-filter/test0-v1.cc		\
diff --git a/tests/data/test-read-dwarf/test16-pr18904.so.abi b/tests/data/test-read-dwarf/test16-pr18904.so.abi
index 8ee54646..9740e83a 100644
--- a/tests/data/test-read-dwarf/test16-pr18904.so.abi
+++ b/tests/data/test-read-dwarf/test16-pr18904.so.abi
@@ -2461,16 +2461,6 @@
           </data-member>
         </class-decl>
       </member-type>
-      <member-type access='public'>
-        <class-decl name='__anonymous_struct__1' size-in-bits='32' is-struct='yes' is-anonymous='yes' visibility='default' filepath='../../../gcc/liboffloadmic/runtime/offload_common.h' line='162' column='1' id='type-id-200'>
-          <data-member access='public' layout-offset-in-bits='0'>
-            <var-decl name='fortran_traceback' type-id='type-id-46' visibility='default' filepath='../../../gcc/liboffloadmic/runtime/offload_common.h' line='163' column='1'/>
-          </data-member>
-          <data-member access='public' layout-offset-in-bits='1'>
-            <var-decl name='omp_async' type-id='type-id-46' visibility='default' filepath='../../../gcc/liboffloadmic/runtime/offload_common.h' line='164' column='1'/>
-          </data-member>
-        </class-decl>
-      </member-type>
       <data-member access='public'>
         <var-decl name='flags' type-id='type-id-46' visibility='default' filepath='../../../gcc/liboffloadmic/runtime/offload_common.h' line='161' column='1'/>
       </data-member>
diff --git a/tests/data/test-types-stability/pr27980-libc.so b/tests/data/test-types-stability/pr27980-libc.so
new file mode 100644
index 0000000000000000000000000000000000000000..2e29e987986245c7d7eeca1ee2a3ca077467a991
GIT binary patch
diff --git a/tests/test-types-stability.cc b/tests/test-types-stability.cc
index 1d173ade..21c5ccde 100644
--- a/tests/test-types-stability.cc
+++ b/tests/test-types-stability.cc
@@ -49,6 +49,7 @@ const char* elf_paths[] =
   "data/test-types-stability/pr19142-topo.o",
   "data/test-types-stability/pr19204-libtcmalloc.so.4.2.6-xlc",
   "data/test-types-stability/PR27165-libzmq.so.5.2.3",
+  "data/test-types-stability/pr27980-libc.so",
   // The below should always be the last element of array.
   0
 };
