From f8ed6d41439b594e4be05b47b2999a45b0c4fecb Mon Sep 17 00:00:00 2001 From: janis Date: Wed, 1 Apr 2009 17:31:26 +0000 Subject: [PATCH] gcc/ PR c/29027 * c-lex.c (interpret_float): Default (no suffix) is double. libcpp/ PR c/29027 * include/cpplib.h (CPP_N_DEFAULT): Define. * expr.c (interpret_float_suffix): Recognize d or D for double, return new value for default. (cpp_classify_number): Issue pedwarn for use of d or D in suffix. gcc/testsuite/ PR c/29027 * gcc.dg/fltconst-1.c: Don't error for use of d or D in suffix. * gcc.dg/fltconst-2.c: New test. * gcc.dg/fltconst-double-pedantic-1.c: New test. * gcc.dg/fltconst-double-pedantic-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@145422 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 +++ gcc/c-lex.c | 7 ++++ gcc/testsuite/ChangeLog | 6 ++++ gcc/testsuite/gcc.dg/fltconst-1.c | 8 ++--- gcc/testsuite/gcc.dg/fltconst-2.c | 40 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/fltconst-double-pedantic-1.c | 13 ++++++++ gcc/testsuite/gcc.dg/fltconst-double-pedantic-2.c | 13 ++++++++ libcpp/ChangeLog | 6 ++++ libcpp/expr.c | 21 +++++++++--- libcpp/include/cpplib.h | 1 + 10 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fltconst-2.c create mode 100644 gcc/testsuite/gcc.dg/fltconst-double-pedantic-1.c create mode 100644 gcc/testsuite/gcc.dg/fltconst-double-pedantic-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7c8880f46ef..9e18af57f86 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2009-04-01 Janis Johnson + + PR c/29027 + * c-lex.c (interpret_float): Default (no suffix) is double. + 2009-04-1 Xinliang David Li * config/i386/i386.c (legitimate_constant_p): Recognize diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 72a959052d2..9fe29df15fb 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -612,6 +612,13 @@ interpret_float (const cpp_token *token, unsigned int flags) char *copy; size_t copylen; + /* Default (no suffix) is double. */ + if (flags & CPP_N_DEFAULT) + { + flags ^= CPP_N_DEFAULT; + flags |= CPP_N_MEDIUM; + } + /* Decode _Fract and _Accum. */ if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM) return interpret_fixed (token, flags); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74daab6b07d..708697bf1c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -4,6 +4,12 @@ 2009-04-01 Janis Johnson + PR c/39027 + * gcc.dg/fltconst-1.c: Don't error for use of d or D in suffix. + * gcc.dg/fltconst-2.c: New test. + * gcc.dg/fltconst-double-pedantic-1.c: New test. + * gcc.dg/fltconst-double-pedantic-2.c: New test. + PR c/33466 * gcc.dg/cpp/pr33466.c: New test. * gcc.dg/dfp/pr33466.c: New test. diff --git a/gcc/testsuite/gcc.dg/fltconst-1.c b/gcc/testsuite/gcc.dg/fltconst-1.c index 1b75210e981..e8ecf6750a3 100644 --- a/gcc/testsuite/gcc.dg/fltconst-1.c +++ b/gcc/testsuite/gcc.dg/fltconst-1.c @@ -3,10 +3,10 @@ double a = 1.ld; /* { dg-error "12:invalid suffix" } */ double b = 1.fd; /* { dg-error "12:invalid suffix" } */ -double c = 1.di; /* { dg-error "12:invalid suffix" } */ -double d = 1.dj; /* { dg-error "12:invalid suffix" } */ -double e = 1.id; /* { dg-error "12:invalid suffix" } */ -double f = 1.jd; /* { dg-error "12:invalid suffix" } */ +double c = 1.di; +double d = 1.dj; +double e = 1.id; +double f = 1.jd; double g = 1.ddd; /* { dg-error "12:invalid suffix" } */ double h = 1.ldd; /* { dg-error "12:invalid suffix" } */ double i = 1.dld; /* { dg-error "12:invalid suffix" } */ diff --git a/gcc/testsuite/gcc.dg/fltconst-2.c b/gcc/testsuite/gcc.dg/fltconst-2.c new file mode 100644 index 00000000000..d4d06ac8823 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fltconst-2.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +/* Check that d or D is recognized as a float constant suffix. */ + +double d = 0.5d; +double D = 0.5D; + +/* Check that d or D is recognized in a hexadecimal floating constant. */ + +double hd1 = 0x1.8p1d; +double hd2 = 0x1.p+1D; +double hd3 = 0x0.8p-1d; + +/* Check that imaginary constant suffixes are still recognized with + only i, I, j, or J. */ + +double i = 0.5i; +double I = 0.5I; +double j = 0.5j; +double J = 0.5J; + +/* Check that imaginary constant suffixes are allowed with d or D. */ + +double di = 0.5di; +double dI = 0.5dI; +double Di = 0.5Di; +double DI = 0.5DI; +double dj = 0.5dj; +double dJ = 0.5dJ; +double Dj = 0.5Dj; +double DJ = 0.5DJ; +double id = 0.5id; +double iD = 0.5iD; +double Id = 0.5Id; +double ID = 0.5ID; +double jd = 0.5jd; +double jD = 0.5jD; +double Jd = 0.5Jd; +double JD = 0.5JD; diff --git a/gcc/testsuite/gcc.dg/fltconst-double-pedantic-1.c b/gcc/testsuite/gcc.dg/fltconst-double-pedantic-1.c new file mode 100644 index 00000000000..07827296db8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fltconst-double-pedantic-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c99 -pedantic" } */ + +double a = 1.d; /* { dg-warning "double constant" } */ +double b = 1.D; /* { dg-warning "double constant" } */ +double c = 1.1e+2d; /* { dg-warning "double constant" } */ + +double d = 1.di; /* { dg-warning "imaginary constants" } */ +double e = 1.dj; /* { dg-warning "imaginary constants" } */ +double f = 1.id; /* { dg-warning "imaginary constants" } */ +double g = 1.jd; /* { dg-warning "imaginary constants" } */ + +double h = 0x1.5p1d; /* { dg-warning "double constant" } */ diff --git a/gcc/testsuite/gcc.dg/fltconst-double-pedantic-2.c b/gcc/testsuite/gcc.dg/fltconst-double-pedantic-2.c new file mode 100644 index 00000000000..316571f762f --- /dev/null +++ b/gcc/testsuite/gcc.dg/fltconst-double-pedantic-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c99 -pedantic-errors" } */ + +double a = 1.d; /* { dg-error "double constant" } */ +double b = 1.D; /* { dg-error "double constant" } */ +double c = 1.1e+2d; /* { dg-error "double constant" } */ + +double d = 1.di; /* { dg-error "imaginary constants" } */ +double e = 1.dj; /* { dg-error "imaginary constants" } */ +double f = 1.id; /* { dg-error "imaginary constants" } */ +double g = 1.jd; /* { dg-error "imaginary constants" } */ + +double h = 0x1.5p1d; /* { dg-error "double constant" } */ diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index c7c723995c8..1ca914db97e 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,5 +1,11 @@ 2009-04-01 Janis Johnson + PR c/39027 + * include/cpplib.h (CPP_N_DEFAULT): Define. + * expr.c (interpret_float_suffix): Recognize d or D for double, + return new value for default. + (cpp_classify_number): Issue pedwarn for use of d or D in suffix. + PR c/33466 * expr.c (interpret_float_suffix): Reject invalid suffix that uses letters from decimal float and fixed-point suffixes. diff --git a/libcpp/expr.c b/libcpp/expr.c index dbbb05a60bb..688439799f9 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -84,10 +84,10 @@ static unsigned int interpret_float_suffix (const uchar *s, size_t len) { size_t flags; - size_t f, l, w, q, i; + size_t f, d, l, w, q, i; flags = 0; - f = l = w = q = i = 0; + f = d = l = w = q = i = 0; /* Process decimal float suffixes, which are two letters starting with d or D. Order and case are significant. */ @@ -103,7 +103,9 @@ interpret_float_suffix (const uchar *s, size_t len) case 'l': return (!uppercase ? (CPP_N_DFLOAT | CPP_N_LARGE) : 0); break; case 'L': return (uppercase ? (CPP_N_DFLOAT | CPP_N_LARGE) : 0); break; default: - return 0; + /* Additional two-character suffixes beginning with D are not + for decimal float constants. */ + break; } } @@ -162,6 +164,7 @@ interpret_float_suffix (const uchar *s, size_t len) switch (s[len]) { case 'f': case 'F': f++; break; + case 'd': case 'D': d++; break; case 'l': case 'L': l++; break; case 'w': case 'W': w++; break; case 'q': case 'Q': q++; break; @@ -171,14 +174,15 @@ interpret_float_suffix (const uchar *s, size_t len) return 0; } - if (f + l + w + q > 1 || i > 1) + if (f + d + l + w + q > 1 || i > 1) return 0; return ((i ? CPP_N_IMAGINARY : 0) | (f ? CPP_N_SMALL : + d ? CPP_N_MEDIUM : l ? CPP_N_LARGE : w ? CPP_N_MD_W : - q ? CPP_N_MD_Q : CPP_N_MEDIUM)); + q ? CPP_N_MD_Q : CPP_N_DEFAULT)); } /* Subroutine of cpp_classify_number. S points to an integer suffix @@ -365,6 +369,13 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token) "traditional C rejects the \"%.*s\" suffix", (int) (limit - str), str); + /* A suffix for double is a GCC extension via decimal float support. + If the suffix also specifies an imaginary value we'll catch that + later. */ + if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile)) + cpp_error (pfile, CPP_DL_PEDWARN, + "suffix for double constant is a GCC extension"); + /* Radix must be 10 for decimal floats. */ if ((result & CPP_N_DFLOAT) && radix != 10) { diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index adc6cf13ede..469aaedff60 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -780,6 +780,7 @@ struct cpp_num #define CPP_N_UNSIGNED 0x1000 /* Properties. */ #define CPP_N_IMAGINARY 0x2000 #define CPP_N_DFLOAT 0x4000 +#define CPP_N_DEFAULT 0x8000 #define CPP_N_FRACT 0x100000 /* Fract types. */ #define CPP_N_ACCUM 0x200000 /* Accum types. */ -- 2.11.4.GIT