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/cp/cp-objcp-common.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/cp/cp-objcp-common.h')
-rw-r--r-- | gcc/cp/cp-objcp-common.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/cp/cp-objcp-common.h b/gcc/cp/cp-objcp-common.h index 4c13731..3c04e5c 100644 --- a/gcc/cp/cp-objcp-common.h +++ b/gcc/cp/cp-objcp-common.h @@ -31,6 +31,7 @@ extern int cp_decl_dwarf_attribute (const_tree, int); extern int cp_type_dwarf_attribute (const_tree, int); extern void cp_common_init_ts (void); extern tree cp_unit_size_without_reusable_padding (tree); +extern tree cp_classtype_as_base (const_tree); extern tree cp_get_global_decls (); extern tree cp_pushdecl (tree); extern void cp_register_dumps (gcc::dump_manager *); @@ -167,6 +168,8 @@ extern tree cxx_simulate_record_decl (location_t, const char *, #define LANG_HOOKS_TYPE_DWARF_ATTRIBUTE cp_type_dwarf_attribute #undef LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING #define LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING cp_unit_size_without_reusable_padding +#undef LANG_HOOKS_CLASSTYPE_AS_BASE +#define LANG_HOOKS_CLASSTYPE_AS_BASE cp_classtype_as_base #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING #define LANG_HOOKS_OMP_PREDETERMINED_SHARING cxx_omp_predetermined_sharing |