]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/36912 (ICE with "-frounding-math -g")
authorJason Merrill <jason@redhat.com>
Thu, 5 Nov 2009 16:32:36 +0000 (11:32 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 5 Nov 2009 16:32:36 +0000 (11:32 -0500)
PR c++/36912
* varasm.c (initializer_constant_valid_p): A PLUS_EXPR
or MINUS_EXPR of REAL_TYPE is not a valid constant initializer.
(output_constant): Avoid crash after error.

From-SVN: r153947

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/static-init2.C [new file with mode: 0644]
gcc/varasm.c

index 716621905841ee2f0862640dad88542cd72005bd..bcaa6cf82bf398a4d08ff082bc9bb34c8bee87ad 100644 (file)
@@ -1,3 +1,10 @@
+2009-11-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/36912
+       * varasm.c (initializer_constant_valid_p): A PLUS_EXPR
+       or MINUS_EXPR of REAL_TYPE is not a valid constant initializer.
+       (output_constant): Avoid crash after error.
+
 2009-11-05  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/41900
index 3169cdec76ebc4e2e8990fcf9f65bf0a2e433632..cd44c06eeaf8b44fc88577d511b60939e9b739b0 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/36912
+       * g++.dg/init/static-init2.C: New.
+
 2009-11-05  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/41900
diff --git a/gcc/testsuite/g++.dg/init/static-init2.C b/gcc/testsuite/g++.dg/init/static-init2.C
new file mode 100644 (file)
index 0000000..34bf2b2
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/36912
+// { dg-options -frounding-math }
+const double c = .1, d = c+1;
index 0113afdd786d35d1811be5df7a3dc02ae408e93e..4390af0b0d5a0a3a39b9f73201867ad139b823b3 100644 (file)
@@ -4232,6 +4232,10 @@ initializer_constant_valid_p (tree value, tree endtype)
 
     case POINTER_PLUS_EXPR:
     case PLUS_EXPR:
+      /* Any valid floating-point constants will have been folded by now;
+        with -frounding-math we hit this with addition of two constants.  */
+      if (TREE_CODE (endtype) == REAL_TYPE)
+       return NULL_TREE;
       if (! INTEGRAL_TYPE_P (endtype)
          || TYPE_PRECISION (endtype) >= POINTER_SIZE)
        {
@@ -4256,6 +4260,8 @@ initializer_constant_valid_p (tree value, tree endtype)
       break;
 
     case MINUS_EXPR:
+      if (TREE_CODE (endtype) == REAL_TYPE)
+       return NULL_TREE;
       if (! INTEGRAL_TYPE_P (endtype)
          || TYPE_PRECISION (endtype) >= POINTER_SIZE)
        {
@@ -4417,8 +4423,8 @@ output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
     case REAL_TYPE:
       if (TREE_CODE (exp) != REAL_CST)
        error ("initializer for floating value is not a floating constant");
-
-      assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
+      else
+       assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
       break;
 
     case COMPLEX_TYPE: