diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2019-08-13 21:35:10 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2019-08-13 21:35:10 +0000 |
commit | cb1180d547e3b28547134a06ee020163afa59cc3 (patch) | |
tree | 27381416159b7f256dd96a13ec9d99d1db40c29d /gcc/c/c-decl.c | |
parent | 0b1fe8cf6f1dde656c505dde6d27279dff388962 (diff) | |
download | gcc-cb1180d547e3b28547134a06ee020163afa59cc3.zip gcc-cb1180d547e3b28547134a06ee020163afa59cc3.tar.gz gcc-cb1180d547e3b28547134a06ee020163afa59cc3.tar.bz2 |
Protect some checks of DECL_FUNCTION_CODE
This patch protects various uses of DECL_FUNCTION_CODE that didn't
obviously check for BUILT_IN_NORMAL first (either directly or in callers).
They could therefore trigger for functions that either aren't built-ins
or are a different kind of built-in.
Also, the patch removes a redundant GIMPLE_CALL check from
optimize_stdarg_builtin, since it gave the impression that the stmt
was less well checked than it actually is.
2019-08-13 Richard Sandiford <richard.sandiford@arm.com>
gcc/
PR middle-end/91421
* attribs.c (decl_attributes): Check the DECL_BUILT_IN_CLASS
before the DECL_FUNCTION_CODE.
* calls.c (maybe_warn_alloc_args_overflow): Use fndecl_built_in_p
to check for a BUILT_IN_ALLOCA call.
* ipa-cp.c (ipa_get_indirect_edge_target_1): Likewise for
BUILT_IN_UNREACHABLE. Don't check for a FUNCTION_TYPE.
* ipa-devirt.c (possible_polymorphic_call_target_p): Likewise.
* ipa-prop.c (try_make_edge_direct_virtual_call): Likewise.
* gimple-ssa-isolate-paths.c (is_addr_local): Check specifically
for BUILT_IN_NORMAL functions.
* trans-mem.c (expand_block_edges): Use gimple_call_builtin_p to
test for BUILT_IN_TM_ABORT.
* tree-ssa-ccp.c (optimize_stack_restore): Use fndecl_built_in_p
to check for a BUILT_IN_STACK_RESTORE call.
(optimize_stdarg_builtin): Remove redundant check for GIMPLE_CALL.
* tree-ssa-threadedge.c
(record_temporary_equivalences_from_stmts_at_dest): Check for a
BUILT_IN_NORMAL decl before checking its DECL_FUNCTION_CODE.
* tree-vect-patterns.c (vect_recog_pow_pattern): Use a positive
test for a BUILT_IN_NORMAL call instead of a negative test for
an internal function call.
gcc/c/
PR middle-end/91421
* c-decl.c (header_for_builtin_fn): Take a FUNCTION_DECL instead
of a built_in_function.
(diagnose_mismatched_decls, implicitly_declare): Update accordingly.
From-SVN: r274403
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 9859cc7..18a97db1 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -605,7 +605,7 @@ static tree grokparms (struct c_arg_info *, bool); static void layout_array_type (tree); static void warn_defaults_to (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); -static const char *header_for_builtin_fn (enum built_in_function); +static const char *header_for_builtin_fn (tree); /* T is a statement. Add it to the statement-tree. This is the C/ObjC version--C++ has a slightly different version of this @@ -1953,7 +1953,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, if (!comptypes (oldtype, newtype)) { if (TREE_CODE (olddecl) == FUNCTION_DECL - && fndecl_built_in_p (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) + && fndecl_built_in_p (olddecl, BUILT_IN_NORMAL) + && !C_DECL_DECLARED_BUILTIN (olddecl)) { /* Accept "harmless" mismatches in function types such as missing qualifiers or pointer vs same size integer @@ -1975,8 +1976,7 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, /* If types don't match for a built-in, throw away the built-in. No point in calling locate_old_decl here, it won't print anything. */ - const char *header - = header_for_builtin_fn (DECL_FUNCTION_CODE (olddecl)); + const char *header = header_for_builtin_fn (olddecl); location_t loc = DECL_SOURCE_LOCATION (newdecl); if (warning_at (loc, OPT_Wbuiltin_declaration_mismatch, "conflicting types for built-in function %q+D; " @@ -3339,13 +3339,17 @@ implicit_decl_warning (location_t loc, tree id, tree olddecl) hint.suppress (); } -/* This function represents mapping of a function code FCODE - to its respective header. */ +/* Return the name of the header file that declares built-in function + FNDECL, or null if either we don't know or don't expect to see an + explicit declaration. */ static const char * -header_for_builtin_fn (enum built_in_function fcode) +header_for_builtin_fn (tree fndecl) { - switch (fcode) + if (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL) + return NULL; + + switch (DECL_FUNCTION_CODE (fndecl)) { CASE_FLT_FN (BUILT_IN_ACOS): CASE_FLT_FN (BUILT_IN_ACOSH): @@ -3595,8 +3599,7 @@ implicitly_declare (location_t loc, tree functionid) "declaration of built-in " "function %qD", decl); /* See if we can hint which header to include. */ - const char *header - = header_for_builtin_fn (DECL_FUNCTION_CODE (decl)); + const char *header = header_for_builtin_fn (decl); if (header != NULL && warned) { rich_location richloc (line_table, loc); |