public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards
@ 2021-12-13 12:24 n.deshmukh at samsung dot com
2021-12-13 12:26 ` [Bug other/103681] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: n.deshmukh at samsung dot com @ 2021-12-13 12:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Bug ID: 103681
Summary: Unusual behavior for tail padding with different c++
standards
Product: gcc
Version: 8.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
Assignee: unassigned at gcc dot gnu.org
Reporter: n.deshmukh at samsung dot com
Target Milestone: ---
When I tried to link two modules which were compiled with different c++
standards, I observed that the offset of some fields of struct were different
when the same struct was accessed from both the modules. The issue is due to
the use of tail padding to allocate member variables in some standards (c++03,
c++11) and not with others (c++14, c++17). I created a small program to
reproduce the behaviour.
-----------------------------padding_error.cpp----------------------------
#include <iostream>
#include <stdint.h>
#include <cstddef>
struct A {
int a;
uint64_t b;
int c = -1;
};
struct B : public A {
int d;
};
int main() {
std::cout << "sizeof(A): " << sizeof(A);
std::cout << ", sizeof(B): " << sizeof(B) << std::endl;
std::cout << "offset of d in B: " << (int)offsetof(B, d) << std::endl;
}
--------------------------------------------------------------------------
The output of this program depends on the -std flag.
~$ /opt/rh/devtoolset-8/root/bin/g++ -std=c++03 padding_error.cpp -o c03
~$ ./c03
sizeof(A): 24, sizeof(B): 24
offset of d in B: 20
~$ /opt/rh/devtoolset-8/root/bin/g++ -std=c++11 padding_error.cpp -o c11
~$ ./c11
sizeof(A): 24, sizeof(B): 24
offset of d in B: 20
~$ /opt/rh/devtoolset-8/root/bin/g++ -std=c++14 padding_error.cpp -o c14
~$ ./c14
sizeof(A): 24, sizeof(B): 32
offset of d in B: 24
~$ /opt/rh/devtoolset-8/root/bin/g++ -std=c++17 padding_error.cpp -o c17
~$ ./c17
sizeof(A): 24, sizeof(B): 32
offset of d in B: 24
I tried with different versions of gcc but the output is the same.
Because of the difference in the offset of the fields, I cannot link files
which were compiled with different -std flags.
The issue can be reproduced with all the gcc compilers which support c++14.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug other/103681] Unusual behavior for tail padding with different c++ standards
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
@ 2021-12-13 12:26 ` pinskia at gcc dot gnu.org
2021-12-13 12:58 ` [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-13 12:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |blocker
Keywords| |ABI, wrong-code
Ever confirmed|0 |1
Last reconfirmed| |2021-12-13
Known to fail| |12.0
Status|UNCONFIRMED |NEW
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Some more information from
Jonathan Wakely:
The C++14 behaviour started with r216750
Implement N3653 (Member initializers and aggregates) and fix
references to 'this' in constexpr cons
tructors.
Implement N3653 (Member initializers and aggregates) and fix
references to 'this' in constexpr constructors.
* class.c (check_field_decls): In C++14 an NSDMI does not make the
class non-aggregate.
But I think the layout should be using "POD for the purpose of
layout", which means the C++98 POD rules. Please do report it to
bugzilla.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
2021-12-13 12:26 ` [Bug other/103681] " pinskia at gcc dot gnu.org
@ 2021-12-13 12:58 ` pinskia at gcc dot gnu.org
2021-12-13 18:55 ` jason at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-13 12:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Unusual behavior for tail |[9/10/11/12 Regression]
|padding with different c++ |Unusual behavior for tail
|standards and NSDMI |padding with different c++
| |standards and NSDMI
Target Milestone|--- |9.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
2021-12-13 12:26 ` [Bug other/103681] " pinskia at gcc dot gnu.org
2021-12-13 12:58 ` [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI pinskia at gcc dot gnu.org
@ 2021-12-13 18:55 ` jason at gcc dot gnu.org
2021-12-13 19:02 ` jason at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-12-13 18:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Status|NEW |ASSIGNED
Priority|P3 |P1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
` (2 preceding siblings ...)
2021-12-13 18:55 ` jason at gcc dot gnu.org
@ 2021-12-13 19:02 ` jason at gcc dot gnu.org
2021-12-14 18:43 ` jason at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-12-13 19:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
compile-time testcase
struct A {
long l;
char c = -1;
};
struct B : public A {
char d;
};
#define SA(X) static_assert(X,#X)
SA(sizeof (B) == sizeof (A) || alignof (long) < 2*sizeof(char));
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
` (3 preceding siblings ...)
2021-12-13 19:02 ` jason at gcc dot gnu.org
@ 2021-12-14 18:43 ` jason at gcc dot gnu.org
2021-12-17 3:27 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-12-14 18:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P1 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
` (4 preceding siblings ...)
2021-12-14 18:43 ` jason at gcc dot gnu.org
@ 2021-12-17 3:27 ` cvs-commit at gcc dot gnu.org
2021-12-17 20:42 ` [Bug c++/103681] [9/10/11 " jason at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-17 3:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:a37e8ce3b66325f0c6de55c80d50ac1664c3d0eb
commit r12-6028-ga37e8ce3b66325f0c6de55c80d50ac1664c3d0eb
Author: Jason Merrill <jason@redhat.com>
Date: Tue Dec 14 17:00:40 2021 -0500
c++: layout of aggregate base with DMI [PR103681]
C++14 changed the definition of 'aggregate' to allow default member
initializers, but such classes still need to be considered "non-POD for the
purpose of layout" for ABI compatibility with C++11 code. It seems rare to
derive from such a class, as evidenced by how long this bug has
survived (since r216750 in 2014), but it's certainly worth fixing.
We only warn when we were failing to allocate another field into the
tail padding of the newly aggregate class; this is the only ABI impact.
This also changes end_of_class to consider all data members, not just empty
data members; that used to be an additional flag, removed in r9-5710, but I
don't see any reason not to always include them. This makes the result of
the function correspond to the ABI nvsize term and its nameless counterpart
that does include virtual bases.
When looking closely at other users of end_of_class, I realized that we
were
assuming that the latter corresponded to the ABI dsize term, but it doesn't
if the class ends with an empty virtual base (in the rare case that the
empty base can't be assigned offset 0), and this matters for layout of
[[no_unique_address]]. So I added another mode that returns the desired
value for that case. I'm not adding a warning for this ABI fix because
it's
a C++20 feature.
PR c++/103681
gcc/ChangeLog:
* common.opt (fabi-version): Add v17.
gcc/cp/ChangeLog:
* cp-tree.h (struct lang_type): Add non_pod_aggregate.
(CLASSTYPE_NON_POD_AGGREGATE): New.
* class.c (check_field_decls): Set it.
(check_bases_and_members): Check it.
(check_non_pod_aggregate): New.
(enum eoc_mode): New.
(end_of_class): Always include non-empty fields.
Add eoc_nv_or_dsize mode.
(include_empty_classes, layout_class_type): Adjust.
gcc/c-family/ChangeLog:
* c-opts.c (c_common_post_options): Update defaults.
gcc/testsuite/ChangeLog:
* g++.dg/abi/macro0.C: Update value.
* g++.dg/abi/no_unique_address6.C: New test.
* g++.dg/abi/nsdmi-aggr1.C: New test.
* g++.dg/abi/nsdmi-aggr1a.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
` (5 preceding siblings ...)
2021-12-17 3:27 ` cvs-commit at gcc dot gnu.org
@ 2021-12-17 20:42 ` jason at gcc dot gnu.org
2022-01-21 17:06 ` cvs-commit at gcc dot gnu.org
2022-05-13 15:27 ` jason at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2021-12-17 20:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12 Regression] |[9/10/11 Regression]
|Unusual behavior for tail |Unusual behavior for tail
|padding with different c++ |padding with different c++
|standards and NSDMI |standards and NSDMI
Known to fail|12.0 |
Known to work| |12.0
Severity|blocker |major
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12 so far.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
` (6 preceding siblings ...)
2021-12-17 20:42 ` [Bug c++/103681] [9/10/11 " jason at gcc dot gnu.org
@ 2022-01-21 17:06 ` cvs-commit at gcc dot gnu.org
2022-05-13 15:27 ` jason at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-21 17:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:23be9f83bbd2c6f03580757adbfe599de6bf702b
commit r12-6800-g23be9f83bbd2c6f03580757adbfe599de6bf702b
Author: Jason Merrill <jason@redhat.com>
Date: Fri Jan 21 11:16:49 2022 -0500
c++: [[no_unique_address]] and virtual base [PR104139]
Fixing a thinko in my patch for 103681: when computing the size of a
virtual
base, it would help to use its binfo instead of the one for the derived
class.
PR c++/104139
PR c++/103681
gcc/cp/ChangeLog:
* class.cc (end_of_class): Use base_binfo.
gcc/testsuite/ChangeLog:
* g++.dg/abi/no_unique_address2.C: Adjust to detect this on x86-64.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/103681] [9/10/11 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
` (7 preceding siblings ...)
2022-01-21 17:06 ` cvs-commit at gcc dot gnu.org
@ 2022-05-13 15:27 ` jason at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2022-05-13 15:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103681
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Target Milestone|9.5 |12.0
Resolution|--- |FIXED
--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Not backporting layout change.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-05-13 15:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 12:24 [Bug other/103681] New: Unusual behavior for tail padding with different c++ standards n.deshmukh at samsung dot com
2021-12-13 12:26 ` [Bug other/103681] " pinskia at gcc dot gnu.org
2021-12-13 12:58 ` [Bug c++/103681] [9/10/11/12 Regression] Unusual behavior for tail padding with different c++ standards and NSDMI pinskia at gcc dot gnu.org
2021-12-13 18:55 ` jason at gcc dot gnu.org
2021-12-13 19:02 ` jason at gcc dot gnu.org
2021-12-14 18:43 ` jason at gcc dot gnu.org
2021-12-17 3:27 ` cvs-commit at gcc dot gnu.org
2021-12-17 20:42 ` [Bug c++/103681] [9/10/11 " jason at gcc dot gnu.org
2022-01-21 17:06 ` cvs-commit at gcc dot gnu.org
2022-05-13 15:27 ` jason at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).