aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-11-13 09:44:20 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2024-11-13 09:44:20 +0100
commit856809e582bacbceb70cdae56feb86da367f379e (patch)
treecc311f08db7c3dfa52160e5047db450299f7d1ad /gcc
parenteb45d151fa1780d01533d9fc9545fec50bfd7152 (diff)
downloadgcc-856809e582bacbceb70cdae56feb86da367f379e.zip
gcc-856809e582bacbceb70cdae56feb86da367f379e.tar.gz
gcc-856809e582bacbceb70cdae56feb86da367f379e.tar.bz2
c: Handle C23 floating constant {d,D}{32,64,128} suffixes like {df,dd,dl}
C23 roughly says that {d,D}{32,64,128} floating point constant suffixes are alternate spellings of {df,dd,dl} suffixes in annex H. So, the following patch allows that alternate spelling. Or is it intentional it isn't enabled and we need to do everything in there first before trying to define __STDC_IEC_60559_DFP__? Like add support for _Decimal32x and _Decimal64x types (including the d32x and d64x suffixes) etc. 2024-11-13 Jakub Jelinek <jakub@redhat.com> libcpp/ * expr.cc (interpret_float_suffix): Handle d32 and D32 suffixes for C like df, d64 and D64 like dd and d128 and D128 like dl. gcc/c-family/ * c-lex.cc (interpret_float): Subtract 3 or 4 from copylen rather than 2 if last character of CPP_N_DFLOAT is a digit. gcc/testsuite/ * gcc.dg/dfp/c11-constants-3.c: New test. * gcc.dg/dfp/c11-constants-4.c: New test. * gcc.dg/dfp/c23-constants-3.c: New test. * gcc.dg/dfp/c23-constants-4.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-lex.cc7
-rw-r--r--gcc/testsuite/gcc.dg/dfp/c11-constants-3.c13
-rw-r--r--gcc/testsuite/gcc.dg/dfp/c11-constants-4.c13
-rw-r--r--gcc/testsuite/gcc.dg/dfp/c23-constants-3.c39
-rw-r--r--gcc/testsuite/gcc.dg/dfp/c23-constants-4.c13
5 files changed, 84 insertions, 1 deletions
diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index f7168ce..8e18293 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -1347,7 +1347,12 @@ interpret_float (const cpp_token *token, unsigned int flags,
if (flags & CPP_N_USERDEF)
copylen -= strlen (suffix);
else if (flags & CPP_N_DFLOAT)
- copylen -= 2;
+ {
+ if (ISDIGIT (token->val.str.text[copylen - 1]))
+ copylen -= (flags & CPP_N_LARGE) ? 4 : 3;
+ else
+ copylen -= 2;
+ }
else
{
if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
diff --git a/gcc/testsuite/gcc.dg/dfp/c11-constants-3.c b/gcc/testsuite/gcc.dg/dfp/c11-constants-3.c
new file mode 100644
index 0000000..63b9a71
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c11-constants-3.c
@@ -0,0 +1,13 @@
+/* Test that DFP constants are diagnosed in C11 mode: -pedantic. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic" } */
+
+int a = (int) 1.1D32; /* { dg-warning "C23 feature" } */
+int b = (int) 2.d32; /* { dg-warning "C23 feature" } */
+int c = (int) .33D64; /* { dg-warning "C23 feature" } */
+int d = (int) 2e1d64; /* { dg-warning "C23 feature" } */
+int e = (int) .3e2D128; /* { dg-warning "C23 feature" } */
+int f = (int) 4.5e3d128; /* { dg-warning "C23 feature" } */
+int g = (int) 5.e0D32; /* { dg-warning "C23 feature" } */
+int h = (int) 1e+2d32; /* { dg-warning "C23 feature" } */
+int i = (int) 1000e-3D128; /* { dg-warning "C23 feature" } */
diff --git a/gcc/testsuite/gcc.dg/dfp/c11-constants-4.c b/gcc/testsuite/gcc.dg/dfp/c11-constants-4.c
new file mode 100644
index 0000000..09e2ae1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c11-constants-4.c
@@ -0,0 +1,13 @@
+/* Test that DFP constants are diagnosed in C11 mode: -pedantic-errors. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+int a = (int) 1.1D32; /* { dg-error "C23 feature" } */
+int b = (int) 2.d32; /* { dg-error "C23 feature" } */
+int c = (int) .33D64; /* { dg-error "C23 feature" } */
+int d = (int) 2e1d64; /* { dg-error "C23 feature" } */
+int e = (int) .3e2D128; /* { dg-error "C23 feature" } */
+int f = (int) 4.5e3d128; /* { dg-error "C23 feature" } */
+int g = (int) 5.e0D32; /* { dg-error "C23 feature" } */
+int h = (int) 1e+2d32; /* { dg-error "C23 feature" } */
+int i = (int) 1000e-3D128; /* { dg-error "C23 feature" } */
diff --git a/gcc/testsuite/gcc.dg/dfp/c23-constants-3.c b/gcc/testsuite/gcc.dg/dfp/c23-constants-3.c
new file mode 100644
index 0000000..7b09715
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c23-constants-3.c
@@ -0,0 +1,39 @@
+/* Test that DFP constants are accepted in C23 mode. */
+/* { dg-do run } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+
+int a = (int) 1.1D32;
+int b = (int) 2.d32;
+int c = (int) .33D64;
+int d = (int) 2e1d64;
+int e = (int) .3e2D128;
+int f = (int) 4.5e3d128;
+int g = (int) 5.e0D32;
+int h = (int) 1e+2d32;
+int i = (int) 1000e-3D128;
+
+#define expr_has_type(e, t) _Generic (e, default : 0, t : 1)
+static_assert (expr_has_type (1.1D32, _Decimal32));
+static_assert (expr_has_type (2.d32, _Decimal32));
+static_assert (expr_has_type (.33D64, _Decimal64));
+static_assert (expr_has_type (2e1d64, _Decimal64));
+static_assert (expr_has_type (.3e2D128, _Decimal128));
+static_assert (expr_has_type (4.5e3d128, _Decimal128));
+static_assert (expr_has_type (5.e0D32, _Decimal32));
+static_assert (expr_has_type (1e+2d32, _Decimal32));
+static_assert (expr_has_type (1000e-3D128, _Decimal128));
+
+int
+main ()
+{
+ if (1.1D32 != 1.1df
+ || 2.d32 != 2.df
+ || .33D64 != .33dd
+ || 2e1d64 != 2e1dd
+ || .3e2D128 != .3e2dl
+ || 4.5e3d128 != 4.5e3dl
+ || 5.e0D32 != 5.e0df
+ || 1e+2d32 != 1e+2df
+ || 1000e-3D128 != 1000e-3dl)
+ __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/dfp/c23-constants-4.c b/gcc/testsuite/gcc.dg/dfp/c23-constants-4.c
new file mode 100644
index 0000000..e9ae6a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c23-constants-4.c
@@ -0,0 +1,13 @@
+/* Test that DFP constants are accepted in C23 mode: compat warnings. */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -Wc11-c23-compat" } */
+
+int a = (int) 1.1D32; /* { dg-warning "C23 feature" } */
+int b = (int) 2.d32; /* { dg-warning "C23 feature" } */
+int c = (int) .33D64; /* { dg-warning "C23 feature" } */
+int d = (int) 2e1d64; /* { dg-warning "C23 feature" } */
+int e = (int) .3e2D128; /* { dg-warning "C23 feature" } */
+int f = (int) 4.5e3d128; /* { dg-warning "C23 feature" } */
+int g = (int) 5.e0D32; /* { dg-warning "C23 feature" } */
+int h = (int) 1e+2d32; /* { dg-warning "C23 feature" } */
+int i = (int) 1000e-3D128; /* { dg-warning "C23 feature" } */