* [Ada] Optimization loses exception in improper use of 'Value
@ 2019-07-22 14:03 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-22 14:03 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 918 bytes --]
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.
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-07-22 Ed Schonberg <schonberg@adacore.com>
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 3434 bytes --]
--- gcc/ada/libgnat/s-valboo.ads
+++ 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)
--- gcc/ada/libgnat/s-valcha.ads
+++ 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)
--- gcc/ada/libgnat/s-valdec.ads
+++ 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;
--- gcc/ada/libgnat/s-valenu.ads
+++ 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;
--- gcc/ada/libgnat/s-valint.ads
+++ 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;
--- gcc/ada/libgnat/s-vallld.ads
+++ 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;
--- gcc/ada/libgnat/s-vallli.ads
+++ 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;
--- gcc/ada/libgnat/s-valllu.ads
+++ 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;
--- gcc/ada/libgnat/s-valrea.ads
+++ gcc/ada/libgnat/s-valrea.ads
@@ -30,7 +30,7 @@
------------------------------------------------------------------------------
package System.Val_Real is
- pragma Pure;
+ pragma Preelaborate;
function Scan_Real
(Str : String;
--- gcc/ada/libgnat/s-valuns.ads
+++ 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;
--- gcc/ada/libgnat/s-valwch.ads
+++ 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;
--- /dev/null
new file mode 100644
+++ 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-07-22 14:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 14:03 [Ada] Optimization loses exception in improper use of 'Value Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).