public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4249] analyzer: only look for named functions in root ns [PR107788] Date: Tue, 22 Nov 2022 22:32:56 +0000 (GMT) [thread overview] Message-ID: <20221122223256.A8DD9385842D@sourceware.org> (raw) https://gcc.gnu.org/g:ec7c796de020cb5cd955aa5b26c92b1da49d6076 commit r13-4249-gec7c796de020cb5cd955aa5b26c92b1da49d6076 Author: David Malcolm <dmalcolm@redhat.com> Date: Tue Nov 22 17:29:21 2022 -0500 analyzer: only look for named functions in root ns [PR107788] gcc/analyzer/ChangeLog: PR analyzer/107788 * known-function-manager.cc (known_function_manager::get_match): Don't look up fndecls by name when they're not in the root namespace. gcc/testsuite/ChangeLog: PR analyzer/107788 * g++.dg/analyzer/named-functions.C: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com> Diff: --- gcc/analyzer/known-function-manager.cc | 15 ++++++++++++--- gcc/testsuite/g++.dg/analyzer/named-functions.C | 12 ++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gcc/analyzer/known-function-manager.cc b/gcc/analyzer/known-function-manager.cc index e17350da5ec..c1074bcb6e5 100644 --- a/gcc/analyzer/known-function-manager.cc +++ b/gcc/analyzer/known-function-manager.cc @@ -91,6 +91,7 @@ known_function_manager::add (enum internal_fn ifn, const known_function * known_function_manager::get_match (tree fndecl, const call_details &cd) const { + /* Look for a matching built-in. */ if (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)) { if (const known_function *candidate @@ -99,10 +100,18 @@ known_function_manager::get_match (tree fndecl, const call_details &cd) const fndecl)) return candidate; } + + /* Look for a match by name. */ + + /* Reject fndecls that aren't in the root namespace. */ + if (DECL_CONTEXT (fndecl) + && TREE_CODE (DECL_CONTEXT (fndecl)) != TRANSLATION_UNIT_DECL) + return NULL; if (tree identifier = DECL_NAME (fndecl)) - if (const known_function *candidate = get_by_identifier (identifier)) - if (candidate->matches_call_types_p (cd)) - return candidate; + if (const known_function *candidate = get_by_identifier (identifier)) + if (candidate->matches_call_types_p (cd)) + return candidate; + return NULL; } diff --git a/gcc/testsuite/g++.dg/analyzer/named-functions.C b/gcc/testsuite/g++.dg/analyzer/named-functions.C new file mode 100644 index 00000000000..661a9307b81 --- /dev/null +++ b/gcc/testsuite/g++.dg/analyzer/named-functions.C @@ -0,0 +1,12 @@ +#define NULL ((void *)0) + +namespace my +{ + int socket (int, int, int); +}; + +void test_my_socket () +{ + /* This shouldn't match the known function "::socket". */ + my::socket (0, 0, 0); /* { dg-bogus "leak" } */ +}
reply other threads:[~2022-11-22 22:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221122223256.A8DD9385842D@sourceware.org \ --to=dmalcolm@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).