Index: gimple-expr.c =================================================================== --- gimple-expr.c (revision 229616) +++ gimple-expr.c (working copy) @@ -84,7 +84,15 @@ useless_type_conversion_p (tree outer_ty if (inner_type == outer_type) return true; - /* Changes in machine mode are never useless conversions unless. */ + /* For aggregate types, if we know the canonical types, compare them. This + is important for the remapping of variably-modified types. */ + if (AGGREGATE_TYPE_P (inner_type) + && TYPE_CANONICAL (inner_type) + && TYPE_CANONICAL (inner_type) == TYPE_CANONICAL (outer_type)) + return true; + + /* Changes in machine mode are never useless conversions because the RTL + middle-end expects explicit conversions between modes. */ if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type)) return false; Index: testsuite/gnat.dg/discr45.adb =================================================================== --- testsuite/gnat.dg/discr45.adb (revision 229630) +++ testsuite/gnat.dg/discr45.adb (working copy) @@ -1,4 +1,4 @@ --- { dg-do run } +-- { dg-do compile } -- { dg-options "-O2 -gnatws" } procedure Discr45 is