diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-04-07 09:14:07 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-04-07 09:14:07 +0200 |
commit | 46c739d40c6c1028295931c53cf414d581519072 (patch) | |
tree | 70ecb58f0520543a4b071225b890f17fc21c9da6 /gcc/langhooks.h | |
parent | 973a2ce71f8dab559fbbfc34b59e39e047df74a6 (diff) | |
download | gcc-46c739d40c6c1028295931c53cf414d581519072.zip gcc-46c739d40c6c1028295931c53cf414d581519072.tar.gz gcc-46c739d40c6c1028295931c53cf414d581519072.tar.bz2 |
c++: Handle __builtin_clear_padding on non-trivially-copyable types [PR102586]
On Fri, Feb 11, 2022 at 07:55:50PM +0100, Jakub Jelinek via Gcc-patches wrote:
> Something like the https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102586#c16
> will still be needed with adjusted testcase from
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102586#c15 such that
> __builtin_clear_padding is called directly on var addresses rather than
> in separate functions.
Here is an updated version of the
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102586#c15
patch which uses FIELD_DECL in the langhook instead of its TREE_TYPE,
and the testcases have been adjusted for the builtin accepting
pointers to non-trivially-copyable types only if it is address of a
declaration.
2022-04-07 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/102586
gcc/
* langhooks.h (struct lang_hooks_for_types): Add classtype_as_base
langhook.
* langhooks-def.h (LANG_HOOKS_CLASSTYPE_AS_BASE): Define.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add it.
* gimple-fold.cc (clear_padding_type): Use ftype instead of
TREE_TYPE (field) some more. For artificial FIELD_DECLs without
name try the lang_hooks.types.classtype_as_base langhook and
if it returns non-NULL, use that instead of ftype for recursive call.
gcc/cp/
* cp-objcp-common.h (cp_classtype_as_base): Declare.
(LANG_HOOKS_CLASSTYPE_AS_BASE): Redefine.
* cp-objcp-common.cc (cp_classtype_as_base): New function.
gcc/testsuite/
* g++.dg/torture/builtin-clear-padding-5.C: New test.
* g++.dg/cpp2a/builtin-clear-padding1.C (bar): Uncomment one
call that is now accepted.
Diffstat (limited to 'gcc/langhooks.h')
-rw-r--r-- | gcc/langhooks.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/langhooks.h b/gcc/langhooks.h index 0eec1b0..4731f08 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -188,6 +188,11 @@ struct lang_hooks_for_types /* Returns a tree for the unit size of T excluding tail padding that might be used by objects inheriting from T. */ tree (*unit_size_without_reusable_padding) (tree); + + /* Returns type corresponding to FIELD's type when FIELD is a C++ base class + i.e., type without virtual base classes or tail padding. Returns + NULL_TREE otherwise. */ + tree (*classtype_as_base) (const_tree); }; /* Language hooks related to decls and the symbol table. */ |