* Ada: fix validity check on some floating point operation
@ 2004-10-27 12:12 Arnaud Charlet
2004-10-27 12:37 ` Arnaud Charlet
0 siblings, 1 reply; 2+ messages in thread
From: Arnaud Charlet @ 2004-10-27 12:12 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Ada: fix validity check on some floating point operation
2004-10-27 12:12 Ada: fix validity check on some floating point operation Arnaud Charlet
@ 2004-10-27 12:37 ` Arnaud Charlet
0 siblings, 0 replies; 2+ messages in thread
From: Arnaud Charlet @ 2004-10-27 12:37 UTC (permalink / raw)
To: Arnaud Charlet; +Cc: gcc-patches, Ed Schonberg
Committed on mainline.
> Tested on x86-linux
> Validity checks were properly enabled on the operands of these operations,
> [...]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-10-27 12:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-27 12:12 Ada: fix validity check on some floating point operation Arnaud Charlet
2004-10-27 12:37 ` Arnaud Charlet
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).