This is a strange regression present on the mainline and 10 branch, whereby an 
enumeration type declared as atomic (or volatile) incorrectly triggers the ODR 
machinery for its values in LTO mode.

Tested on x86-64/Linux, applied on the mainline and 10 branch.


2021-03-10  Eric Botcazou  <ebotca...@adacore.com>

        * gcc-interface/decl.c (gnat_to_gnu_entity): Build a TYPE_STUB_DECL
        for the main variant of an enumeration type declared as volatile.


2021-03-10  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/specs/lto25.ads: New test.

-- 
Eric Botcazou
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 340782)
+++ gcc-interface/decl.c	(revision 340783)
@@ -4690,6 +4690,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gn
 	  const int quals
 	    = TYPE_QUAL_VOLATILE
 	      | (Is_Full_Access (gnat_entity) ? TYPE_QUAL_ATOMIC : 0);
+	  /* This is required by free_lang_data_in_type to disable the ODR.  */
+	  if (TREE_CODE (gnu_type) == ENUMERAL_TYPE)
+	    TYPE_STUB_DECL (gnu_type)
+	      = create_type_stub_decl (TYPE_NAME (gnu_type), gnu_type);
 	  gnu_type = change_qualified_type (gnu_type, quals);
 	}
 
-- { dg-do compile }
-- { dg-options "-flto" { target lto } }

package Lto25 is

  type Enum is (One, Two, Three) with Atomic;

  type Rec is record
    E : Enum := One;
  end record;

end Lto25;

Reply via email to