diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-03-14 10:47:38 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-03-14 10:47:38 +0100 |
commit | c879b92c30d088ff01eb0c3e912eb8a01f9fc6e3 (patch) | |
tree | 46d4451b5c6b4cc2d64f0558b14dc39f08595762 /libgomp/fortran.c | |
parent | a010954cc190e942994ed5d56fba503851b20b9a (diff) | |
download | gcc-c879b92c30d088ff01eb0c3e912eb8a01f9fc6e3.zip gcc-c879b92c30d088ff01eb0c3e912eb8a01f9fc6e3.tar.gz gcc-c879b92c30d088ff01eb0c3e912eb8a01f9fc6e3.tar.bz2 |
c++: Reject __builtin_clear_padding on non-trivially-copyable types with one exception [PR102586]
As mentioned by Jason in the PR, non-trivially-copyable types (or non-POD
for purposes of layout?) types can be base classes of derived classes in
which the padding in those non-trivially-copyable types can be reused for
some real data members or even the layout can change and data members can
be moved to other positions.
__builtin_clear_padding is right now used for multiple purposes,
in <atomic> where it isn't used yet but was planned as the main spot
it can be used for trivially copyable types only, ditto for std::bit_cast
where we also use it. It is used for OpenMP long double atomics too but
long double is trivially copyable, and lastly for -ftrivial-auto-var-init=.
The following patch restricts the builtin to pointers to trivially-copyable
types, with the exception when it is called directly on an address of a
variable, in that case already the FE can verify it is the complete object
type and so it is safe to clear all the paddings in it.
2022-03-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/102586
gcc/
* doc/extend.texi (__builtin_clear_padding): Clearify that for C++
argument type should be pointer to trivially-copyable type unless it
is address of a variable or parameter.
gcc/cp/
* call.cc (build_cxx_call): Diagnose __builtin_clear_padding where
first argument's type is pointer to non-trivially-copyable type unless
it is address of a variable or parameter.
gcc/testsuite/
* g++.dg/cpp2a/builtin-clear-padding1.C: New test.
Diffstat (limited to 'libgomp/fortran.c')
0 files changed, 0 insertions, 0 deletions