@@ -27,7 +27,7 @@ private CallInstruction getTranslatedCallInstruction(Call call) {
2727 * of a higher-level constructor (e.g. the allocator call in a `NewExpr`).
2828 */
2929abstract class TranslatedCall extends TranslatedExpr {
30- final override TranslatedElement getChild ( int id ) {
30+ final override TranslatedElement getChildInternal ( int id ) {
3131 // We choose the child's id in the order of evaluation.
3232 // The qualifier is evaluated before the call target, because the value of
3333 // the call target may depend on the value of the qualifier for virtual
@@ -47,13 +47,19 @@ abstract class TranslatedCall extends TranslatedExpr {
4747 else result = this .getFirstCallTargetInstruction ( kind )
4848 }
4949
50+ override Instruction getALastInstructionInternal ( ) {
51+ result = this .getSideEffects ( ) .getALastInstruction ( )
52+ }
53+
54+ override TranslatedElement getLastChild ( ) { result = this .getSideEffects ( ) }
55+
5056 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
5157 tag = CallTag ( ) and
5258 opcode instanceof Opcode:: Call and
5359 resultType = getTypeForPRValue ( this .getCallResultType ( ) )
5460 }
5561
56- override Instruction getChildSuccessor ( TranslatedElement child , EdgeKind kind ) {
62+ override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
5763 child = this .getQualifier ( ) and
5864 result = this .getFirstCallTargetInstruction ( kind )
5965 or
@@ -87,7 +93,7 @@ abstract class TranslatedCall extends TranslatedExpr {
8793 )
8894 }
8995
90- override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
96+ override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
9197 tag = CallTag ( ) and
9298 result = this .getSideEffects ( ) .getFirstInstruction ( kind )
9399 }
@@ -225,7 +231,7 @@ abstract class TranslatedSideEffects extends TranslatedElement {
225231 )
226232 }
227233
228- final override Instruction getChildSuccessor ( TranslatedElement te , EdgeKind kind ) {
234+ final override Instruction getChildSuccessorInternal ( TranslatedElement te , EdgeKind kind ) {
229235 exists ( int i |
230236 this .getChild ( i ) = te and
231237 if exists ( this .getChild ( i + 1 ) )
@@ -234,6 +240,10 @@ abstract class TranslatedSideEffects extends TranslatedElement {
234240 )
235241 }
236242
243+ override TranslatedElement getLastChild ( ) {
244+ result = this .getChild ( max ( int i | exists ( this .getChild ( i ) ) ) )
245+ }
246+
237247 final override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
238248 none ( )
239249 }
@@ -246,7 +256,18 @@ abstract class TranslatedSideEffects extends TranslatedElement {
246256 result = this .getParent ( ) .getChildSuccessor ( this , kind )
247257 }
248258
249- final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) { none ( ) }
259+ override Instruction getALastInstructionInternal ( ) {
260+ if exists ( this .getAChild ( ) )
261+ then result = this .getChild ( max ( int i | exists ( this .getChild ( i ) ) ) ) .getALastInstruction ( )
262+ else
263+ // If there are no side effects, the "last" instruction should be the parent call's last
264+ // instruction, so that implicit destructors can be inserted in the right place.
265+ result = this .getParent ( ) .getInstruction ( CallTag ( ) )
266+ }
267+
268+ final override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
269+ none ( )
270+ }
250271
251272 /** Gets the primary instruction to be associated with each side effect instruction. */
252273 abstract Instruction getPrimaryInstruction ( ) ;
@@ -273,8 +294,8 @@ abstract class TranslatedDirectCall extends TranslatedCall {
273294 resultType = getFunctionGLValueType ( )
274295 }
275296
276- override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
277- result = TranslatedCall .super .getInstructionSuccessor ( tag , kind )
297+ override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
298+ result = TranslatedCall .super .getInstructionSuccessorInternal ( tag , kind )
278299 or
279300 tag = CallTargetTag ( ) and
280301 result = this .getFirstArgumentOrCallInstruction ( kind )
@@ -367,6 +388,16 @@ class TranslatedStructorCall extends TranslatedFunctionCall {
367388 context = this .getParent ( ) and
368389 result = context .getReceiver ( )
369390 )
391+ or
392+ exists ( Stmt parent |
393+ expr = parent .getAnImplicitDestructorCall ( ) and
394+ result = getTranslatedExpr ( expr .getQualifier ( ) .getFullyConverted ( ) ) .getResult ( )
395+ )
396+ or
397+ exists ( Expr parent |
398+ expr = parent .getAnImplicitDestructorCall ( ) and
399+ result = getTranslatedExpr ( expr .getQualifier ( ) .getFullyConverted ( ) ) .getResult ( )
400+ )
370401 }
371402
372403 override predicate hasQualifier ( ) { any ( ) }
@@ -416,19 +447,25 @@ private int initializeAllocationGroup() { result = 3 }
416447abstract class TranslatedSideEffect extends TranslatedElement {
417448 final override TranslatedElement getChild ( int n ) { none ( ) }
418449
419- final override Instruction getChildSuccessor ( TranslatedElement child , EdgeKind kind ) { none ( ) }
450+ final override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
451+ none ( )
452+ }
420453
421454 final override Instruction getFirstInstruction ( EdgeKind kind ) {
422455 result = this .getInstruction ( OnlyInstructionTag ( ) ) and
423456 kind instanceof GotoEdge
424457 }
425458
459+ override Instruction getALastInstructionInternal ( ) {
460+ result = this .getInstruction ( OnlyInstructionTag ( ) )
461+ }
462+
426463 final override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
427464 tag = OnlyInstructionTag ( ) and
428465 this .sideEffectInstruction ( opcode , type )
429466 }
430467
431- final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
468+ final override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
432469 result = this .getParent ( ) .getChildSuccessor ( this , kind ) and
433470 tag = OnlyInstructionTag ( )
434471 }
0 commit comments