Skip to content

Commit 2283eac

Browse files
committed
C++: Fix bad join in 'definitionOf'.
1 parent 3b15f23 commit 2283eac

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

cpp/ql/lib/definitions.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ private predicate constructorCallTypeMention(ConstructorCall cc, TypeMention tm)
123123
)
124124
}
125125

126+
/** Holds if `loc` has the container `container` and is on the line starting at `startLine`. */
127+
pragma[nomagic]
128+
private predicate hasContainerAndStartLine(Location loc, Container container, int startLine) {
129+
loc.getStartLine() = startLine and
130+
loc.getContainer() = container
131+
}
132+
126133
/**
127134
* Gets an element, of kind `kind`, that element `e` uses, if any.
128135
* Attention: This predicate yields multiple definitions for a single location.
@@ -184,11 +191,9 @@ Top definitionOf(Top e, string kind) {
184191
kind = "I" and
185192
result = e.(Include).getIncludedFile() and
186193
// exclude `#include` directives containing macros
187-
not exists(MacroInvocation mi, Location l1, Location l2 |
188-
l1 = e.(Include).getLocation() and
189-
l2 = mi.getLocation() and
190-
l1.getContainer() = l2.getContainer() and
191-
l1.getStartLine() = l2.getStartLine()
194+
not exists(MacroInvocation mi, Container container, int startLine |
195+
hasContainerAndStartLine(e.(Include).getLocation(), container, startLine) and
196+
hasContainerAndStartLine(mi.getLocation(), container, startLine)
192197
// (an #include directive must be always on it's own line)
193198
)
194199
) and

cpp/ql/lib/semmle/code/cpp/Location.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import semmle.code.cpp.File
1010
*/
1111
class Location extends @location {
1212
/** Gets the container corresponding to this location. */
13+
pragma[nomagic]
1314
Container getContainer() { this.fullLocationInfo(result, _, _, _, _) }
1415

1516
/** Gets the file corresponding to this location, if any. */
1617
File getFile() { result = this.getContainer() }
1718

1819
/** Gets the 1-based line number (inclusive) where this location starts. */
20+
pragma[nomagic]
1921
int getStartLine() { this.fullLocationInfo(_, result, _, _, _) }
2022

2123
/** Gets the 1-based column number (inclusive) where this location starts. */

0 commit comments

Comments
 (0)