This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Improve use of Is_Known_Valid in constant folding


Comparisons that involve variables with non-static values can be constant-folded
if the bounds of the types of the variables are static, and the variables are
known to be valid, that is to say initialized to proper values of their
subtypes. If the variables are not known to hold valid values, the constant-
folding is unsafe and may lead to bounded errors (wrong results or  constraint
errors).  This patch tightens the checks on validity and inhibits spurious
compile-time transformations.

Execution of program My_Test must output:

TRUE
FALSE
FALSE

--
with Ada.Text_IO;

procedure My_Test is

   type My_Enum is (A, B ,C);
   for My_Enum use (A => 1, B => 2, C => 3);

   subtype My_Sub_Enum is My_Enum range A .. A;

   Foo : My_Sub_Enum;

   Foo_Overlay : My_Enum;
   for Foo_Overlay'Address use Foo'Address;

begin
   Foo_Overlay := A;
   Ada.Text_IO.Put_Line (Boolean'Image (Foo'Valid));

   Foo_Overlay := B;
   Ada.Text_IO.Put_Line (Boolean'Image (Foo'Valid));

   Foo_Overlay := C;
   Ada.Text_IO.Put_Line (Boolean'Image (Foo'Valid));
end My_Test;

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

2009-07-27  Ed Schonberg  <schonberg@adacore.com>

	* sem_eval.adb (Compile_Time_Compare): More precise handling of
	Known_Valid flag, to prevent spurious range deductions when scalar
	variables may be uninitialized. New predicate Is_Known_Valid_Operand.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]