When subtype predicate checks are added for object declarations, it could lead to a compiler crash or to an incorrect check. When the subtype for the object being declared is built later by Analyze_Object_Declaration, the predicate check can't be applied on the object instead of a copy as the call will be incorrect after the subtype has been built. When subtypes for LHS and RHS do not statically match, only checking the predicate on the object after it has been initialized may miss a failing predicate on the RHS. In both cases, skip the optimization and check the predicate on a copy. Rename Should_Build_Subtype into Build_Default_Subtype_OK and move it out of sem_ch3 to make it available to other part of the compiler (in particular to checks.adb). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * checks.adb (Apply_Predicate_Check): Refine condition for applying optimization. * sem_ch3.adb (Analyze_Component_Declaration): Adjust calls to Should_Build_Subtype. (Analyze_Object_Declaration): Likewise. (Should_Build_Subtype): Rename/move to ... * sem_util.ads (Build_Default_Subtype_OK): ... this. * sem_util.adb (Build_Default_Subtype_OK): Moved from sem_ch3.adb.