From e0421dbf536230046c5ac20e502df469d47630f4 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Tue, 28 Apr 2026 13:38:14 +0200 Subject: [PATCH] C#: Reinstate toString for SSA data flow nodes. --- csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll | 14 -------------- .../code/csharp/dataflow/internal/SsaImpl.qll | 4 ++++ shared/ssa/codeql/ssa/Ssa.qll | 4 +++- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll index 4a7f774af07..c251a30b351 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll @@ -506,8 +506,6 @@ module Ssa { } override Element getElement() { result = ad.getElement() } - - override string toString() { result = "SSA def(" + this.getSourceVariable() + ")" } } /** @@ -551,12 +549,6 @@ module Ssa { final Callable getCallable() { result = this.getBasicBlock().getEnclosingCallable() } override Element getElement() { result = this.getCallable() } - - override string toString() { - if this.getSourceVariable().getAssignable() instanceof LocalScopeVariable - then result = "SSA capture def(" + this.getSourceVariable() + ")" - else result = "SSA entry def(" + this.getSourceVariable() + ")" - } } /** @@ -590,10 +582,6 @@ module Ssa { /** Gets the parameter that this entry definition represents. */ Parameter getParameter() { result = p } - - override string toString() { - result = "SSA param_default(" + pragma[only_bind_out](this.getParameter()) + ")" - } } /** @@ -687,8 +675,6 @@ module Ssa { predicate hasInputFromBlock(Definition inp, BasicBlock bb) { inp = SsaImpl::phiHasInputFromBlock(this, bb) } - - override string toString() { result = "SSA phi(" + this.getSourceVariable() + ")" } } /** diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll index 6db089928e0..218b8c97717 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll @@ -78,6 +78,10 @@ module Ssa_ = Impl::MakeSsa; class Definition = Impl::Definition; +private class SsaDefinitionToStringProxy extends Definition { + override string toString() { result = this.(SsaDefinition).toString() } +} + deprecated class WriteDefinition = Impl::WriteDefinition; deprecated class UncertainWriteDefinition = Impl::UncertainWriteDefinition; diff --git a/shared/ssa/codeql/ssa/Ssa.qll b/shared/ssa/codeql/ssa/Ssa.qll index 8d6b960b283..861f797ed6d 100644 --- a/shared/ssa/codeql/ssa/Ssa.qll +++ b/shared/ssa/codeql/ssa/Ssa.qll @@ -1054,7 +1054,7 @@ module Make< /** A static single assignment (SSA) definition. */ class SsaDefinition extends FinalDefinition { /** Gets a textual representation of this SSA definition. */ - string toString() { result = super.toString() } + string toString() { result = "SSA def(" + this.getSourceVariable() + ")" } /** * Gets the control flow node of this SSA definition. @@ -1207,6 +1207,8 @@ module Make< * a phi definition for `x` is inserted just before the call `puts x`. */ class SsaPhiDefinition extends SsaDefinition instanceof PhiNode { + override string toString() { result = "SSA phi(" + this.getSourceVariable() + ")" } + /** Holds if `inp` is an input to this phi definition along the edge originating in `bb`. */ predicate hasInputFromBlock(SsaDefinition inp, BasicBlock bb) { phiHasInputFromBlockCached(this, inp, bb)