diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-01-26 18:40:43 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2020-01-31 09:00:57 -0500 |
commit | 182ce042e7325a05a87fb34d2eaf6db3666fbd7f (patch) | |
tree | d9b9ba23a26d11ec85cf122c6d369c6c1b53c4e8 /gcc/tree.h | |
parent | 45eb3e4944ba93b1d4e9070c703068cfa7aaace4 (diff) | |
download | gcc-182ce042e7325a05a87fb34d2eaf6db3666fbd7f.zip gcc-182ce042e7325a05a87fb34d2eaf6db3666fbd7f.tar.gz gcc-182ce042e7325a05a87fb34d2eaf6db3666fbd7f.tar.bz2 |
calls.c: refactor special_function_p for use by analyzer (v2)
This patch refactors some code in special_function_p that checks for
the function being sane to match by name, splitting it out into a new
maybe_special_function_p, and using it it two places in the analyzer.
gcc/analyzer/ChangeLog:
* analyzer.cc (is_named_call_p): Replace tests for fndecl being
extern at file scope and having a non-NULL DECL_NAME with a call
to maybe_special_function_p.
* function-set.cc (function_set::contains_decl_p): Add call to
maybe_special_function_p.
gcc/ChangeLog:
* calls.c (special_function_p): Split out the check for DECL_NAME
being non-NULL and fndecl being extern at file scope into a
new maybe_special_function_p and call it. Drop check for fndecl
being non-NULL that was after a usage of DECL_NAME (fndecl).
* tree.h (maybe_special_function_p): New inline function.
Diffstat (limited to 'gcc/tree.h')
-rw-r--r-- | gcc/tree.h | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -5611,6 +5611,31 @@ builtin_decl_declared_p (enum built_in_function fncode) && builtin_info[uns_fncode].declared_p); } +/* Determine if the function identified by FNDECL is one that + makes sense to match by name, for those places where we detect + "magic" functions by name. + + Return true if FNDECL has a name and is an extern fndecl at file scope. + FNDECL must be a non-NULL decl. + + Avoid using this, as it's generally better to use attributes rather + than to check for functions by name. */ + +static inline bool +maybe_special_function_p (const_tree fndecl) +{ + tree name_decl = DECL_NAME (fndecl); + if (name_decl + /* Exclude functions not at the file scope, or not `extern', + since they are not the magic functions we would otherwise + think they are. */ + && (DECL_CONTEXT (fndecl) == NULL_TREE + || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL) + && TREE_PUBLIC (fndecl)) + return true; + return false; +} + /* Return true if T (assumed to be a DECL) is a global variable. A variable is considered global if its storage is not automatic. */ |