aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-03-14 10:47:38 +0100
committerJakub Jelinek <jakub@redhat.com>2022-03-14 10:47:38 +0100
commitc879b92c30d088ff01eb0c3e912eb8a01f9fc6e3 (patch)
tree46d4451b5c6b4cc2d64f0558b14dc39f08595762 /gcc/doc
parenta010954cc190e942994ed5d56fba503851b20b9a (diff)
downloadgcc-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 'gcc/doc')
-rw-r--r--gcc/doc/extend.texi5
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 0dc752e8..a4a25e8 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -13993,6 +13993,11 @@ bits that are padding bits for all the union members.
This built-in-function is useful if the padding bits of an object might
have intederminate values and the object representation needs to be
bitwise compared to some other object, for example for atomic operations.
+
+For C++, @var{ptr} argument type should be pointer to trivially-copyable
+type, unless the argument is address of a variable or parameter, because
+otherwise it isn't known if the type isn't just a base class whose padding
+bits are reused or laid out differently in a derived class.
@end deftypefn
@deftypefn {Built-in Function} @var{type} __builtin_bit_cast (@var{type}, @var{arg})