Skip to content

Commit 74c0197

Browse files
authored
C++: take IR Operand locations from definitions
Previously Operand's getLocation would take it from the Operand use. This lead to slightly confusing query results, where for example an issue related to a call argument would highlight the function part of the call instead of the parameter.
1 parent 83d204d commit 74c0197

File tree

4 files changed

+7019
-2
lines changed

4 files changed

+7019
-2
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/Operand.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Operand extends TStageOperand {
4646
/**
4747
* Gets the location of the source code for this operand.
4848
*/
49-
final Language::Location getLocation() { result = this.getUse().getLocation() }
49+
final Language::Location getLocation() { result = this.getAnyDef().getLocation() }
5050

5151
/**
5252
* Gets the function that contains this operand.
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
private import cpp
22

3+
/**
4+
* Holds if an AST or IR with the specified location should be printed in the test output.
5+
*
6+
* This predicate excludes locations in standard headers.
7+
*/
8+
predicate shouldDump(Location loc) {
9+
not loc.getFile().getAbsolutePath().regexpMatch(".*/include/[^/]+")
10+
}
11+
312
/**
413
* Holds if the AST or IR for the specified function should be printed in the test output.
514
*
615
* This predicate excludes functions defined in standard headers.
716
*/
817
predicate shouldDumpFunction(Function func) {
9-
not func.getLocation().getFile().getAbsolutePath().regexpMatch(".*/include/[^/]+")
18+
shouldDump(func.getLocation())
1019
}

0 commit comments

Comments
 (0)