This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[4.5 patch] allow d or D suffix for double for c/39027


Draft N1312 of draft Technical Report 24732 for decimal float support
in C specifies an optional suffix of 'd' or 'D' for type double.  This
patch recognizes that suffix and allows it to be used with i, I, j, or
J for an imaginary value in a constant of a complex double type.

Besides handling 'd' and 'D', this patch causes interpret_float_suffix
to report that the suffix was empty by returning CPP_N_DEFAULT, which
is then handled in interpret_float.  With this patch the default is
still type double, but that will change with an upcoming patch to add
more functionality from N1312 that allows the default to be either
double or _Decimal32.

Tested against the c-4.5 branch on powerpc64-linux, all languages but
Objective-C++ and Ada, for -m32 and -m64.  OK for mainline in stage 1?
OK now for the c-4.5 branch so I can more easily test and submit the
next patch in this series?

2009-02-24  Janis Johnson  <janis187@us.ibm.com>

libcpp/
	PR c/39027
	* include/cpplib.h (CPP_N_DEFAULT): Define.
	* expr.c (interpret_float_suffix): Recognize d or D for double.

gcc/
	PR c/39027
	* c-lex.c (interpret_float): Default (no suffix) is double. 

gcc/testsuite/
	PR c/39027
	* gcc.dg/cpp/pr39027.c: New test.
	* gcc.dg/fltconst-1.c: No error for d with i or j.

Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 144391)
+++ libcpp/include/cpplib.h	(working copy)
@@ -804,6 +804,7 @@
 #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.  */
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 144391)
+++ libcpp/expr.c	(working copy)
@@ -84,10 +84,10 @@
 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 @@
       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 @@
     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 @@
 	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
Index: gcc/c-lex.c
===================================================================
--- gcc/c-lex.c	(revision 144391)
+++ gcc/c-lex.c	(working copy)
@@ -612,6 +612,13 @@
   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);
Index: gcc/testsuite/gcc.dg/fltconst-1.c
===================================================================
--- gcc/testsuite/gcc.dg/fltconst-1.c	(revision 144391)
+++ gcc/testsuite/gcc.dg/fltconst-1.c	(working copy)
@@ -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" } */
Index: gcc/testsuite/gcc.dg/cpp/pr39027.c
===================================================================
--- gcc/testsuite/gcc.dg/cpp/pr39027.c	(revision 0)
+++ gcc/testsuite/gcc.dg/cpp/pr39027.c	(revision 0)
@@ -0,0 +1,34 @@
+/* { 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 imaginary constant suffixes are still recognized with
+   only i, I, j, or J.  */
+
+long double i = 0.5i;
+long double I = 0.5I;
+long double j = 0.5j;
+long double J = 0.5J;
+
+/* Check that imaginary constant suffixes are allowed with d or D.  */
+
+long double di = 0.5di;
+long double dI = 0.5dI;
+long double Di = 0.5Di;
+long double DI = 0.5DI;
+long double dj = 0.5dj;
+long double dJ = 0.5dJ;
+long double Dj = 0.5Dj;
+long double DJ = 0.5DJ;
+long double id = 0.5id;
+long double iD = 0.5iD;
+long double Id = 0.5Id;
+long double ID = 0.5ID;
+long double jd = 0.5jd;
+long double jD = 0.5jD;
+long double Jd = 0.5Jd;
+long double JD = 0.5JD;



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]