From: Eric Botcazou Date: Wed, 10 Mar 2021 11:04:25 +0000 (+0100) Subject: Fix ICE on atomic enumeration type with LTO X-Git-Tag: releases/gcc-10.3.0~236 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a068491e12ec39860ac55f4e86734306de47805;p=thirdparty%2Fgcc.git Fix ICE on atomic enumeration type with LTO This is a strange regression whereby an enumeration type declared as atomic (or volatile) incorrectly triggers the ODR machinery for its values in LTO mode. gcc/ada/ * gcc-interface/decl.c (gnat_to_gnu_entity): Build a TYPE_STUB_DECL for the main variant of an enumeration type declared as volatile. gcc/testsuite/ * gnat.dg/specs/lto25.ads: New test. --- diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index fb0042369c9d..300f7c04b0cd 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -4682,6 +4682,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) const int quals = TYPE_QUAL_VOLATILE | (Is_Atomic_Or_VFA (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); } diff --git a/gcc/testsuite/gnat.dg/specs/lto25.ads b/gcc/testsuite/gnat.dg/specs/lto25.ads new file mode 100644 index 000000000000..89876b64a00b --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/lto25.ads @@ -0,0 +1,12 @@ +-- { 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;