OSDN Git Service

* class.c (layout_class_type): Make DECL_MODE match TYPE_MODE for
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 15 Sep 2003 00:27:16 +0000 (00:27 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 15 Sep 2003 00:27:16 +0000 (00:27 +0000)
an bit-field whose width exceeds that of its type.

* g++.dg/abi/bitfield11.C: New test.
* g++.dg/abi/bitfield12.C: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71392 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/abi/bitfield11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/abi/bitfield12.C [new file with mode: 0644]

index 582caf4..706ebbf 100644 (file)
@@ -4759,7 +4759,15 @@ layout_class_type (tree t, tree *virtuals_p)
             field to the size of its declared type; the rest of the
             field is effectively invisible.  */
          DECL_SIZE (field) = TYPE_SIZE (type);
-         DECL_MODE (field) = TYPE_MODE (type);
+         /* We must also reset the DECL_MODE of the field.  */
+         if (abi_version_at_least (2))
+           DECL_MODE (field) = TYPE_MODE (type);
+         else if (warn_abi
+                  && DECL_MODE (field) != TYPE_MODE (type))
+           /* Versions of G++ before G++ 3.4 did not reset the
+              DECL_MODE.  */
+           warning ("the offset of `%D' may not be ABI-compliant and may "
+                    "change in a future version of GCC", field);
        }
       else
        layout_nonempty_base_or_field (rli, field, NULL_TREE,
index 9d7c8e5..802d53e 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-14  Mark Mitchell  <mark@codesourcery.com>
+
+       * g++.dg/abi/bitfield11.C: New test.
+       * g++.dg/abi/bitfield12.C: Likewise.
+
 2003-09-14  Alexandre Oliva  <aoliva@redhat.com>
 
        * gcc.dg/cpp/separate-1.c: Adjust line of error.  Test for correct
diff --git a/gcc/testsuite/g++.dg/abi/bitfield11.C b/gcc/testsuite/g++.dg/abi/bitfield11.C
new file mode 100644 (file)
index 0000000..e78ea12
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do run } 
+// { dg-options "-w -fabi-version=0" }
+
+struct S {
+  char c : 1024;
+};
+
+S s;
+
+int main () {
+  s.c = 1;
+  if (*(char *)&s != 1)
+    return 1;
+}
diff --git a/gcc/testsuite/g++.dg/abi/bitfield12.C b/gcc/testsuite/g++.dg/abi/bitfield12.C
new file mode 100644 (file)
index 0000000..6cfda5d
--- /dev/null
@@ -0,0 +1,5 @@
+// { dg-options "-Wabi -fabi-version=1" }
+
+struct S { // { dg-warning "ABI" }
+  char c : 1024; // { dg-warning "width" }
+};