Skip to content

Commit 9da580f

Browse files
committed
unified: Make accessors introduce LocalVariables too
1 parent 364e982 commit 9da580f

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ module Public {
409409
|
410410
decl instanceof VariableDeclaration or
411411
decl instanceof FunctionDeclaration or // treat functions as values
412+
decl instanceof AccessorDeclaration or
412413
decl instanceof Parameter or
413414
decl instanceof ForEachStmt or
414415
decl instanceof PatternGuardExpr or
@@ -446,6 +447,25 @@ module Public {
446447
}
447448
}
448449

450+
private AccessorDeclaration getAnAccessor(LocalVariable v) {
451+
v.getABinding() = result.getNameNode() and
452+
(result instanceof GetterDeclaration or result instanceof SetterDeclaration)
453+
}
454+
455+
/** A local variable defined by a getter/setter pair, which does not store a value on its own. */
456+
final class ComputedLocalVariable extends LocalVariable {
457+
ComputedLocalVariable() { exists(getAnAccessor(this)) }
458+
459+
/** Gets the getter or setter for this computed variable. */
460+
AccessorDeclaration getAnAccessor() { result = getAnAccessor(this) }
461+
462+
/** Gets the getter for this computed variable. */
463+
GetterDeclaration getGetterDeclaration() { result = getAnAccessor(this) }
464+
465+
/** Gets the setter for this computed variable. */
466+
SetterDeclaration getSetterDeclaration() { result = getAnAccessor(this) }
467+
}
468+
449469
/** An access to a locally-declared name. */
450470
class LocalNameAccess extends PotentialLocalNameAccess {
451471
LocalNameAccess() { not this instanceof UnqualifiedMemberAccess }

‎unified/ql/lib/codeql/unified/internal/dataflow/CaptureSsa.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module CaptureSsaInput implements InputSig<Location, BasicBlock> {
2121
Callable basicBlockGetEnclosingCallable(BasicBlock bb) { result = bb.getEnclosingCallable() }
2222

2323
class CapturedVariable extends LocalVariable {
24-
CapturedVariable() { this.isCaptured() }
24+
CapturedVariable() { this.isCaptured() and not this instanceof ComputedLocalVariable }
2525

2626
Callable getCallable() { result = super.getDeclaringCallable() }
2727
}

‎unified/ql/lib/codeql/unified/internal/dataflow/LocalSsa.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private import codeql.util.Void
1010

1111
module LocalSsaInput implements InputSig<Location, BasicBlock> {
1212
class SourceVariable extends LocalVariable {
13-
SourceVariable() { not this.isCaptured() }
13+
SourceVariable() { not this.isCaptured() and not this instanceof ComputedLocalVariable }
1414
}
1515

1616
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {

0 commit comments

Comments
 (0)