a bit more caching

This commit is contained in:
Erik Krogh Kristensen
2021-12-11 00:21:52 +01:00
parent 7643aac207
commit 79713e0ef8
3 changed files with 10 additions and 1 deletions

View File

@@ -140,6 +140,7 @@ module Stages {
private import semmle.python.Flow as Flow
private import semmle.python.objects.ObjectInternal as ObjectInternal
private import semmle.python.objects.ObjectAPI as ObjectAPI
private import semmle.python.pointsto.PointsTo as PointsTo
/**
* DONT USE!
@@ -166,6 +167,8 @@ module Stages {
exists(any(Flow::ControlFlowNode c).toString())
or
exists(any(ObjectInternal::ObjectInternal o).toString())
or
PointsTo::AttributePointsTo::variableAttributePointsTo(_, _, _, _, _)
}
}

View File

@@ -6,6 +6,7 @@ private import semmle.python.pointsto.PointsToContext
private import semmle.python.pointsto.MRO
private import semmle.python.types.Builtins
private import semmle.python.types.Extensions
private import semmle.python.internal.CachedStages
/* Use this version for speed */
class CfgOrigin extends @py_object {
@@ -2555,10 +2556,11 @@ module AttributePointsTo {
f.isLoad() and var.getASourceUse() = f.(AttrNode).getObject(name)
}
pragma[nomagic]
cached
predicate variableAttributePointsTo(
EssaVariable var, Context context, string name, ObjectInternal value, CfgOrigin origin
) {
Stages::DataFlow::ref() and
definitionAttributePointsTo(var.getDefinition(), context, name, value, origin)
or
exists(EssaVariable prev |

View File

@@ -75,9 +75,11 @@ class Object extends @py_object {
* For more information, see
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
*/
cached
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
Stages::DataFlow::ref() and
this.hasOrigin() and
this.getOrigin()
.getLocation()
@@ -95,7 +97,9 @@ class Object extends @py_object {
Builtin asBuiltin() { result = this }
/** Gets a textual representation of this element. */
cached
string toString() {
Stages::DataFlow::ref() and
not this = undefinedVariable() and
not this = unknownValue() and
exists(ClassObject type | type.asBuiltin() = this.asBuiltin().getClass() |