diff mbox series

[Ada] Add adequate guard before calling First_Rep_Item

Message ID 20210922151557.GA1908016@adacore.com
State New
Headers show
Series [Ada] Add adequate guard before calling First_Rep_Item | expand

Commit Message

Pierre-Marie de Rodat Sept. 22, 2021, 3:15 p.m. UTC
New contracts on Ada.Strings.Bounded revealed an unprotected call to
First_Rep_Item on a possibly empty node.

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

gcc/ada/

	* sem_ch13.adb (Build_Predicate_Functions): Add guard.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -10104,7 +10104,10 @@  package body Sem_Ch13 is
          --  If the type is private, check whether full view has inherited
          --  predicates.
 
-         if Is_Private_Type (Typ) and then No (Ritem) then
+         if Is_Private_Type (Typ)
+           and then No (Ritem)
+           and then Present (Full_View (Typ))
+         then
             Ritem := First_Rep_Item (Full_View (Typ));
          end if;