public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Crash on applying 'Pos to expression of a type derived from a formal type
@ 2022-11-14 13:52 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-11-14 13:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: Gary Dismukes

From: Gary Dismukes <dismukes@adacore.com>

The compiler crashes when trying to do a static check for a range violation
in a type conversion of a Pos attribute applied to a prefix of a type derived
from a generic formal discrete type. This optimization was suppressed in the
case of formal types, because the upper bound may not be known, but it also
needs to be suppressed for types derived from formal types.

gcc/ada/

	* checks.adb
	(Apply_Type_Conversion_Checks): Apply Root_Type to the type of the
	prefix of a Pos attribute when checking whether the type is a
	formal discrete type.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/checks.adb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 96876672871..2a45f4d49b0 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -3789,13 +3789,14 @@ package body Checks is
                --  Universal_Integer. So in numeric conversions it is usually
                --  within range of the target integer type. Use the static
                --  bounds of the base types to check. Disable this optimization
-               --  in case of a generic formal discrete type, because we don't
-               --  necessarily know the upper bound yet.
+               --  in case of a descendant of a generic formal discrete type,
+               --  because we don't necessarily know the upper bound yet.
 
                if Nkind (Expr) = N_Attribute_Reference
                  and then Attribute_Name (Expr) = Name_Pos
                  and then Is_Enumeration_Type (Etype (Prefix (Expr)))
-                 and then not Is_Generic_Type (Etype (Prefix (Expr)))
+                 and then
+                   not Is_Generic_Type (Root_Type (Etype (Prefix (Expr))))
                  and then Is_Integer_Type (Target_Type)
                then
                   declare
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-14 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14 13:52 [COMMITTED] ada: Crash on applying 'Pos to expression of a type derived from a formal type Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).