@@ -161,6 +161,16 @@ private module Input2 implements Impl::Private::InputSig2 {
161161 )
162162 }
163163
164+ private MemberFunction getFunctionFromType ( Expr e ) {
165+ result .getClassAndName ( "operator()" ) .getADerivedClass * ( ) = e .getUnspecifiedType ( )
166+ }
167+
168+ private Function getFunctionFromExpr ( Expr e ) {
169+ result = e .( FunctionAccess ) .getTarget ( )
170+ or
171+ result = e .( ConversionCall ) .getQualifier ( ) .( LambdaExpression ) .getLambdaFunction ( )
172+ }
173+
164174 class SourceSinkReportingElement extends Element {
165175 SourceSinkReportingElement ( ) { this instanceof Expr or this instanceof Parameter }
166176
@@ -169,29 +179,29 @@ private module Input2 implements Impl::Private::InputSig2 {
169179 [ this .( Expr ) .getEnclosingFunction ( ) , this .( Parameter ) .getFunction ( ) ]
170180 }
171181
172- /**
173- * Gets the member function corresponding to an overloaded `operator()` when this element is
174- * invoked.
175- */
176- private MemberFunction getOperatorCallFunction ( ) {
177- // An `operator()` on a struct
178- result .getClassAndName ( "operator()" ) .getADerivedClass * ( ) = this .( Expr ) .getUnspecifiedType ( )
179- or
180- // A lambda that has undergone "lambda to function-pointer conversion"
181- result = this .( ConversionCall ) .getQualifier ( ) .( LambdaExpression ) .getLambdaFunction ( )
182- }
183-
184182 /** Gets the function invoked when this element is used as a callback. */
185- private Function getCallbackFunction ( ) {
186- // Taking the address of a function
187- result = this . ( FunctionAccess ) . getTarget ( )
183+ private Function getCallable ( ) {
184+ // The expression is a struct which implements `operator()`.
185+ result = getFunctionFromType ( this )
188186 or
189- // Passing an object with an overloaded `operator()`
190- result = this .getOperatorCallFunction ( )
187+ // The expression is a function pointer
188+ result = getFunctionFromExpr ( this )
189+ or
190+ // The expression is an SSA read of an assignment of a callable
191+ exists ( Ssa:: Definition def |
192+ def .getAUse ( ) .getDef ( ) .getUnconvertedResultExpression ( ) = this and
193+ result =
194+ getFunctionFromExpr ( def .getAnUltimateDefinition ( )
195+ .( Ssa:: DirectExplicitDefinition )
196+ .getAssignedInstruction ( )
197+ .( StoreInstruction )
198+ .getSourceValue ( )
199+ .getUnconvertedResultExpression ( ) )
200+ )
191201 }
192202
193203 SourceSinkReportingElement getASuccessor ( Impl:: Private:: SummaryComponent sc ) {
194- exists ( Function f | f = this .getCallbackFunction ( ) |
204+ exists ( Function f | f = this .getCallable ( ) |
195205 exists ( ParameterPosition pos | sc = Impl:: Private:: SummaryComponent:: parameter ( pos ) |
196206 result = pos .getParameter ( f )
197207 )
0 commit comments