@@ -89,10 +89,10 @@ module MustFlow {
8989
9090 /** Holds if `nodeFrom` flows to `nodeTo`. */
9191 private predicate step ( Instruction nodeFrom , Instruction nodeTo ) {
92- Cached:: localStep ( pragma [ only_bind_into ] ( nodeFrom ) , pragma [ only_bind_into ] ( nodeTo ) )
92+ Cached:: localStep ( nodeFrom , nodeTo )
9393 or
9494 allowInterproceduralFlow ( ) and
95- Cached:: flowThroughCallable ( pragma [ only_bind_into ] ( nodeFrom ) , pragma [ only_bind_into ] ( nodeTo ) )
95+ Cached:: flowThroughCallable ( nodeFrom , nodeTo )
9696 or
9797 isAdditionalFlowStep ( nodeFrom .getAUse ( ) , nodeTo )
9898 }
@@ -145,134 +145,133 @@ module MustFlow {
145145 }
146146 }
147147 }
148+ }
148149
149- cached
150- private module Cached {
151- /** Holds if `p` is the `n`'th parameter of the non-virtual function `f`. */
152- private predicate parameterOf ( Parameter p , Function f , int n ) {
153- not f .isVirtual ( ) and f .getParameter ( n ) = p
154- }
150+ cached
151+ private module Cached {
152+ /** Holds if `p` is the `n`'th parameter of the non-virtual function `f`. */
153+ private predicate parameterOf ( Parameter p , Function f , int n ) {
154+ not f .isVirtual ( ) and f .getParameter ( n ) = p
155+ }
155156
156- /**
157- * Holds if `instr` is the `n`'th argument to a call to the non-virtual function `f`, and
158- * `init` is the corresponding initialization instruction that receives the value of `instr` in `f`.
159- */
160- private predicate flowIntoParameter (
161- Function f , int n , CallInstruction call , Instruction instr ,
162- InitializeParameterInstruction init
163- ) {
164- not f .isVirtual ( ) and
165- call .getPositionalArgument ( n ) = instr and
166- f = call .getStaticCallTarget ( ) and
167- isEnclosingNonVirtualFunctionInitializeParameter ( init , f ) and
168- init .getParameter ( ) .getIndex ( ) = pragma [ only_bind_into ] ( pragma [ only_bind_out ] ( n ) )
169- }
157+ /**
158+ * Holds if `instr` is the `n`'th argument to a call to the non-virtual function `f`, and
159+ * `init` is the corresponding initialization instruction that receives the value of `instr` in `f`.
160+ */
161+ private predicate flowIntoParameter (
162+ Function f , int n , CallInstruction call , Instruction instr , InitializeParameterInstruction init
163+ ) {
164+ not f .isVirtual ( ) and
165+ call .getPositionalArgument ( n ) = instr and
166+ f = call .getStaticCallTarget ( ) and
167+ isEnclosingNonVirtualFunctionInitializeParameter ( init , f ) and
168+ init .getParameter ( ) .getIndex ( ) = pragma [ only_bind_into ] ( pragma [ only_bind_out ] ( n ) )
169+ }
170170
171- /**
172- * Holds if `instr` is an argument to a call to the function `f`, and `init` is the
173- * corresponding initialization instruction that receives the value of `instr` in `f`.
174- */
175- pragma [ noinline]
176- private predicate isPositionalArgumentInitParam (
177- CallInstruction call , Instruction instr , InitializeParameterInstruction init , Function f
178- ) {
179- exists ( int n |
180- parameterOf ( _, f , n ) and
181- flowIntoParameter ( f , pragma [ only_bind_into ] ( pragma [ only_bind_out ] ( n ) ) , call , instr , init )
182- )
183- }
171+ /**
172+ * Holds if `instr` is an argument to a call to the function `f`, and `init` is the
173+ * corresponding initialization instruction that receives the value of `instr` in `f`.
174+ */
175+ pragma [ noinline]
176+ private predicate isPositionalArgumentInitParam (
177+ CallInstruction call , Instruction instr , InitializeParameterInstruction init , Function f
178+ ) {
179+ exists ( int n |
180+ parameterOf ( _, f , n ) and
181+ flowIntoParameter ( f , pragma [ only_bind_into ] ( pragma [ only_bind_out ] ( n ) ) , call , instr , init )
182+ )
183+ }
184184
185- /**
186- * Holds if `instr` is the qualifier to a call to the non-virtual function `f`, and
187- * `init` is the corresponding initialization instruction that receives the value of
188- * `instr` in `f`.
189- */
190- pragma [ noinline]
191- private predicate isThisArgumentInitParam (
192- CallInstruction call , Instruction instr , InitializeParameterInstruction init , Function f
193- ) {
194- not f .isVirtual ( ) and
195- call .getStaticCallTarget ( ) = f and
196- isEnclosingNonVirtualFunctionInitializeParameter ( init , f ) and
197- call .getThisArgument ( ) = instr and
198- init .getIRVariable ( ) instanceof IRThisVariable
199- }
185+ /**
186+ * Holds if `instr` is the qualifier to a call to the non-virtual function `f`, and
187+ * `init` is the corresponding initialization instruction that receives the value of
188+ * `instr` in `f`.
189+ */
190+ pragma [ noinline]
191+ private predicate isThisArgumentInitParam (
192+ CallInstruction call , Instruction instr , InitializeParameterInstruction init , Function f
193+ ) {
194+ not f .isVirtual ( ) and
195+ call .getStaticCallTarget ( ) = f and
196+ isEnclosingNonVirtualFunctionInitializeParameter ( init , f ) and
197+ call .getThisArgument ( ) = instr and
198+ init .getIRVariable ( ) instanceof IRThisVariable
199+ }
200200
201- /** Holds if `f` is the enclosing non-virtual function of `init`. */
202- private predicate isEnclosingNonVirtualFunctionInitializeParameter (
203- InitializeParameterInstruction init , Function f
204- ) {
205- not f .isVirtual ( ) and
206- init .getEnclosingFunction ( ) = f
207- }
201+ /** Holds if `f` is the enclosing non-virtual function of `init`. */
202+ private predicate isEnclosingNonVirtualFunctionInitializeParameter (
203+ InitializeParameterInstruction init , Function f
204+ ) {
205+ not f .isVirtual ( ) and
206+ init .getEnclosingFunction ( ) = f
207+ }
208208
209- /** Holds if `f` is the enclosing non-virtual function of `init`. */
210- private predicate isEnclosingNonVirtualFunctionInitializeIndirection (
211- InitializeIndirectionInstruction init , Function f
212- ) {
213- not f .isVirtual ( ) and
214- init .getEnclosingFunction ( ) = f
215- }
209+ /** Holds if `f` is the enclosing non-virtual function of `init`. */
210+ private predicate isEnclosingNonVirtualFunctionInitializeIndirection (
211+ InitializeIndirectionInstruction init , Function f
212+ ) {
213+ not f .isVirtual ( ) and
214+ init .getEnclosingFunction ( ) = f
215+ }
216216
217- /**
218- * Holds if `argument` is an argument (or argument indirection) to a call, and
219- * `parameter` is the corresponding initialization instruction in the call target.
220- */
221- cached
222- predicate flowThroughCallable ( Instruction argument , Instruction parameter ) {
223- // Flow from an argument to a parameter
224- exists ( CallInstruction call , InitializeParameterInstruction init | init = parameter |
225- isPositionalArgumentInitParam ( call , argument , init , call .getStaticCallTarget ( ) )
226- or
227- isThisArgumentInitParam ( call , argument , init , call .getStaticCallTarget ( ) )
228- )
217+ /**
218+ * Holds if `argument` is an argument (or argument indirection) to a call, and
219+ * `parameter` is the corresponding initialization instruction in the call target.
220+ */
221+ cached
222+ predicate flowThroughCallable ( Instruction argument , Instruction parameter ) {
223+ // Flow from an argument to a parameter
224+ exists ( CallInstruction call , InitializeParameterInstruction init | init = parameter |
225+ isPositionalArgumentInitParam ( call , argument , init , call .getStaticCallTarget ( ) )
229226 or
230- // Flow from argument indirection to parameter indirection
231- exists (
232- CallInstruction call , ReadSideEffectInstruction read , InitializeIndirectionInstruction init
233- |
234- init = parameter and
235- read .getPrimaryInstruction ( ) = call and
236- isEnclosingNonVirtualFunctionInitializeIndirection ( init , call .getStaticCallTarget ( ) )
237- |
238- exists ( int n |
239- read .getSideEffectOperand ( ) .getAnyDef ( ) = argument and
240- read .getIndex ( ) = pragma [ only_bind_into ] ( n ) and
241- init .getParameter ( ) .getIndex ( ) = pragma [ only_bind_into ] ( n )
242- )
243- or
244- call .getThisArgument ( ) = argument and
245- init .getIRVariable ( ) instanceof IRThisVariable
227+ isThisArgumentInitParam ( call , argument , init , call .getStaticCallTarget ( ) )
228+ )
229+ or
230+ // Flow from argument indirection to parameter indirection
231+ exists (
232+ CallInstruction call , ReadSideEffectInstruction read , InitializeIndirectionInstruction init
233+ |
234+ init = parameter and
235+ read .getPrimaryInstruction ( ) = call and
236+ isEnclosingNonVirtualFunctionInitializeIndirection ( init , call .getStaticCallTarget ( ) )
237+ |
238+ exists ( int n |
239+ read .getSideEffectOperand ( ) .getAnyDef ( ) = argument and
240+ read .getIndex ( ) = pragma [ only_bind_into ] ( n ) and
241+ init .getParameter ( ) .getIndex ( ) = pragma [ only_bind_into ] ( n )
246242 )
247- }
243+ or
244+ call .getThisArgument ( ) = argument and
245+ init .getIRVariable ( ) instanceof IRThisVariable
246+ )
247+ }
248248
249- private predicate instructionToOperandStep ( Instruction instr , Operand operand ) {
250- operand .getDef ( ) = instr
251- }
249+ private predicate instructionToOperandStep ( Instruction instr , Operand operand ) {
250+ operand .getDef ( ) = instr
251+ }
252252
253- /**
254- * Holds if data flows from `operand` to `instr`.
255- *
256- * This predicate ignores flow through `PhiInstruction`s to create a 'must flow' relation.
257- */
258- private predicate operandToInstructionStep ( Operand operand , Instruction instr ) {
259- instr .( CopyInstruction ) .getSourceValueOperand ( ) = operand
260- or
261- instr .( ConvertInstruction ) .getUnaryOperand ( ) = operand
262- or
263- instr .( CheckedConvertOrNullInstruction ) .getUnaryOperand ( ) = operand
264- or
265- instr .( InheritanceConversionInstruction ) .getUnaryOperand ( ) = operand
266- or
267- instr .( ChiInstruction ) .getTotalOperand ( ) = operand
268- }
253+ /**
254+ * Holds if data flows from `operand` to `instr`.
255+ *
256+ * This predicate ignores flow through `PhiInstruction`s to create a 'must flow' relation.
257+ */
258+ private predicate operandToInstructionStep ( Operand operand , Instruction instr ) {
259+ instr .( CopyInstruction ) .getSourceValueOperand ( ) = operand
260+ or
261+ instr .( ConvertInstruction ) .getUnaryOperand ( ) = operand
262+ or
263+ instr .( CheckedConvertOrNullInstruction ) .getUnaryOperand ( ) = operand
264+ or
265+ instr .( InheritanceConversionInstruction ) .getUnaryOperand ( ) = operand
266+ or
267+ instr .( ChiInstruction ) .getTotalOperand ( ) = operand
268+ }
269269
270- cached
271- predicate localStep ( Instruction nodeFrom , Instruction nodeTo ) {
272- exists ( Operand mid |
273- instructionToOperandStep ( nodeFrom , mid ) and
274- operandToInstructionStep ( mid , nodeTo )
275- )
276- }
270+ cached
271+ predicate localStep ( Instruction nodeFrom , Instruction nodeTo ) {
272+ exists ( Operand mid |
273+ instructionToOperandStep ( nodeFrom , mid ) and
274+ operandToInstructionStep ( mid , nodeTo )
275+ )
277276 }
278277}
0 commit comments