From 70df40cab6f268ba7f05c6d1421928cca0834ee3 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 8 Apr 2020 17:16:55 +0200 Subject: Allow new/delete operator deletion only for replaceable. PR c++/94314 * gimple.c (gimple_call_operator_delete_p): Rename to... (gimple_call_replaceable_operator_delete_p): ... this. Use DECL_IS_REPLACEABLE_OPERATOR_DELETE_P. * gimple.h (gimple_call_operator_delete_p): Rename to ... (gimple_call_replaceable_operator_delete_p): ... this. * tree-core.h (tree_function_decl): Add replaceable_operator flag. * tree-ssa-dce.c (mark_all_reaching_defs_necessary_1): Use DECL_IS_REPLACEABLE_OPERATOR_DELETE_P. (propagate_necessity): Use gimple_call_replaceable_operator_delete_p. (eliminate_unnecessary_stmts): Likewise. * tree-streamer-in.c (unpack_ts_function_decl_value_fields): Pack DECL_IS_REPLACEABLE_OPERATOR. * tree-streamer-out.c (pack_ts_function_decl_value_fields): Unpack the field here. * tree.h (DECL_IS_REPLACEABLE_OPERATOR): New. (DECL_IS_REPLACEABLE_OPERATOR_NEW_P): New. (DECL_IS_REPLACEABLE_OPERATOR_DELETE_P): New. * cgraph.c (cgraph_node::dump): Dump if an operator is replaceable. * ipa-icf.c (sem_item::compare_referenced_symbol_properties): Compare replaceable operator flags. PR c++/94314 * decl.c (duplicate_decls): Duplicate also DECL_IS_REPLACEABLE_OPERATOR. (cxx_init_decl_processing): Mark replaceable all implicitly defined operators. PR c++/94314 * lto-common.c (compare_tree_sccs_1): Compare also DECL_IS_REPLACEABLE_OPERATOR. PR c++/94314 * g++.dg/pr94314-2.C: New test. * g++.dg/pr94314-3.C: New test. * g++.dg/pr94314.C: New test. --- gcc/tree.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'gcc/tree.h') diff --git a/gcc/tree.h b/gcc/tree.h index 66dfa87..1c28785 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3037,6 +3037,11 @@ set_function_decl_type (tree decl, function_decl_type t, bool set) FUNCTION_DECL_DECL_TYPE (decl) = NONE; } +/* Nonzero in a FUNCTION_DECL means this function is a replaceable + function (like replaceable operators new or delete). */ +#define DECL_IS_REPLACEABLE_OPERATOR(NODE)\ + (FUNCTION_DECL_CHECK (NODE)->function_decl.replaceable_operator) + /* Nonzero in a FUNCTION_DECL means this function should be treated as C++ operator new, meaning that it returns a pointer for which we should not use type based aliasing. */ @@ -3044,7 +3049,7 @@ set_function_decl_type (tree decl, function_decl_type t, bool set) (FUNCTION_DECL_CHECK (NODE)->function_decl.decl_type == OPERATOR_NEW) #define DECL_IS_REPLACEABLE_OPERATOR_NEW_P(NODE) \ - (DECL_IS_OPERATOR_NEW_P (NODE) && DECL_IS_MALLOC (NODE)) + (DECL_IS_OPERATOR_NEW_P (NODE) && DECL_IS_REPLACEABLE_OPERATOR (NODE)) #define DECL_SET_IS_OPERATOR_NEW(NODE, VAL) \ set_function_decl_type (FUNCTION_DECL_CHECK (NODE), OPERATOR_NEW, VAL) @@ -3054,6 +3059,9 @@ set_function_decl_type (tree decl, function_decl_type t, bool set) #define DECL_IS_OPERATOR_DELETE_P(NODE) \ (FUNCTION_DECL_CHECK (NODE)->function_decl.decl_type == OPERATOR_DELETE) +#define DECL_IS_REPLACEABLE_OPERATOR_DELETE_P(NODE) \ + (DECL_IS_OPERATOR_DELETE_P (NODE) && DECL_IS_REPLACEABLE_OPERATOR (NODE)) + #define DECL_SET_IS_OPERATOR_DELETE(NODE, VAL) \ set_function_decl_type (FUNCTION_DECL_CHECK (NODE), OPERATOR_DELETE, VAL) -- cgit v1.1