re PR c++/9881 (What is an address constant expression?)
authorNathan Sidwell <nathan@codesourcery.com>
Mon, 21 Apr 2003 11:16:57 +0000 (11:16 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Mon, 21 Apr 2003 11:16:57 +0000 (11:16 +0000)
cp:
PR c++/9881
* typeck.c (build_unary_op): Fold all COMPONENT_REF addr
expressions. Reverts my 2002-08-08 patch.

* typeck.c (comp_ptr_ttypes_real): Swap final && operands for
cheaper early exit.
testsuite:
PR c++/9881
* g++.dg/init/addr-const1.C: New test.
* g++.dg/other/packed1.C: XFAIL on aligned architectures.

From-SVN: r65882

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/addr-const1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/packed1.C

index 8ea634fb439837aeac7460124b71c169f775242c..cbe913e8d7269c721dd49174c507adccc2d9ba8a 100644 (file)
@@ -1,3 +1,12 @@
+2003-04-21  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/9881
+       * typeck.c (build_unary_op): Fold all COMPONENT_REF addr
+       expressions. Reverts my 2002-08-08 patch.
+       
+       * typeck.c (comp_ptr_ttypes_real): Swap final && operands for
+       cheaper early exit.
+
 2003-04-20  Nathan Sidwell  <nathan@codesourcery.com>
 
        * cp/decl2.c (start_static_storage_duration_function): Take count
index 8e2682f7f93fe91f09152c38819f55f4d0c60906..e60eb105ada27f26c3297feb262b452e13425111 100644 (file)
@@ -4504,19 +4504,19 @@ build_unary_op (code, xarg, noconvert)
            && TREE_CODE (TREE_OPERAND (arg, 1)) == BASELINK)
          arg = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
 
-       if (TREE_CODE (arg) == COMPONENT_REF
-           && DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
+       if (TREE_CODE (arg) != COMPONENT_REF)
+         addr = build_address (arg);
+       else if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
          {
            error ("attempt to take address of bit-field structure member `%D'",
                   TREE_OPERAND (arg, 1));
            return error_mark_node;
          }
-       else if (TREE_CODE (arg) == COMPONENT_REF
-                && TREE_CODE (TREE_OPERAND (arg, 0)) == INDIRECT_REF
-                && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg, 0), 0))
-                    == INTEGER_CST))
+       else
          {
-           /* offsetof idiom, fold it.  */
+           /* Unfortunately we cannot just build an address
+              expression here, because we would not handle
+              address-constant-expressions or offsetof correctly.  */
            tree field = TREE_OPERAND (arg, 1);
            tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
            tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)),
@@ -4529,8 +4529,6 @@ build_unary_op (code, xarg, noconvert)
            addr = fold (build (PLUS_EXPR, argtype, rval,
                                cp_convert (argtype, byte_position (field))));
          }
-       else
-         addr = build_address (arg);
 
        if (TREE_CODE (argtype) == POINTER_TYPE
            && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
@@ -6578,15 +6576,14 @@ comp_ptr_ttypes_real (to, from, constp)
        }
 
       if (TREE_CODE (to) != POINTER_TYPE)
-       return 
-         same_type_ignoring_top_level_qualifiers_p (to, from)
-         && (constp >= 0 || to_more_cv_qualified);
+       return ((constp >= 0 || to_more_cv_qualified)
+               && same_type_ignoring_top_level_qualifiers_p (to, from));
     }
 }
 
-/* When comparing, say, char ** to char const **, this function takes the
-   'char *' and 'char const *'.  Do not pass non-pointer types to this
-   function.  */
+/* When comparing, say, char ** to char const **, this function takes
+   the 'char *' and 'char const *'.  Do not pass non-pointer/reference
+   types to this function.  */
 
 int
 comp_ptr_ttypes (to, from)
index 408d817eea36cb971f65f8f90e078c194d2573f6..fe9eb5cf4804800ff746dc032c91071b531cd61a 100644 (file)
@@ -1,4 +1,10 @@
-2003-04-19  Nathan Sidwell  <nathan@codesourcery.com>
+2003-04-21  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/9881
+       * g++.dg/init/addr-const1.C: New test.
+       * g++.dg/other/packed1.C: XFAIL on aligned architectures.
+
+2003-04-20  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/10405
        * g++.dg/lookup/struct-hack1.C: New test.
diff --git a/gcc/testsuite/g++.dg/init/addr-const1.C b/gcc/testsuite/g++.dg/init/addr-const1.C
new file mode 100644 (file)
index 0000000..3b4637a
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-do run }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 19 Apr 2003 <nathan@codesourcery.com>
+
+// PR 9881. address-constant-expression not static initialized
+
+struct bar {
+  double p;
+}; // bar
+    
+bar v;
+static bool error = false;
+
+struct foo {
+  static double *a;
+  static double *b;
+  static double storage;
+};
+
+struct baz {
+  baz () {
+    if (foo::a != &v.p)
+      error = true;
+    if (foo::b != &foo::storage)
+      error = true;
+  }
+};
+
+baz f; // Get constructor to run before any other non-static initializers
+
+double *foo::a = &(((bar *)(&v))->p);
+double *foo::b = &(((bar *)(&foo::storage))->p);
+double foo::storage = 0.0;
+
+int main() {
+  return error;
+}
index 4fb7194dd9f9a836a4984aeb499afe4ab9add9bd..d19bb00b1cf4394cfda81271ebb2f060f94a69da 100644 (file)
@@ -1,4 +1,7 @@
-// { dg-do run }
+// { dg-do run { xfail arm-*-* } { xfail mips-*-* } { xfail powerpc-*-* } { xfail sh-*-* } { xfail sparc-*-* }
+
+// NMS:2003-04-21 this fails on strict aligned architectures again,
+// the patch was reverted because it broke something more important.
 
 // Copyright (C) 2002 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 8 Aug 2002 <nathan@codesourcery.com>