Skip to content

Commit 43704e2

Browse files
authored
Merge pull request #144 from ian-semmle/topLevel2
C++: Improve GlobalNamespace.getADeclaration()
2 parents 20ade48 + 3fd6a8d commit 43704e2

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-26
lines changed

cpp/ql/src/semmle/code/cpp/Namespace.qll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ class GlobalNamespace extends Namespace {
190190

191191
override Declaration getADeclaration() {
192192
suppressWarningForUnused(this) and
193-
not exists(DeclStmt d |
194-
d.getADeclaration() = result and
195-
not result instanceof Function
196-
) and
197-
not exists(ConditionDeclExpr cde | cde.getVariable() = result) and
198193
result.isTopLevel() and
199194
not namespacembrs(_, unresolveElement(result))
200195
}
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | __va_list_tag | __va_list_tag |
2-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | fp_offset | __va_list_tag::fp_offset |
3-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | gp_offset | __va_list_tag::gp_offset |
4-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= |
5-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= |
6-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area |
7-
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area |
8-
| file://:0:0:0:0 | B | namespaces.cpp:32:7:32:7 | x | B::x |
9-
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> |
10-
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> |
11-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:13:17:13:17 | f | C::D::f |
12-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | E | C::D::E |
13-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= |
14-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= |
15-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:12:17:12 | g | C::D::E::g |
16-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:18:17:18 | p | <none> |
17-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:18:12:18:12 | a | <none> |
18-
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:20:13:20:13 | b | <none> |
1+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | __va_list_tag | __va_list_tag | true |
2+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | fp_offset | __va_list_tag::fp_offset | false |
3+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | gp_offset | __va_list_tag::gp_offset | false |
4+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= | false |
5+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | operator= | __va_list_tag::operator= | false |
6+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | overflow_arg_area | __va_list_tag::overflow_arg_area | false |
7+
| file://:0:0:0:0 | (global namespace) | file://:0:0:0:0 | reg_save_area | __va_list_tag::reg_save_area | false |
8+
| file://:0:0:0:0 | (global namespace) | namespaces.cpp:40:5:40:13 | globalInt | globalInt | true |
9+
| file://:0:0:0:0 | (global namespace) | namespaces.cpp:42:6:42:18 | globalIntUser | globalIntUser | true |
10+
| file://:0:0:0:0 | <none> | file://:0:0:0:0 | auto | <none> | false |
11+
| file://:0:0:0:0 | B | namespaces.cpp:32:7:32:7 | x | B::x | true |
12+
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> | false |
13+
| namespaces.cpp:11:13:11:13 | C::D | file://:0:0:0:0 | p#0 | <none> | false |
14+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:13:17:13:17 | f | C::D::f | true |
15+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | E | C::D::E | true |
16+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= | false |
17+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:15:12:15:12 | operator= | C::D::E::operator= | false |
18+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:12:17:12 | g | C::D::E::g | false |
19+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:17:18:17:18 | p | <none> | false |
20+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:18:12:18:12 | a | <none> | false |
21+
| namespaces.cpp:11:13:11:13 | C::D | namespaces.cpp:20:13:20:13 | b | <none> | false |

cpp/ql/test/library-tests/namespaces/namespaces/decls.ql

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@ string qual(Declaration d) {
66
else result = "<none>"
77
}
88

9-
from Namespace n, Declaration d
10-
where n = d.getNamespace()
11-
select n, d, qual(d)
9+
newtype TMaybeNamespace = SomeNamespace(Namespace ns) or NoNamespace()
1210

11+
class MaybeNamespace extends TMaybeNamespace {
12+
string toString() {
13+
this = NoNamespace() and result = "<none>"
14+
or
15+
exists(Namespace ns | this = SomeNamespace(ns) and result = ns.toString())
16+
}
17+
18+
Location getLocation() {
19+
exists(Namespace ns |
20+
this = SomeNamespace(ns) and result = ns.getLocation())
21+
}
22+
}
23+
24+
from MaybeNamespace n, Declaration d
25+
where n = SomeNamespace(d.getNamespace())
26+
or n = NoNamespace() and not exists(d.getNamespace())
27+
select n, d,
28+
qual(d),
29+
any(boolean b | if d.isTopLevel() then b = true else b = false)

cpp/ql/test/library-tests/namespaces/namespaces/namespaces.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ namespace B {
3636
namespace std {
3737

3838
}
39+
40+
int globalInt;
41+
42+
void globalIntUser(void) {
43+
extern int globalInt;
44+
}

0 commit comments

Comments
 (0)