[gcc r15-11452] Ada: Fix crash on Unchecked_Union component with -gnateV
Eric Botcazou via Gcc-cvs <[email protected]> Sun, 2 Aug 2026 12:14:12 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:6fe0e2898efe3391183a4afb246df6330c6a5ec4 commit r15-11452-g6fe0e2898efe3391183a4afb246df6330c6a5ec4 Author: Eric Botcazou <[email protected]> Date: Sat Aug 1 18:44:12 2026 +0200 Ada: Fix crash on Unchecked_Union component with -gnateV This is the same bug as PR ada/123857, but at a nested level, and the fix is the same 1-liner but at a different place. gcc/ada/ PR ada/126553 * exp_attr.adb (Build_Record_VS_Func.Validate_Field): Do nothing if the field is of an Unchecked_Union type. gcc/testsuite/ * gnat.dg/unchecked_union5.adb: New test. Diff: --- gcc/ada/exp_attr.adb | 7 +++++-- gcc/testsuite/gnat.dg/unchecked_union5.adb | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 66ef1919576c..313ff1e679aa 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -656,9 +656,12 @@ package body Exp_Attr is if Field_Nam in Name_uObject | Name_uParent | Name_uTag then null; - -- Do not process fields without any scalar components + -- Do not process fields without any scalar components, or whose type + -- is an unchecked union since we cannot know where they are. - elsif not Scalar_Part_Present (Field_Typ) then + elsif not Scalar_Part_Present (Field_Typ) + or else Is_Unchecked_Union (Field_Typ) + then null; -- Otherwise the field needs to be validated. Use Make_Identifier diff --git a/gcc/testsuite/gnat.dg/unchecked_union5.adb b/gcc/testsuite/gnat.dg/unchecked_union5.adb new file mode 100644 index 000000000000..746ed19e03c6 --- /dev/null +++ b/gcc/testsuite/gnat.dg/unchecked_union5.adb @@ -0,0 +1,23 @@ +-- { dg-do compile } +-- { dg-options "-gnateV" } + +procedure Unchecked_Union5 is + + type R (Bytes_Mode : Boolean := False) is record + case Bytes_Mode is + when True => + A : Boolean; + when False => + B : Boolean; + end case; + end record with Unchecked_Union; + + type T is record + Data : R; + end record; + + function F (Message : T) return Integer is (0); + +begin + null; +end;