Skip to content

Commit 60f3ff8

Browse files
committed
C#: Introduce type for Synthetic fields.
1 parent b49ca6a commit 60f3ff8

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ private module Cached {
759759
newtype TContent =
760760
TFieldContent(Field f) { f.isUnboundDeclaration() } or
761761
TPropertyContent(Property p) { p.isUnboundDeclaration() } or
762-
TElementContent()
762+
TElementContent() or
763+
TSyntheticFieldContent(SyntheticField f)
763764

764765
pragma[nomagic]
765766
private predicate commonSubTypeGeneral(DataFlowTypeOrUnifiable t1, RelevantDataFlowType t2) {
@@ -2038,3 +2039,10 @@ predicate additionalLambdaFlowStep(Node nodeFrom, Node nodeTo, boolean preserves
20382039
predicate allowParameterReturnInSelf(ParameterNode p) {
20392040
FlowSummaryImpl::Private::summaryAllowParameterReturnInSelf(p)
20402041
}
2042+
2043+
abstract class SyntheticField extends string {
2044+
bindingset[this]
2045+
SyntheticField() { any() }
2046+
2047+
Type getType() { result instanceof ObjectType }
2048+
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPublic.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ class FieldContent extends Content, TFieldContent {
224224
deprecated override Gvn::GvnType getType() { result = Gvn::getGlobalValueNumber(f.getType()) }
225225
}
226226

227+
class SyntheticFieldContent extends Content, TSyntheticFieldContent {
228+
private SyntheticField f;
229+
230+
SyntheticFieldContent() { this = TSyntheticFieldContent(f) }
231+
232+
SyntheticField getField() { result = f }
233+
234+
override string toString() { result = "synthetic " + f.toString() }
235+
}
236+
227237
/** A reference to a property. */
228238
class PropertyContent extends Content, TPropertyContent {
229239
private Property p;

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ DataFlowType getContentType(Content c) {
2929
or
3030
t = c.(PropertyContent).getProperty().getType()
3131
or
32+
t = c.(SyntheticFieldContent).getField().getType()
33+
or
3234
c instanceof ElementContent and
3335
t instanceof ObjectType // we don't know what the actual element type is
3436
)

0 commit comments

Comments
 (0)