typeck.c (build_component_addr): Remove.
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 8 Aug 2002 15:59:33 +0000 (15:59 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 8 Aug 2002 15:59:33 +0000 (15:59 +0000)
cp:
* typeck.c (build_component_addr): Remove.
(build_unary_op): Just check it's not a bitfield, and then build
an ADDR_EXPR.
testsuite:
* g++.dg/other/packed1.C: New test.

From-SVN: r56132

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

index 3d852a13c9ff0df5eddb7bce139d69b899cf7f92..361da7557dc4c15177e3db4a9ee476eac169dd76 100644 (file)
@@ -1,3 +1,9 @@
+2002-08-08  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * typeck.c (build_component_addr): Remove.
+       (build_unary_op): Just check it's not a bitfield, and then build
+       an ADDR_EXPR.
+
 2002-08-08  Nathan Sidwell  <nathan@codesourcery.com>
 
        * class.c (convert_to_base): Correct check for error_mark_node.
index 6ac38224a248ea8455861f14de514575e1419e73..97626f68b29be52ca4f8640735f4c1d28b253cb5 100644 (file)
@@ -57,7 +57,6 @@ static int comp_array_types PARAMS ((int (*) (tree, tree, int), tree,
 static tree common_base_type PARAMS ((tree, tree));
 static tree lookup_anon_field PARAMS ((tree, tree));
 static tree pointer_diff PARAMS ((tree, tree, tree));
-static tree build_component_addr PARAMS ((tree, tree));
 static tree qualify_type_recursive PARAMS ((tree, tree));
 static tree get_delta_difference PARAMS ((tree, tree, int));
 static int comp_cv_target_types PARAMS ((tree, tree, int));
@@ -3741,50 +3740,6 @@ pointer_diff (op0, op1, ptrtype)
   return folded;
 }
 \f
-/* Handle the case of taking the address of a COMPONENT_REF.
-   Called by `build_unary_op'.
-
-   ARG is the COMPONENT_REF whose address we want.
-   ARGTYPE is the pointer type that this address should have. */
-
-static tree
-build_component_addr (arg, argtype)
-     tree arg, argtype;
-{
-  tree field = TREE_OPERAND (arg, 1);
-  tree basetype = decl_type_context (field);
-  tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
-
-  my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 981018);
-
-  if (DECL_C_BIT_FIELD (field))
-    {
-      error ("attempt to take address of bit-field structure member `%D'",
-                field);
-      return error_mark_node;
-    }
-
-  if (TREE_CODE (field) == FIELD_DECL
-      && TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (basetype))
-    {
-      /* Can't convert directly to ARGTYPE, since that
-        may have the same pointer type as one of our
-        baseclasses.  */
-      tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (rval)), basetype,
-                               ba_check, NULL);
-
-      rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
-      rval = build1 (NOP_EXPR, argtype, rval);
-      TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
-    }
-  else
-    /* This conversion is harmless.  */
-    rval = convert_force (argtype, rval, 0);
-
-  return fold (build (PLUS_EXPR, argtype, rval,
-                     cp_convert (argtype, byte_position (field))));
-}
-   
 /* Construct and perhaps optimize a tree representation
    for a unary operation.  CODE, a tree_code, specifies the operation
    and XARG is the operand.  */
@@ -4290,8 +4245,13 @@ build_unary_op (code, xarg, noconvert)
       {
        tree addr;
 
-       if (TREE_CODE (arg) == COMPONENT_REF)
-         addr = build_component_addr (arg, argtype);
+       if (TREE_CODE (arg) == COMPONENT_REF
+           && 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
          addr = build1 (ADDR_EXPR, argtype, arg);
 
index c458f430f887826cb33b7dd1adb4fcef2a1e0bd8..fa5f8e73541f480d7528ff130596cb0a6c3270ed 100644 (file)
@@ -1,3 +1,7 @@
+2002-08-08  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/other/packed1.C: New test.
+
 2002-08-07  Mark Mitchell  <mark@codesourcery.com>
 
        * g++.dg/abi/offsetof.C: Tweak error messages.
diff --git a/gcc/testsuite/g++.dg/other/packed1.C b/gcc/testsuite/g++.dg/other/packed1.C
new file mode 100644 (file)
index 0000000..b515854
--- /dev/null
@@ -0,0 +1,22 @@
+// { dg-do run }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 8 Aug 2002 <nathan@codesourcery.com>
+
+// WRS SPR 63496, lost packed attribute when accessing a packed
+// field. This matters on aligned architectures like sh
+
+struct thing { int m; };
+
+struct pod {char a; thing m __attribute__ ((packed)); };
+
+int main ()
+{
+  thing t;
+  pod p;
+  
+  p.m = t; /* runtime bus error here */
+
+  return 0;
+  
+};