* [committed] analyzer: only look for named functions in root ns [PR107788]
@ 2022-11-22 22:37 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-11-22 22:37 UTC (permalink / raw)
To: gcc-patches; +Cc: David Malcolm
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-4249-gec7c796de020cb.
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>
---
gcc/analyzer/known-function-manager.cc | 15 ++++++++++++---
gcc/testsuite/g++.dg/analyzer/named-functions.C | 12 ++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/analyzer/named-functions.C
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" } */
+}
--
2.26.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-22 22:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 22:37 [committed] analyzer: only look for named functions in root ns [PR107788] David Malcolm
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).