re PR c/47473 (Incorrect computation with complex numbers when using -std=c99)
authorJakub Jelinek <jakub@redhat.com>
Wed, 26 Jan 2011 20:06:57 +0000 (21:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 26 Jan 2011 20:06:57 +0000 (21:06 +0100)
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: r169299

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

index ebcb5c2617e301c257dbbc2134fd65c517d65395..d18ba202bced9c4b211fa9a00a09d082b9aa8883 100644 (file)
@@ -1,3 +1,10 @@
+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-01-26  Arnaud Charlet  <charlet@adacore.com>
 
        * c-ada-spec.c (dump_generic_ada_node): Avoid dereferencing null type.
index 778e4246749b523f0d223eef6c606df4e369b1e7..1ea57f1cdda1577eaa43ba4d8e393f2ebab8180b 100644 (file)
@@ -1,7 +1,7 @@
 /* Mainly the interface between cpplib and the C front ends.
    Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
-   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
-   Free Software Foundation, Inc.
+   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
+   2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -752,8 +752,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 ed90ed7e8e969632bd4d8e2f7ebf4ba4c729507a..274471253a3bcb5cc5902bb7f8715369647e9438 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/47473
+       * gcc.dg/torture/pr47473.c: New test.
+
 2011-01-26  Jan Hubicka  <jh@suse.cz>
 
        PR target/47237
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;
+}