https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102586

--- Comment #29 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:c879b92c30d088ff01eb0c3e912eb8a01f9fc6e3

commit r12-7641-gc879b92c30d088ff01eb0c3e912eb8a01f9fc6e3
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Mar 14 10:47:38 2022 +0100

    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  <ja...@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.

Reply via email to