public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Arnaud Charlet <charlet@ACT-Europe.FR>
To: gcc-patches@gcc.gnu.org
Cc: Ed Schonberg <schonberg@gnat.com>
Subject: Ada: fix validity check on some floating point operation
Date: Wed, 27 Oct 2004 12:12:00 -0000	[thread overview]
Message-ID: <20041027102052.GJ91230@province.act-europe.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 853 bytes --]

Tested on x86-linux

Validity checks were properly enabled on the operands of these operations,
but not on the result, which allowed the generation and propagation of abnormal
values (Infinities and NaN's).
Test p_test_float verifies that invalid values are properly
detected:

with TEXT_IO;
use TEXT_IO;

procedure P_TEST_FLOAT is
  V_1, V_2, V_3 : Long_Float; 
begin
  V_1 := 0.004389773266958945;
  V_2 := 0.0;

  V_3 := V_1 / V_2;
  put_line ("Failed: division by zero");
exception
  when constraint_error => put_line ("division by zero detected");
end P_TEST_FLOAT;

$ gnatmake -q -gnatVirofc p_test_float

2004-10-26  Ed Schonberg  <schonberg@gnat.com>

	* checks.adb (Expr_Known_Valid): If floating-point validity checks are
	enabled, check the result of unary and binary operations when the
	expression is the right-hand side of an assignment.


[-- Attachment #2: difs.8 --]
[-- Type: text/plain, Size: 1493 bytes --]

Index: checks.adb
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/checks.adb,v
retrieving revision 1.29
diff -u -p -r1.29 checks.adb
--- checks.adb	4 Oct 2004 14:58:46 -0000	1.29
+++ checks.adb	27 Oct 2004 09:32:36 -0000
@@ -3792,13 +3792,26 @@ package body Checks is
 
       --  The result of any function call or operator is always considered
       --  valid, since we assume the necessary checks are done by the call.
+      --  For operators on floating-point operations, we must also check
+      --  when the operation is the right-hand side of an assignment, or
+      --  is an actual in a call.
 
-      elsif Nkind (Expr) in N_Binary_Op
-              or else
-            Nkind (Expr) in N_Unary_Op
-              or else
-            Nkind (Expr) = N_Function_Call
+      elsif
+        Nkind (Expr) in N_Binary_Op or else Nkind (Expr) in N_Unary_Op
       then
+         if Is_Floating_Point_Type (Typ)
+            and then Validity_Check_Floating_Point
+            and then
+              (Nkind (Parent (Expr)) = N_Assignment_Statement
+                or else Nkind (Parent (Expr)) = N_Function_Call
+                or else Nkind (Parent (Expr)) = N_Parameter_Association)
+         then
+            return False;
+         else
+            return True;
+         end if;
+
+      elsif Nkind (Expr) = N_Function_Call then
          return True;
 
       --  For all other cases, we do not know the expression is valid

             reply	other threads:[~2004-10-27 10:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-27 12:12 Arnaud Charlet [this message]
2004-10-27 12:37 ` Arnaud Charlet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041027102052.GJ91230@province.act-europe.fr \
    --to=charlet@act-europe.fr \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=schonberg@gnat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).