mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
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.
This commit is contained in:
@@ -46,7 +46,7 @@ class Operand extends TStageOperand {
|
||||
/**
|
||||
* Gets the location of the source code for this operand.
|
||||
*/
|
||||
final Language::Location getLocation() { result = this.getUse().getLocation() }
|
||||
final Language::Location getLocation() { result = this.getAnyDef().getLocation() }
|
||||
|
||||
/**
|
||||
* Gets the function that contains this operand.
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
private import cpp
|
||||
|
||||
/**
|
||||
* Holds if an AST or IR with the specified location should be printed in the test output.
|
||||
*
|
||||
* This predicate excludes locations in standard headers.
|
||||
*/
|
||||
predicate shouldDump(Location loc) {
|
||||
not loc.getFile().getAbsolutePath().regexpMatch(".*/include/[^/]+")
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the AST or IR for the specified function should be printed in the test output.
|
||||
*
|
||||
* This predicate excludes functions defined in standard headers.
|
||||
*/
|
||||
predicate shouldDumpFunction(Function func) {
|
||||
not func.getLocation().getFile().getAbsolutePath().regexpMatch(".*/include/[^/]+")
|
||||
shouldDump(func.getLocation())
|
||||
}
|
||||
|
||||
7001
cpp/ql/test/library-tests/ir/ir/operand_locations.expected
Normal file
7001
cpp/ql/test/library-tests/ir/ir/operand_locations.expected
Normal file
File diff suppressed because it is too large
Load Diff
7
cpp/ql/test/library-tests/ir/ir/operand_locations.ql
Normal file
7
cpp/ql/test/library-tests/ir/ir/operand_locations.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
private import cpp
|
||||
private import semmle.code.cpp.ir.IR
|
||||
private import PrintConfig
|
||||
|
||||
from Operand a
|
||||
where shouldDump(a.getLocation())
|
||||
select a, a.getDumpString()
|
||||
Reference in New Issue
Block a user