diff options
author | Joseph Myers <jsm@polyomino.org.uk> | 2004-10-08 20:25:42 +0000 |
---|---|---|
committer | Joseph Myers <jsm@polyomino.org.uk> | 2004-10-08 20:25:42 +0000 |
commit | f807dd579e59b2ced7e14377775e390f52982101 (patch) | |
tree | 31256910f3b10e27ff12fd3f87bb0f45c2c64979 | |
parent | 04a9f838c7dcdc345e2c740e6061d4524ef15ffb (diff) |
* c-lex.c (interpret_float): Give a pedwarn rather than a warning
for an out-of-range floating point constant.
* builtins.c (fold_builtin_inf): Give a pedwarn rather than a
warning if the target format does not support infinities.
testsuite:
* gcc.dg/float-range-1.c, gcc.dg/float-range-2.c: New tests.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@88793 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/builtins.c | 9 | ||||
-rw-r--r-- | gcc/c-lex.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/float-range-1.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/float-range-2.c | 14 |
6 files changed, 52 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d6f83b4bb7..876aad467c9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2004-10-08 Joseph S. Myers <jsm@polyomino.org.uk> + + * c-lex.c (interpret_float): Give a pedwarn rather than a warning + for an out-of-range floating point constant. + * builtins.c (fold_builtin_inf): Give a pedwarn rather than a + warning if the target format does not support infinities. + 2004-10-08 Kazu Hirata <kazu@cs.umass.edu> * emit-rtl.c (last_label_num, base_label_num): Remove. diff --git a/gcc/builtins.c b/gcc/builtins.c index 76be4a7f619..255a47ba19c 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5825,8 +5825,15 @@ fold_builtin_inf (tree type, int warn) { REAL_VALUE_TYPE real; + /* __builtin_inff is intended to be usable to define INFINITY on all + targets. If an infinity is not available, INFINITY expands "to a + positive constant of type float that overflows at translation + time", footnote "In this case, using INFINITY will violate the + constraint in 6.4.4 and thus require a diagnostic." (C99 7.12#4). + Thus we pedwarn to ensure this constraint violation is + diagnosed. */ if (!MODE_HAS_INFINITIES (TYPE_MODE (type)) && warn) - warning ("target format does not support infinity"); + pedwarn ("target format does not support infinity"); real_inf (&real); return build_real (type, real); diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 98f60f639d4..77c2e4c8ace 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -653,13 +653,13 @@ interpret_float (const cpp_token *token, unsigned int flags) real_from_string (&real, copy); real_convert (&real, TYPE_MODE (type), &real); - /* A diagnostic is required for "soft" overflow by some ISO C - testsuites. This is not pedwarn, because some people don't want - an error for this. - ??? That's a dubious reason... is this a mandatory diagnostic or - isn't it? -- zw, 2001-08-21. */ + /* Both C and C++ require a diagnostic for a floating constant + outside the range of representable values of its type. Since we + have __builtin_inf* to produce an infinity, it might now be + appropriate for this to be a mandatory pedwarn rather than + conditioned on -pedantic. */ if (REAL_VALUE_ISINF (real) && pedantic) - warning ("floating constant exceeds range of %<%s%>", type_name); + pedwarn ("floating constant exceeds range of %<%s%>", type_name); /* Create a node with determined type and value. */ value = build_real (type, real); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 82f1f09d14c..6e1ee3dcf7a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2004-10-08 Joseph S. Myers <jsm@polyomino.org.uk> + * gcc.dg/float-range-1.c, gcc.dg/float-range-2.c: New tests. + +2004-10-08 Joseph S. Myers <jsm@polyomino.org.uk> + * gcc.dg/assign-warn-3.c: New test. 2004-10-08 Andrew Pinski <pinskia@physics.uc.edu> diff --git a/gcc/testsuite/gcc.dg/float-range-1.c b/gcc/testsuite/gcc.dg/float-range-1.c new file mode 100644 index 00000000000..e14e345aba3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/float-range-1.c @@ -0,0 +1,13 @@ +/* Floating constants outside the range of their type should receive a + pedwarn, not a warning. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile } */ +/* { dg-options "-ansi -pedantic-errors" } */ + +void +f (void) +{ + float a = 1e+100000000f; /* { dg-error "error: floating constant exceeds range of 'float'" } */ + double b = 1e+100000000; /* { dg-error "error: floating constant exceeds range of 'double'" } */ + long double c = 1e+100000000l; /* { dg-error "error: floating constant exceeds range of 'long double'" } */ +} diff --git a/gcc/testsuite/gcc.dg/float-range-2.c b/gcc/testsuite/gcc.dg/float-range-2.c new file mode 100644 index 00000000000..45447bc7912 --- /dev/null +++ b/gcc/testsuite/gcc.dg/float-range-2.c @@ -0,0 +1,14 @@ +/* Floating constants outside the range of their type should receive a + pedwarn, not a warning. This includes INFINITY if the target does + not support infinities. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk> */ +/* { dg-do compile { target vax-*-* pdp11-*-* } } */ +/* { dg-options "-ansi -pedantic-errors" } */ + +void +f (void) +{ + float a = __builtin_inff (); /* { dg-error "error: target format does not support infinity" } */ + double b = __builtin_inf (); /* { dg-error "error: target format does not support infinity" } */ + long double c = __builtin_infl (); /* { dg-error "error: target format does not support infinity" } */ +} |