@@ -128,38 +128,35 @@ private predicate summaryModel(
128128}
129129
130130private predicate summaryModelRelevant (
131- Function f , string input , string output , string kind , Provenance provenance ,
131+ Function f , string input , string output , string kind , Provenance provenance , boolean isInherited ,
132132 QlBuiltins:: ExtensionId madId
133133) {
134- exists ( boolean isInherited |
135- summaryModel ( f , input , output , kind , provenance , isInherited , madId )
136- |
137- // Only apply generated or inherited models to functions in library code and
138- // when no strictly better model exists
139- if provenance .isGenerated ( ) or isInherited = true
140- then
141- not f .fromSource ( ) and
142- not exists ( Provenance other | summaryModel ( f , _, _, _, other , false , _) |
143- provenance .isGenerated ( ) and other .isManual ( )
144- or
145- provenance = other and isInherited = true
146- )
147- else any ( )
148- )
134+ summaryModel ( f , input , output , kind , provenance , isInherited , madId ) and
135+ // Only apply generated or inherited models to functions in library code and
136+ // when no strictly better model exists
137+ if provenance .isGenerated ( ) or isInherited = true
138+ then
139+ not f .fromSource ( ) and
140+ not exists ( Provenance other | summaryModel ( f , _, _, _, other , false , _) |
141+ provenance .isGenerated ( ) and other .isManual ( )
142+ or
143+ provenance = other and isInherited = true
144+ )
145+ else any ( )
149146}
150147
151148private class SummarizedCallableFromModel extends SummarizedCallable:: Range {
152- SummarizedCallableFromModel ( ) { summaryModelRelevant ( this , _, _, _, _, _) }
149+ SummarizedCallableFromModel ( ) { summaryModelRelevant ( this , _, _, _, _, _, _ ) }
153150
154151 override predicate hasProvenance ( Provenance provenance ) {
155- summaryModelRelevant ( this , _, _, _, provenance , _)
152+ summaryModelRelevant ( this , _, _, _, provenance , _, _ )
156153 }
157154
158155 override predicate propagatesFlow (
159156 string input , string output , boolean preservesValue , string model
160157 ) {
161158 exists ( string kind , QlBuiltins:: ExtensionId madId |
162- summaryModelRelevant ( this , input , output , kind , _, madId ) and
159+ summaryModelRelevant ( this , input , output , kind , _, _ , madId ) and
163160 model = "MaD:" + madId .toString ( )
164161 |
165162 kind = "value" and
@@ -202,3 +199,56 @@ private class FlowSinkFromModel extends FlowSink::Range {
202199 )
203200 }
204201}
202+
203+ private module Debug {
204+ private import FlowSummaryImpl
205+ private import Private
206+ private import Content
207+ private import codeql.rust.dataflow.internal.DataFlowImpl
208+ private import codeql.rust.internal.TypeMention
209+ private import codeql.rust.internal.Type
210+
211+ private predicate relevantManualModel ( SummarizedCallableImpl sc , string can ) {
212+ exists ( Provenance manual |
213+ can = sc .getCanonicalPath ( ) and
214+ summaryModelRelevant ( sc , _, _, _, manual , false , _) and
215+ manual .isManual ( )
216+ )
217+ }
218+
219+ predicate manualModelMissingParameterReference (
220+ SummarizedCallableImpl sc , string can , SummaryComponentStack input , ParamBase p
221+ ) {
222+ exists ( RustDataFlow:: ParameterPosition pos , TypeMention tm |
223+ relevantManualModel ( sc , can ) and
224+ sc .propagatesFlow ( input , _, _, _) and
225+ input .head ( ) = SummaryComponent:: argument ( pos ) and
226+ p = pos .getParameterIn ( sc .getParamList ( ) ) and
227+ tm .resolveType ( ) instanceof RefType and
228+ not input .tail ( ) .head ( ) = SummaryComponent:: content ( TSingletonContentSet ( TReferenceContent ( ) ) )
229+ |
230+ tm = p .getTypeRepr ( )
231+ or
232+ tm = getSelfParamTypeMention ( p )
233+ )
234+ }
235+
236+ predicate manualModelMissingReturnReference (
237+ SummarizedCallableImpl sc , string can , SummaryComponentStack output
238+ ) {
239+ exists ( TypeMention tm |
240+ relevantManualModel ( sc , can ) and
241+ sc .propagatesFlow ( _, output , _, _) and
242+ tm .resolveType ( ) instanceof RefType and
243+ output .head ( ) = SummaryComponent:: return ( _) and
244+ not output .tail ( ) .head ( ) =
245+ SummaryComponent:: content ( TSingletonContentSet ( TReferenceContent ( ) ) ) and
246+ tm = getReturnTypeMention ( sc ) and
247+ not can =
248+ [
249+ "<& as core::ops::deref::Deref>::deref" ,
250+ "<&mut as core::ops::deref::Deref>::deref"
251+ ]
252+ )
253+ }
254+ }
0 commit comments