[Ada] Fix wrong type being used for range check generation

Message ID 20200609081007.GA73914@adacore.com
State New
Headers show
Series
  • [Ada] Fix wrong type being used for range check generation
Related show

Commit Message

Pierre-Marie de Rodat June 9, 2020, 8:10 a.m.
Before this commit, GNAT would use the type of the expression rather
than that of the subtype mark in order to decide whether it should
generate range checks or not. This means that in some cases, GNAT would
decide that no range checks were needed, which was wrong. This issue
went mostly unnoticed because the expansion routines use their own logic
in order to determine whether range checks should be generated or not.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-09  Ghjuvan Lacambre  <lacambre@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve_Qualified_Expression): Use Subtype_Mark
	type.

Patch

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -10004,8 +10004,10 @@  package body Sem_Res is
       --  check may convert an illegal static expression and result in warning
       --  rather than giving an error (e.g Integer'(Integer'Last + 1)).
 
-      if Nkind (N) = N_Qualified_Expression and then Is_Scalar_Type (Typ) then
-         Apply_Scalar_Range_Check (Expr, Typ);
+      if Nkind (N) = N_Qualified_Expression
+        and then Is_Scalar_Type (Target_Typ)
+      then
+         Apply_Scalar_Range_Check (Expr, Target_Typ);
       end if;
 
       --  AI12-0100: Once the qualified expression is resolved, check whether