@@ -27,7 +27,7 @@ private CallInstruction getTranslatedCallInstruction(Call call) {
27
27
* of a higher-level constructor (e.g. the allocator call in a `NewExpr`).
28
28
*/
29
29
abstract class TranslatedCall extends TranslatedExpr {
30
- final override TranslatedElement getChild ( int id ) {
30
+ final override TranslatedElement getChildInternal ( int id ) {
31
31
// We choose the child's id in the order of evaluation.
32
32
// The qualifier is evaluated before the call target, because the value of
33
33
// the call target may depend on the value of the qualifier for virtual
@@ -47,13 +47,19 @@ abstract class TranslatedCall extends TranslatedExpr {
47
47
else result = this .getFirstCallTargetInstruction ( kind )
48
48
}
49
49
50
+ override Instruction getALastInstructionInternal ( ) {
51
+ result = this .getSideEffects ( ) .getALastInstruction ( )
52
+ }
53
+
54
+ override TranslatedElement getLastChild ( ) { result = this .getSideEffects ( ) }
55
+
50
56
override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
51
57
tag = CallTag ( ) and
52
58
opcode instanceof Opcode:: Call and
53
59
resultType = getTypeForPRValue ( this .getCallResultType ( ) )
54
60
}
55
61
56
- override Instruction getChildSuccessor ( TranslatedElement child , EdgeKind kind ) {
62
+ override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
57
63
child = this .getQualifier ( ) and
58
64
result = this .getFirstCallTargetInstruction ( kind )
59
65
or
@@ -87,7 +93,7 @@ abstract class TranslatedCall extends TranslatedExpr {
87
93
)
88
94
}
89
95
90
- override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
96
+ override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
91
97
tag = CallTag ( ) and
92
98
result = this .getSideEffects ( ) .getFirstInstruction ( kind )
93
99
}
@@ -225,7 +231,7 @@ abstract class TranslatedSideEffects extends TranslatedElement {
225
231
)
226
232
}
227
233
228
- final override Instruction getChildSuccessor ( TranslatedElement te , EdgeKind kind ) {
234
+ final override Instruction getChildSuccessorInternal ( TranslatedElement te , EdgeKind kind ) {
229
235
exists ( int i |
230
236
this .getChild ( i ) = te and
231
237
if exists ( this .getChild ( i + 1 ) )
@@ -234,6 +240,10 @@ abstract class TranslatedSideEffects extends TranslatedElement {
234
240
)
235
241
}
236
242
243
+ override TranslatedElement getLastChild ( ) {
244
+ result = this .getChild ( max ( int i | exists ( this .getChild ( i ) ) ) )
245
+ }
246
+
237
247
final override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
238
248
none ( )
239
249
}
@@ -246,7 +256,18 @@ abstract class TranslatedSideEffects extends TranslatedElement {
246
256
result = this .getParent ( ) .getChildSuccessor ( this , kind )
247
257
}
248
258
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
+ }
250
271
251
272
/** Gets the primary instruction to be associated with each side effect instruction. */
252
273
abstract Instruction getPrimaryInstruction ( ) ;
@@ -273,8 +294,8 @@ abstract class TranslatedDirectCall extends TranslatedCall {
273
294
resultType = getFunctionGLValueType ( )
274
295
}
275
296
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 )
278
299
or
279
300
tag = CallTargetTag ( ) and
280
301
result = this .getFirstArgumentOrCallInstruction ( kind )
@@ -367,6 +388,16 @@ class TranslatedStructorCall extends TranslatedFunctionCall {
367
388
context = this .getParent ( ) and
368
389
result = context .getReceiver ( )
369
390
)
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
+ )
370
401
}
371
402
372
403
override predicate hasQualifier ( ) { any ( ) }
@@ -416,19 +447,25 @@ private int initializeAllocationGroup() { result = 3 }
416
447
abstract class TranslatedSideEffect extends TranslatedElement {
417
448
final override TranslatedElement getChild ( int n ) { none ( ) }
418
449
419
- final override Instruction getChildSuccessor ( TranslatedElement child , EdgeKind kind ) { none ( ) }
450
+ final override Instruction getChildSuccessorInternal ( TranslatedElement child , EdgeKind kind ) {
451
+ none ( )
452
+ }
420
453
421
454
final override Instruction getFirstInstruction ( EdgeKind kind ) {
422
455
result = this .getInstruction ( OnlyInstructionTag ( ) ) and
423
456
kind instanceof GotoEdge
424
457
}
425
458
459
+ override Instruction getALastInstructionInternal ( ) {
460
+ result = this .getInstruction ( OnlyInstructionTag ( ) )
461
+ }
462
+
426
463
final override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
427
464
tag = OnlyInstructionTag ( ) and
428
465
this .sideEffectInstruction ( opcode , type )
429
466
}
430
467
431
- final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
468
+ final override Instruction getInstructionSuccessorInternal ( InstructionTag tag , EdgeKind kind ) {
432
469
result = this .getParent ( ) .getChildSuccessor ( this , kind ) and
433
470
tag = OnlyInstructionTag ( )
434
471
}
0 commit comments