]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/47473 (Incorrect computation with complex numbers when using -std...
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 Apr 2011 18:24:43 +0000 (20:24 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 Apr 2011 18:24:43 +0000 (20:24 +0200)
Backported from mainline
2011-01-26  Jakub Jelinek  <jakub@redhat.com>

PR c/47473
* c-lex.c (interpret_float): If CPP_N_IMAGINARY, ensure
EXCESS_PRECISION_EXPR is created with COMPLEX_TYPE instead of
REAL_TYPE.

* gcc.dg/torture/pr47473.c: New test.

From-SVN: r172113

gcc/ChangeLog
gcc/c-lex.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr47473.c [new file with mode: 0644]

index 0d6cf493cd8d4616e162592b2b37524880b3a431..d619992113a2dd3e716810a931a23cba67d625d3 100644 (file)
@@ -1,3 +1,13 @@
+2011-04-07  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2011-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/47473
+       * c-lex.c (interpret_float): If CPP_N_IMAGINARY, ensure
+       EXCESS_PRECISION_EXPR is created with COMPLEX_TYPE instead of
+       REAL_TYPE.
+
 2011-04-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/47391
index 5535eaeb42edb0a94da705a8d78e2b5b83170713..e5aca0da83255585cbcc54b674a1a813929a0526 100644 (file)
@@ -739,8 +739,15 @@ interpret_float (const cpp_token *token, unsigned int flags)
   /* Create a node with determined type and value.  */
   value = build_real (const_type, real);
   if (flags & CPP_N_IMAGINARY)
-    value = build_complex (NULL_TREE, convert (const_type, integer_zero_node),
-                          value);
+    {
+      value = build_complex (NULL_TREE, convert (const_type,
+                                                integer_zero_node), value);
+      if (type != const_type)
+       {
+         const_type = TREE_TYPE (value);
+         type = build_complex_type (type);
+       }
+    }
 
   if (type != const_type)
     value = build1 (EXCESS_PRECISION_EXPR, type, value);
index b8f8cb752852904b4a56efbd17b8351875a4a350..48f03430af48ecb456384e319c10b8c20700e4c8 100644 (file)
@@ -1,8 +1,13 @@
 2011-04-07  Jakub Jelinek  <jakub@redhat.com>
 
-       Backport from mainline
+       Backported from mainline
+       2011-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/47473
+       * gcc.dg/torture/pr47473.c: New test.
+
        2011-01-21  Jakub Jelinek  <jakub@redhat.com>
+
        PR tree-optimization/47391
        * gcc.dg/pr47391.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr47473.c b/gcc/testsuite/gcc.dg/torture/pr47473.c
new file mode 100644 (file)
index 0000000..92f2b87
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR c/47473 */
+/* { dg-do run } */
+/* { dg-options "-std=c99" } */
+
+int
+main (void)
+{
+  long double _Complex w = 0.2L - 0.3iL;
+  w = w * (0.3L - (0.0F + 1.0iF) * 0.9L);
+  if (__builtin_fabsl (__real__ w + 0.21L) > 0.001L
+      || __builtin_fabsl (__imag__ w + 0.27L) > 0.001L)
+    __builtin_abort ();
+  return 0;
+}