This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: Jason Merrill <jason at redhat dot com>, Ulrich Weigand <uweigand at de dot ibm dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Jakub Jelinek <jakub at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, Markus Trippelsdorf <markus at trippelsdorf dot de>
- Date: Tue, 15 Mar 2016 17:23:24 -0700
- Subject: Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOrx2TKEnBsSzCkB6eB33FjsaFoyKqx68D=jgNzxjhNHng at mail dot gmail dot com> <20160302162538 dot 66068C88E at oc7340732750 dot ibm dot com> <CAMe9rOqF-B-he1JWaxq5++1a75vKtpECRAgcMDd+EbjdxQzLdQ at mail dot gmail dot com> <56E82BC4 dot 7070401 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1603152138570 dot 17533 at digraph dot polyomino dot org dot uk> <CAMe9rOq-EmEDSOvo-ycJ2PkZZyupcLVbTpEumKMAfQos2=8TKw at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1603152233290 dot 17533 at digraph dot polyomino dot org dot uk>
On Tue, Mar 15, 2016 at 3:34 PM, Joseph Myers <joseph@codesourcery.com> wrote:
> On Tue, 15 Mar 2016, H.J. Lu wrote:
>
>> On Tue, Mar 15, 2016 at 2:39 PM, Joseph Myers <joseph@codesourcery.com> wrote:
>> > I'm not sure if the zero-size arrays (a GNU extension) are considered to
>> > make a struct non-empty, but in any case I think the tests should cover
>> > such arrays as elements of structs.
>>
>> There are couple tests for structs with members of array
>> of empty types. testsuite/g++.dg/abi/empty14.h has
>
> My concern is the other way round - structs with elements such as
> "int a[0];", an array [0] of a nonempty type. My reading of the subobject
> definition is that such an array should not cause the struct to be
> considered nonempty (it doesn't result in any int subobjects).
This is a test for struct with zero-size array, which isn't treated
as empty type. C++ and C are compatible in its passing.
--
H.J.
From 549583547f8dfb284b6ae083031757371907671f Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 15 Mar 2016 17:20:08 -0700
Subject: [PATCH] Add a test for struct with zero-size array
---
gcc/testsuite/g++.dg/abi/empty18.C | 17 +++++++++++++++++
gcc/testsuite/g++.dg/abi/empty18.h | 9 +++++++++
gcc/testsuite/g++.dg/abi/empty18a.c | 6 ++++++
3 files changed, 32 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/abi/empty18.C
create mode 100644 gcc/testsuite/g++.dg/abi/empty18.h
create mode 100644 gcc/testsuite/g++.dg/abi/empty18a.c
diff --git a/gcc/testsuite/g++.dg/abi/empty18.C b/gcc/testsuite/g++.dg/abi/empty18.C
new file mode 100644
index 0000000..cf850ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/empty18.C
@@ -0,0 +1,17 @@
+// PR c++/60336
+// { dg-do run }
+// { dg-options "-Wabi=9 -x c" }
+// { dg-additional-sources "empty18a.c" }
+// { dg-prune-output "command line option" }
+
+#include "empty18.h"
+extern "C" void fun(struct dummy, struct foo);
+
+int main()
+{
+ struct dummy d;
+ struct foo f = { -1, -2, -3, -4, -5 };
+
+ fun(d, f);
+ return 0;
+}
diff --git a/gcc/testsuite/g++.dg/abi/empty18.h b/gcc/testsuite/g++.dg/abi/empty18.h
new file mode 100644
index 0000000..86e7ecd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/empty18.h
@@ -0,0 +1,9 @@
+struct dummy { int d[0]; };
+struct foo
+{
+ int i1;
+ int i2;
+ int i3;
+ int i4;
+ int i5;
+};
diff --git a/gcc/testsuite/g++.dg/abi/empty18a.c b/gcc/testsuite/g++.dg/abi/empty18a.c
new file mode 100644
index 0000000..902860b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/empty18a.c
@@ -0,0 +1,6 @@
+#include "empty18.h"
+void fun(struct dummy d, struct foo f)
+{
+ if (f.i1 != -1)
+ __builtin_abort();
+}
--
2.5.0