@@ -355,6 +355,13 @@ abstract class LibraryTypeDataFlow extends Type {
355355 * needed for a summary specified by `callableFlow()`.
356356 */
357357 predicate requiresAccessPath ( Content head , AccessPath tail ) { none ( ) }
358+
359+ pragma [ nomagic]
360+ predicate clearsContent (
361+ CallableFlowSource source , Content content , SourceDeclarationCallable callable
362+ ) {
363+ none ( )
364+ }
358365}
359366
360367/** Data flow for `System.Int32`. */
@@ -630,8 +637,8 @@ class SystemStringFlow extends LibraryTypeDataFlow, SystemStringClass {
630637/** Data flow for `System.Text.StringBuilder`. */
631638class SystemTextStringBuilderFlow extends LibraryTypeDataFlow , SystemTextStringBuilderClass {
632639 override predicate callableFlow (
633- CallableFlowSource source , AccessPath sourceAp , CallableFlowSink sink , AccessPath sinkAp , SourceDeclarationCallable c ,
634- boolean preservesValue
640+ CallableFlowSource source , AccessPath sourceAp , CallableFlowSink sink , AccessPath sinkAp ,
641+ SourceDeclarationCallable c , boolean preservesValue
635642 ) {
636643 (
637644 constructorFlow ( source , sourceAp , sink , sinkAp , c )
@@ -641,7 +648,10 @@ class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringB
641648 preservesValue = false
642649 }
643650
644- private predicate constructorFlow ( CallableFlowSource source , AccessPath sourceAp , CallableFlowSink sink , AccessPath sinkAp , Constructor c ) {
651+ private predicate constructorFlow (
652+ CallableFlowSource source , AccessPath sourceAp , CallableFlowSink sink , AccessPath sinkAp ,
653+ Constructor c
654+ ) {
645655 c = getAMember ( ) and
646656 c .getParameter ( 0 ) .getType ( ) instanceof StringType and
647657 source = TCallableFlowSourceArg ( 0 ) and
@@ -651,7 +661,8 @@ class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringB
651661 }
652662
653663 private predicate methodFlow (
654- CallableFlowSource source , AccessPath sourceAp , CallableFlowSink sink , AccessPath sinkAp , SourceDeclarationMethod m
664+ CallableFlowSource source , AccessPath sourceAp , CallableFlowSink sink , AccessPath sinkAp ,
665+ SourceDeclarationMethod m
655666 ) {
656667 exists ( string name | m = this .getAMethod ( name ) |
657668 name = "ToString" and
@@ -673,6 +684,18 @@ class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringB
673684 )
674685 )
675686 }
687+
688+ override predicate clearsContent (
689+ CallableFlowSource source , Content content , SourceDeclarationCallable callable
690+ ) {
691+ source = TCallableFlowSourceQualifier ( ) and
692+ callable = this .getAMethod ( "Clear" ) and
693+ (
694+ content instanceof ElementContent
695+ // or
696+ // content = this.getAMember().(FieldOrProperty).getContent()
697+ )
698+ }
676699}
677700
678701/** Data flow for `System.Lazy<>`. */
@@ -1279,6 +1302,18 @@ class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
12791302 name .regexpMatch ( "Find(All|Last)?" )
12801303 )
12811304 }
1305+
1306+ override predicate clearsContent (
1307+ CallableFlowSource source , Content content , SourceDeclarationCallable callable
1308+ ) {
1309+ source = TCallableFlowSourceQualifier ( ) and
1310+ callable = this .getAMethod ( "Clear" ) and
1311+ (
1312+ content instanceof ElementContent
1313+ // or
1314+ // content = this.getAMember().(FieldOrProperty).getContent()
1315+ )
1316+ }
12821317}
12831318
12841319/** Data flow for `System.Collections.[Generic.]ICollection` (and sub types). */
0 commit comments