Commit ca305a84 by Ed Schonberg Committed by Pierre-Marie de Rodat

[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  <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.

From-SVN: r273687
parent 8c029ee8
2019-07-22 Ed Schonberg <schonberg@adacore.com> 2019-07-22 Ed Schonberg <schonberg@adacore.com>
* 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 <schonberg@adacore.com>
* sem_warn.adb (Check_References): Do not emit s warning on a * sem_warn.adb (Check_References): Do not emit s warning on a
referenced entity with no explicit assignment if the type of the referenced entity with no explicit assignment if the type of the
entity has Preelaborable_Initialixation, such as entity has Preelaborable_Initialixation, such as
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
package System.Val_Bool is package System.Val_Bool is
pragma Pure; pragma Preelaborate;
function Value_Boolean (Str : String) return Boolean; function Value_Boolean (Str : String) return Boolean;
-- Computes Boolean'Value (Str) -- Computes Boolean'Value (Str)
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
package System.Val_Char is package System.Val_Char is
pragma Pure; pragma Preelaborate;
function Value_Character (Str : String) return Character; function Value_Character (Str : String) return Character;
-- Computes Character'Value (Str) -- Computes Character'Value (Str)
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
-- Decimal_IO, and the Value attribute for such decimal types. -- Decimal_IO, and the Value attribute for such decimal types.
package System.Val_Dec is package System.Val_Dec is
pragma Pure; pragma Preelaborate;
function Scan_Decimal function Scan_Decimal
(Str : String; (Str : String;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
-- details of the format of constructed image tables. -- details of the format of constructed image tables.
package System.Val_Enum is package System.Val_Enum is
pragma Pure; pragma Preelaborate;
function Value_Enumeration_8 function Value_Enumeration_8
(Names : String; (Names : String;
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
-- in Text_IO.Integer_IO, and the Value attribute. -- in Text_IO.Integer_IO, and the Value attribute.
package System.Val_Int is package System.Val_Int is
pragma Pure; pragma Preelaborate;
function Scan_Integer function Scan_Integer
(Str : String; (Str : String;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
-- Decimal_IO, and the Value attribute for such decimal types. -- Decimal_IO, and the Value attribute for such decimal types.
package System.Val_LLD is package System.Val_LLD is
pragma Pure; pragma Preelaborate;
function Scan_Long_Long_Decimal function Scan_Long_Long_Decimal
(Str : String; (Str : String;
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
-- values for use in Text_IO.Integer_IO, and the Value attribute. -- values for use in Text_IO.Integer_IO, and the Value attribute.
package System.Val_LLI is package System.Val_LLI is
pragma Pure; pragma Preelaborate;
function Scan_Long_Long_Integer function Scan_Long_Long_Integer
(Str : String; (Str : String;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
with System.Unsigned_Types; with System.Unsigned_Types;
package System.Val_LLU is package System.Val_LLU is
pragma Pure; pragma Preelaborate;
function Scan_Raw_Long_Long_Unsigned function Scan_Raw_Long_Long_Unsigned
(Str : String; (Str : String;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
package System.Val_Real is package System.Val_Real is
pragma Pure; pragma Preelaborate;
function Scan_Real function Scan_Real
(Str : String; (Str : String;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
with System.Unsigned_Types; with System.Unsigned_Types;
package System.Val_Uns is package System.Val_Uns is
pragma Pure; pragma Preelaborate;
function Scan_Raw_Unsigned function Scan_Raw_Unsigned
(Str : String; (Str : String;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
with System.WCh_Con; with System.WCh_Con;
package System.Val_WChar is package System.Val_WChar is
pragma Pure; pragma Preelaborate;
function Value_Wide_Character function Value_Wide_Character
(Str : String; (Str : String;
......
2019-07-22 Ed Schonberg <schonberg@adacore.com> 2019-07-22 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/opt80.adb: New testcase.
2019-07-22 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/warn25.adb: New testcase. * gnat.dg/warn25.adb: New testcase.
2019-07-22 Yannick Moy <moy@adacore.com> 2019-07-22 Yannick Moy <moy@adacore.com>
......
-- { 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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment