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:
Paolo Tranquilli
2021-11-19 13:39:40 +00:00
committed by GitHub
parent 83d204d7a8
commit 74c0197544
4 changed files with 7019 additions and 2 deletions

View File

@@ -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.

View File

@@ -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())
}

File diff suppressed because it is too large Load Diff

View 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()