Patchwork [Ada] Validity checks on boolean expressions

login
register
mail settings
Submitter Arnaud Charlet
Date Sept. 10, 2010, 9:45 a.m.
Message ID <20100910094542.GA30175@adacore.com>
Download mbox | patch
Permalink /patch/64363/
State New
Headers show

Comments

Arnaud Charlet - Sept. 10, 2010, 9:45 a.m.
The value of a boolean expression or short-circuit operation is valid if the
elementary operands of the expression are valid. This patch removes validity
checks that were superfluous, and led to a quadratic expansion in the generated
code for short-circuit expressions with multiple alternatives.
No simple example available.

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

2010-09-10  Ed Schonberg  <schonberg@adacore.com>

	* checks.adb (Ensure_Valid): If the expression is a boolean expression
	or short-circuit operation, do no emit a validity check: only the
	elementary operands of the expression need checking.

Patch

Index: checks.adb
===================================================================
--- checks.adb	(revision 164098)
+++ checks.adb	(working copy)
@@ -4108,6 +4108,17 @@  package body Checks is
          end if;
       end if;
 
+      --  If this is a boolean expression, only its elementary consituents
+      --  need checking: if they are valid, a boolean or short-circuit
+      --  operation with them will be valid as well.
+
+      if Base_Type (Typ) = Standard_Boolean
+        and then
+          (Nkind (Expr) in N_Op or else Nkind (Expr) in N_Short_Circuit)
+      then
+         return;
+      end if;
+
       --  If we fall through, a validity check is required
 
       Insert_Valid_Check (Expr);