CodeQL library for C#
codeql/csharp-all 6.0.2 (changelog, source)
Search

Predicate Ssa::ssaGetAFirstUse

Gets a read of the source variable underlying the SSA definition def that can be reached from def without passing through any other SSA definition or read. Example:

int Field;

void SetField(int i) {
  this.Field = i;
  Use(this.Field);
  if (i > 0)
    this.Field = i - 1;
  else if (i < 0)
    SetField(1);
  Use(this.Field);
  Use(this.Field);
}
  • The read of i on line 4 can be reached from the explicit SSA definition (wrapping an implicit entry definition) on line 3.
  • The reads of i on lines 6 and 7 are not the first reads of any SSA definition.
  • The read of this.Field on line 5 can be reached from the explicit SSA definition on line 4.
  • The read of this.Field on line 10 can be reached from the phi node between lines 9 and 10.
  • The read of this.Field on line 11 is not the first read of any SSA definition.

Subsequent reads can be found by following the steps defined by AssignableRead.getANextRead().

Import path

import csharp
AssignableRead ssaGetAFirstUse(SsaDefinition def)