From clark.nelson at intel.com Fri Dec 11 00:11:18 2015 From: clark.nelson at intel.com (Nelson, Clark) Date: Fri, 11 Dec 2015 00:11:18 +0000 Subject: [cxx-abi-dev] Passing an empty class by value Message-ID: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> It has come to my attention that GCC and clang generate incompatible code for passing an argument of an empty class type. clang seems to completely ignore arguments and parameters of empty class type -- which seems to make a certain amount of sense. OTOH, as far as I understand it, GCC effectively treats an empty class equivalently to a class containing a single member with some character type -- which also seems pretty reasonable. Should the C++ ABI come down on one side or the other of this question? This is really the sort of question a psABI should settle. But of course the C language doesn't actually support a structure with no members, so it's not too surprising if a psABI doesn't nail down what should happen for this. -- Clark Nelson Chair, PL22.16 (ANSI C++ standard committee) Intel Corporation Chair, SG10 (C++ SG for feature-testing) clark.nelson at intel.com Chair, CPLEX (C SG for parallel language extensions) From rjmccall at apple.com Fri Dec 11 00:15:30 2015 From: rjmccall at apple.com (John McCall) Date: Thu, 10 Dec 2015 16:15:30 -0800 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> Message-ID: <42A290F1-70B3-4BC1-A4F5-F42051DB7629@apple.com> > On Dec 10, 2015, at 4:11 PM, Nelson, Clark wrote: > > It has come to my attention that GCC and clang generate incompatible code > for passing an argument of an empty class type. > > clang seems to completely ignore arguments and parameters of empty class > type -- which seems to make a certain amount of sense. > > OTOH, as far as I understand it, GCC effectively treats an empty class > equivalently to a class containing a single member with some character > type -- which also seems pretty reasonable. > > Should the C++ ABI come down on one side or the other of this question? > > This is really the sort of question a psABI should settle. But of course > the C language doesn't actually support a structure with no members, so > it's not too surprising if a psABI doesn't nail down what should happen > for this. It?s valid as a C extension in GCC. If there are platforms where we use a different rule from GCC, we should come to some understanding with them. Because of the GCC extension, C++ can?t really use different rules from C. John. > > -- > Clark Nelson Chair, PL22.16 (ANSI C++ standard committee) > Intel Corporation Chair, SG10 (C++ SG for feature-testing) > clark.nelson at intel.com Chair, CPLEX (C SG for parallel language extensions) > _______________________________________________ > cxx-abi-dev mailing list > cxx-abi-dev at codesourcery.com > http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev From rjmccall at apple.com Fri Dec 11 00:17:07 2015 From: rjmccall at apple.com (John McCall) Date: Thu, 10 Dec 2015 16:17:07 -0800 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: <42A290F1-70B3-4BC1-A4F5-F42051DB7629@apple.com> References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> <42A290F1-70B3-4BC1-A4F5-F42051DB7629@apple.com> Message-ID: <60519BF5-76AF-4958-8151-A1493384B344@apple.com> > On Dec 10, 2015, at 4:15 PM, John McCall wrote: >> On Dec 10, 2015, at 4:11 PM, Nelson, Clark wrote: >> >> It has come to my attention that GCC and clang generate incompatible code >> for passing an argument of an empty class type. >> >> clang seems to completely ignore arguments and parameters of empty class >> type -- which seems to make a certain amount of sense. >> >> OTOH, as far as I understand it, GCC effectively treats an empty class >> equivalently to a class containing a single member with some character >> type -- which also seems pretty reasonable. >> >> Should the C++ ABI come down on one side or the other of this question? >> >> This is really the sort of question a psABI should settle. But of course >> the C language doesn't actually support a structure with no members, so >> it's not too surprising if a psABI doesn't nail down what should happen >> for this. > > It?s valid as a C extension in GCC. If there are platforms where we use a > different rule from GCC, we should come to some understanding with them. Sorry, that was me wearing my ?clang? hat. The C++ ABI answer is that, because of this: > Because of the GCC extension, C++ can?t really use different rules from C. this has to be resolved in the psABI, or at least in the system compiler?s filling-in of the psABI?s details. John. From richardsmith at googlers.com Fri Dec 11 00:32:13 2015 From: richardsmith at googlers.com (Richard Smith) Date: Thu, 10 Dec 2015 16:32:13 -0800 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: <42A290F1-70B3-4BC1-A4F5-F42051DB7629@apple.com> References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> <42A290F1-70B3-4BC1-A4F5-F42051DB7629@apple.com> Message-ID: On 10 December 2015 at 16:15, John McCall wrote: > > On Dec 10, 2015, at 4:11 PM, Nelson, Clark > wrote: > > > > It has come to my attention that GCC and clang generate incompatible code > > for passing an argument of an empty class type. > > > > clang seems to completely ignore arguments and parameters of empty class > > type -- which seems to make a certain amount of sense. > > > > OTOH, as far as I understand it, GCC effectively treats an empty class > > equivalently to a class containing a single member with some character > > type -- which also seems pretty reasonable. > > > > Should the C++ ABI come down on one side or the other of this question? > > > > This is really the sort of question a psABI should settle. But of course > > the C language doesn't actually support a structure with no members, so > > it's not too surprising if a psABI doesn't nail down what should happen > > for this. > > It?s valid as a C extension in GCC. If there are platforms where we use a > different rule from GCC, we should come to some understanding with them. > > Because of the GCC extension, C++ can?t really use different rules from C. (For x86_64:) GCC uses different rules for C and C++. In C, they do not pass anything. In C++, they pass a 1-byte object on the stack. Clang uses the same rules for C and C++, passing nothing in both cases. A careful reading of the x86_64 psABI suggests that clang is right in both cases; the eightbyte corresponding to the 1-byte empty struct parameter is never classified (at all), so should occupy neither a register nor memory, but it's not really especially clear. In any case, I think GCC should be the one to change here, because its C and C++ ABIs don't match. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marc.glisse at inria.fr Fri Dec 11 07:05:48 2015 From: marc.glisse at inria.fr (Marc Glisse) Date: Fri, 11 Dec 2015 08:05:48 +0100 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> Message-ID: On Fri, 11 Dec 2015, Nelson, Clark wrote: > It has come to my attention that GCC and clang generate incompatible code > for passing an argument of an empty class type. > > clang seems to completely ignore arguments and parameters of empty class > type -- which seems to make a certain amount of sense. > > OTOH, as far as I understand it, GCC effectively treats an empty class > equivalently to a class containing a single member with some character > type -- which also seems pretty reasonable. > > Should the C++ ABI come down on one side or the other of this question? See A-5 in https://mentorembedded.github.io/cxx-abi/cxx-closed.html for some historical discussion. > This is really the sort of question a psABI should settle. But of course > the C language doesn't actually support a structure with no members, so > it's not too surprising if a psABI doesn't nail down what should happen > for this. Last time I raised this, psABI was also suggested: http://sourcerytools.com/pipermail/cxx-abi-dev/2013-November/002627.html -- Marc Glisse From gdr at integrable-solutions.net Fri Dec 11 10:41:08 2015 From: gdr at integrable-solutions.net (Gabriel Dos Reis) Date: Fri, 11 Dec 2015 02:41:08 -0800 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> Message-ID: Passing nothing at all is makes the most sense for a vigorous C++ support. Passing a 1-byte that nothing can possibly read and makes sense of is an unfortunate sub-optimal codegen. On Thu, Dec 10, 2015 at 11:05 PM, Marc Glisse wrote: > On Fri, 11 Dec 2015, Nelson, Clark wrote: > > It has come to my attention that GCC and clang generate incompatible code >> for passing an argument of an empty class type. >> >> clang seems to completely ignore arguments and parameters of empty class >> type -- which seems to make a certain amount of sense. >> >> OTOH, as far as I understand it, GCC effectively treats an empty class >> equivalently to a class containing a single member with some character >> type -- which also seems pretty reasonable. >> >> Should the C++ ABI come down on one side or the other of this question? >> > > See A-5 in https://mentorembedded.github.io/cxx-abi/cxx-closed.html for > some historical discussion. > > This is really the sort of question a psABI should settle. But of course >> the C language doesn't actually support a structure with no members, so >> it's not too surprising if a psABI doesn't nail down what should happen >> for this. >> > > Last time I raised this, psABI was also suggested: > http://sourcerytools.com/pipermail/cxx-abi-dev/2013-November/002627.html > > -- > Marc Glisse > > _______________________________________________ > cxx-abi-dev mailing list > cxx-abi-dev at codesourcery.com > http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rjmccall at apple.com Fri Dec 11 18:08:23 2015 From: rjmccall at apple.com (John McCall) Date: Fri, 11 Dec 2015 10:08:23 -0800 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> Message-ID: > On Dec 11, 2015, at 2:41 AM, Gabriel Dos Reis wrote: > > Passing nothing at all is makes the most sense for a vigorous C++ support. Passing a 1-byte that nothing can possibly read and makes sense of is an unfortunate sub-optimal codegen. I completely agree that psABI authors should specify that empty types are passed as nothing. John. > > On Thu, Dec 10, 2015 at 11:05 PM, Marc Glisse > wrote: > On Fri, 11 Dec 2015, Nelson, Clark wrote: > > It has come to my attention that GCC and clang generate incompatible code > for passing an argument of an empty class type. > > clang seems to completely ignore arguments and parameters of empty class > type -- which seems to make a certain amount of sense. > > OTOH, as far as I understand it, GCC effectively treats an empty class > equivalently to a class containing a single member with some character > type -- which also seems pretty reasonable. > > Should the C++ ABI come down on one side or the other of this question? > > See A-5 in https://mentorembedded.github.io/cxx-abi/cxx-closed.html for some historical discussion. > > This is really the sort of question a psABI should settle. But of course > the C language doesn't actually support a structure with no members, so > it's not too surprising if a psABI doesn't nail down what should happen > for this. > > Last time I raised this, psABI was also suggested: > http://sourcerytools.com/pipermail/cxx-abi-dev/2013-November/002627.html > > -- > Marc Glisse > > _______________________________________________ > cxx-abi-dev mailing list > cxx-abi-dev at codesourcery.com > http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev > > _______________________________________________ > cxx-abi-dev mailing list > cxx-abi-dev at codesourcery.com > http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason at redhat.com Fri Dec 11 18:37:55 2015 From: jason at redhat.com (Jason Merrill) Date: Fri, 11 Dec 2015 13:37:55 -0500 Subject: [cxx-abi-dev] Passing an empty class by value In-Reply-To: References: <38C37E44FD352B44ABFC58410B0790D0901271A2@ORSMSX103.amr.corp.intel.com> <42A290F1-70B3-4BC1-A4F5-F42051DB7629@apple.com> Message-ID: <566B1803.8070201@redhat.com> On 12/10/2015 07:32 PM, Richard Smith wrote: > On 10 December 2015 at 16:15, John McCall wrote: > >>> On Dec 10, 2015, at 4:11 PM, Nelson, Clark >> wrote: >>> >>> It has come to my attention that GCC and clang generate incompatible code >>> for passing an argument of an empty class type. >>> >>> clang seems to completely ignore arguments and parameters of empty class >>> type -- which seems to make a certain amount of sense. >>> >>> OTOH, as far as I understand it, GCC effectively treats an empty class >>> equivalently to a class containing a single member with some character >>> type -- which also seems pretty reasonable. >>> >>> Should the C++ ABI come down on one side or the other of this question? >>> >>> This is really the sort of question a psABI should settle. But of course >>> the C language doesn't actually support a structure with no members, so >>> it's not too surprising if a psABI doesn't nail down what should happen >>> for this. >> >> It?s valid as a C extension in GCC. If there are platforms where we use a >> different rule from GCC, we should come to some understanding with them. >> >> Because of the GCC extension, C++ can?t really use different rules from C. > > > (For x86_64:) GCC uses different rules for C and C++. In C, they do not > pass anything. In C++, they pass a 1-byte object on the stack. Clang uses > the same rules for C and C++, passing nothing in both cases. > > A careful reading of the x86_64 psABI suggests that clang is right in both > cases; the eightbyte corresponding to the 1-byte empty struct parameter is > never classified (at all), so should occupy neither a register nor memory, > but it's not really especially clear. > > In any case, I think GCC should be the one to change here, because its C > and C++ ABIs don't match. Agreed. Jason From hjl.tools at gmail.com Wed Dec 9 21:39:40 2015 From: hjl.tools at gmail.com (H.J. Lu) Date: Wed, 09 Dec 2015 21:39:40 -0000 Subject: [cxx-abi-dev] Should C++ ABI specify how empty class is passed? Message-ID: From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60336 GCC passes empty class as one-byte record. On x86-64, it is always passed on stack. Clang skips empty class the same way as C empty struct. Empty C++ class is a corner case which isn't covered in psABI nor C++ ABI. Should C++ ABI specify how it is passed? -- H.J.