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>
This commit is contained in:
parent
64fb291c58
commit
ec7c796de0
2 changed files with 24 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
12
gcc/testsuite/g++.dg/analyzer/named-functions.C
Normal file
12
gcc/testsuite/g++.dg/analyzer/named-functions.C
Normal file
|
@ -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" } */
|
||||
}
|
Loading…
Add table
Reference in a new issue