--- /dev/null
+-- { dg-do compile }\r
+-- { dg-options "-O" }\r
+\r
+package body Opt29 is\r
+\r
+ procedure Proc (T : Rec) is\r
+ begin\r
+ if Derived2 (T.F2.all).Id = T.F1.Id then\r
+ raise Program_Error;\r
+ end if;\r
+ end;\r
+\r
+end Opt29;\r
--- /dev/null
+package Opt29 is\r
+\r
+ type Word is mod 2**16;\r
+\r
+ type PID is record\r
+ W1, W2: Word;\r
+ end record;\r
+\r
+ type Root1 is tagged record\r
+ Id: PID;\r
+ end record;\r
+ type Root1_Ptr is access all Root1'Class;\r
+\r
+ type Root2 is tagged null record;\r
+ type Root2_Ptr is access all Root2'class;\r
+\r
+ type Derived2 is new Root2 with record\r
+ Id: PID;\r
+ end record;\r
+\r
+ type Rec is record\r
+ F1: Root1_Ptr;\r
+ F2: Root2_Ptr;\r
+ end record;\r
+\r
+ procedure Proc (T : Rec);\r
+\r
+end Opt29;\r