From: Ed Schonberg Date: Mon, 22 Jul 2019 13:57:55 +0000 (+0000) Subject: [Ada] Optimization loses exception in improper use of 'Value X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca305a848c4f1cc493e61083a14b77df226ac8af;p=gcc.git [Ada] Optimization loses exception in improper use of 'Value This patch prevents an improper removal of an evaluation of attribute 'Value on an illegal input that will raise Constraint_Error, when a subsequent use of this evaluation might be optimized away by the back-end. 2019-07-22 Ed Schonberg gcc/ada/ * libgnat/s-valboo.ads, libgnat/s-valcha.ads, libgnat/s-valdec.ads, libgnat/s-valenu.ads, libgnat/s-valint.ads, libgnat/s-vallld.ads, libgnat/s-vallli.ads, libgnat/s-valllu.ads, libgnat/s-valrea.ads, libgnat/s-valuns.ads, libgnat/s-valwch.ads: Change categorization of packages that implement attribute 'Value from Pure to Preelaborate, to prevent undesirable optimizations when the evaluation of the attribute raises Constraint_Error, but subsequent use of the result of this evsaluation is removed by a subsequent optimization. gcc/testsuite/ * gnat.dg/opt80.adb: New testcase. From-SVN: r273687 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 12ea5adb30e..30b798c52df 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,16 @@ +2019-07-22 Ed Schonberg + + * libgnat/s-valboo.ads, libgnat/s-valcha.ads, + libgnat/s-valdec.ads, libgnat/s-valenu.ads, + libgnat/s-valint.ads, libgnat/s-vallld.ads, + libgnat/s-vallli.ads, libgnat/s-valllu.ads, + libgnat/s-valrea.ads, libgnat/s-valuns.ads, + libgnat/s-valwch.ads: Change categorization of packages that + implement attribute 'Value from Pure to Preelaborate, to prevent + undesirable optimizations when the evaluation of the attribute + raises Constraint_Error, but subsequent use of the result of + this evsaluation is removed by a subsequent optimization. + 2019-07-22 Ed Schonberg * sem_warn.adb (Check_References): Do not emit s warning on a diff --git a/gcc/ada/libgnat/s-valboo.ads b/gcc/ada/libgnat/s-valboo.ads index bed1ae3fa88..f900621ea36 100644 --- a/gcc/ada/libgnat/s-valboo.ads +++ b/gcc/ada/libgnat/s-valboo.ads @@ -30,7 +30,7 @@ ------------------------------------------------------------------------------ package System.Val_Bool is - pragma Pure; + pragma Preelaborate; function Value_Boolean (Str : String) return Boolean; -- Computes Boolean'Value (Str) diff --git a/gcc/ada/libgnat/s-valcha.ads b/gcc/ada/libgnat/s-valcha.ads index 0d3edfcfdce..b9d537331a3 100644 --- a/gcc/ada/libgnat/s-valcha.ads +++ b/gcc/ada/libgnat/s-valcha.ads @@ -30,7 +30,7 @@ ------------------------------------------------------------------------------ package System.Val_Char is - pragma Pure; + pragma Preelaborate; function Value_Character (Str : String) return Character; -- Computes Character'Value (Str) diff --git a/gcc/ada/libgnat/s-valdec.ads b/gcc/ada/libgnat/s-valdec.ads index 9d4733346ef..ec104903e9e 100644 --- a/gcc/ada/libgnat/s-valdec.ads +++ b/gcc/ada/libgnat/s-valdec.ads @@ -34,7 +34,7 @@ -- Decimal_IO, and the Value attribute for such decimal types. package System.Val_Dec is - pragma Pure; + pragma Preelaborate; function Scan_Decimal (Str : String; diff --git a/gcc/ada/libgnat/s-valenu.ads b/gcc/ada/libgnat/s-valenu.ads index 343acf387b0..e2a3a15174d 100644 --- a/gcc/ada/libgnat/s-valenu.ads +++ b/gcc/ada/libgnat/s-valenu.ads @@ -34,7 +34,7 @@ -- details of the format of constructed image tables. package System.Val_Enum is - pragma Pure; + pragma Preelaborate; function Value_Enumeration_8 (Names : String; diff --git a/gcc/ada/libgnat/s-valint.ads b/gcc/ada/libgnat/s-valint.ads index b4be1e4dc17..d9f15ed8466 100644 --- a/gcc/ada/libgnat/s-valint.ads +++ b/gcc/ada/libgnat/s-valint.ads @@ -33,7 +33,7 @@ -- in Text_IO.Integer_IO, and the Value attribute. package System.Val_Int is - pragma Pure; + pragma Preelaborate; function Scan_Integer (Str : String; diff --git a/gcc/ada/libgnat/s-vallld.ads b/gcc/ada/libgnat/s-vallld.ads index 1ff561e99b8..17db0789453 100644 --- a/gcc/ada/libgnat/s-vallld.ads +++ b/gcc/ada/libgnat/s-vallld.ads @@ -34,7 +34,7 @@ -- Decimal_IO, and the Value attribute for such decimal types. package System.Val_LLD is - pragma Pure; + pragma Preelaborate; function Scan_Long_Long_Decimal (Str : String; diff --git a/gcc/ada/libgnat/s-vallli.ads b/gcc/ada/libgnat/s-vallli.ads index 2f510ca680d..ee75bdc69f1 100644 --- a/gcc/ada/libgnat/s-vallli.ads +++ b/gcc/ada/libgnat/s-vallli.ads @@ -33,7 +33,7 @@ -- values for use in Text_IO.Integer_IO, and the Value attribute. package System.Val_LLI is - pragma Pure; + pragma Preelaborate; function Scan_Long_Long_Integer (Str : String; diff --git a/gcc/ada/libgnat/s-valllu.ads b/gcc/ada/libgnat/s-valllu.ads index c51849205bc..ddb84144033 100644 --- a/gcc/ada/libgnat/s-valllu.ads +++ b/gcc/ada/libgnat/s-valllu.ads @@ -35,7 +35,7 @@ with System.Unsigned_Types; package System.Val_LLU is - pragma Pure; + pragma Preelaborate; function Scan_Raw_Long_Long_Unsigned (Str : String; diff --git a/gcc/ada/libgnat/s-valrea.ads b/gcc/ada/libgnat/s-valrea.ads index 49607ed15b5..b59f345cf4e 100644 --- a/gcc/ada/libgnat/s-valrea.ads +++ b/gcc/ada/libgnat/s-valrea.ads @@ -30,7 +30,7 @@ ------------------------------------------------------------------------------ package System.Val_Real is - pragma Pure; + pragma Preelaborate; function Scan_Real (Str : String; diff --git a/gcc/ada/libgnat/s-valuns.ads b/gcc/ada/libgnat/s-valuns.ads index 741ae6fdbfa..7d261b1d5eb 100644 --- a/gcc/ada/libgnat/s-valuns.ads +++ b/gcc/ada/libgnat/s-valuns.ads @@ -35,7 +35,7 @@ with System.Unsigned_Types; package System.Val_Uns is - pragma Pure; + pragma Preelaborate; function Scan_Raw_Unsigned (Str : String; diff --git a/gcc/ada/libgnat/s-valwch.ads b/gcc/ada/libgnat/s-valwch.ads index 5a72295c16b..5179517e7b4 100644 --- a/gcc/ada/libgnat/s-valwch.ads +++ b/gcc/ada/libgnat/s-valwch.ads @@ -34,7 +34,7 @@ with System.WCh_Con; package System.Val_WChar is - pragma Pure; + pragma Preelaborate; function Value_Wide_Character (Str : String; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9679c756c8..acc60635027 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-22 Ed Schonberg + + * gnat.dg/opt80.adb: New testcase. + 2019-07-22 Ed Schonberg * gnat.dg/warn25.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/opt80.adb b/gcc/testsuite/gnat.dg/opt80.adb new file mode 100644 index 00000000000..39c6cef0cd7 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt80.adb @@ -0,0 +1,15 @@ +-- { dg-do run } +-- { dg-options "-O2" } + +with Ada.Text_IO; use Ada.Text_IO; + +procedure Opt80 is + Item : Integer; +begin + Item := Integer'Value ("zzz"); + Put_Line (Boolean'Image (Item'Valid)); + raise Program_Error; +exception + when Constraint_Error => + null; +end;