@@ -206,7 +206,44 @@ abstract class TranslatedCall extends TranslatedExpr {
206206
207207 predicate hasPreciseSideEffect ( ) { exists ( getSideEffects ( ) ) }
208208
209- TranslatedSideEffects getSideEffects ( ) { result .getCall ( ) = expr }
209+ final TranslatedSideEffects getSideEffects ( ) { result .getExpr ( ) = expr }
210+ }
211+
212+ abstract class TranslatedSideEffects extends TranslatedElement {
213+ abstract Expr getExpr ( ) ;
214+
215+ final override Locatable getAST ( ) { result = getExpr ( ) }
216+
217+ final override Function getFunction ( ) { result = getExpr ( ) .getEnclosingFunction ( ) }
218+
219+ override TranslatedElement getChild ( int i ) {
220+ result =
221+ rank [ i + 1 ] ( TranslatedSideEffect tse , int isWrite , int index |
222+ (
223+ tse .getCall ( ) = getExpr ( ) and
224+ tse .getArgumentIndex ( ) = index and
225+ if tse .isWrite ( ) then isWrite = 1 else isWrite = 0
226+ )
227+ |
228+ tse order by isWrite , index
229+ )
230+ }
231+
232+ final override Instruction getChildSuccessor ( TranslatedElement te ) {
233+ exists ( int i |
234+ getChild ( i ) = te and
235+ if exists ( getChild ( i + 1 ) )
236+ then result = getChild ( i + 1 ) .getFirstInstruction ( )
237+ else result = getParent ( ) .getChildSuccessor ( this )
238+ )
239+ }
240+
241+ /**
242+ * Gets the `TranslatedFunction` containing this expression.
243+ */
244+ final TranslatedFunction getEnclosingFunction ( ) {
245+ result = getTranslatedFunction ( getExpr ( ) .getEnclosingFunction ( ) )
246+ }
210247}
211248
212249/**
@@ -308,66 +345,27 @@ class TranslatedStructorCall extends TranslatedFunctionCall {
308345 override predicate hasQualifier ( ) { any ( ) }
309346}
310347
311- class TranslatedSideEffects extends TranslatedElement , TTranslatedSideEffects {
312- Call expr ;
313-
314- TranslatedSideEffects ( ) { this = TTranslatedSideEffects ( expr ) }
348+ class TranslatedAllocationSideEffects extends TranslatedSideEffects ,
349+ TTranslatedAllocationSideEffects {
350+ AllocationExpr expr ;
315351
316- override string toString ( ) { result = "(side effects for " + expr . toString ( ) + ")" }
352+ TranslatedAllocationSideEffects ( ) { this = TTranslatedAllocationSideEffects ( expr ) }
317353
318- override Locatable getAST ( ) { result = expr }
354+ final override AllocationExpr getExpr ( ) { result = expr }
319355
320- Call getCall ( ) { result = expr }
356+ override string toString ( ) { result = "(allocation side effects for " + expr . toString ( ) + ")" }
321357
322- override TranslatedElement getChild ( int i ) {
323- result =
324- rank [ i + 1 ] ( TranslatedSideEffect tse , int isWrite , int index |
325- (
326- tse .getCall ( ) = getCall ( ) and
327- tse .getArgumentIndex ( ) = index and
328- if tse .isWrite ( ) then isWrite = 1 else isWrite = 0
329- )
330- |
331- tse order by isWrite , index
332- )
333- }
334-
335- override Instruction getChildSuccessor ( TranslatedElement te ) {
336- exists ( int i |
337- getChild ( i ) = te and
338- if exists ( getChild ( i + 1 ) )
339- then result = getChild ( i + 1 ) .getFirstInstruction ( )
340- else result = getParent ( ) .getChildSuccessor ( this )
341- )
342- }
358+ override Instruction getFirstInstruction ( ) { result = getInstruction ( OnlyInstructionTag ( ) ) }
343359
344360 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) {
345- expr .getTarget ( ) instanceof AllocationFunction and
346- not exists ( NewOrNewArrayExpr newExpr |
347- // we synthesize allocator calls for `new` and `new[]`, so don't add instructions to
348- // the existing allocator call when it exists.
349- newExpr .getAllocatorCall ( ) = expr
350- ) and
351361 opcode instanceof Opcode:: InitializeDynamicAllocation and
352362 tag = OnlyInstructionTag ( ) and
353363 type = getUnknownType ( )
354364 }
355365
356- override Instruction getFirstInstruction ( ) {
357- if expr .getTarget ( ) instanceof AllocationFunction
358- then result = getInstruction ( OnlyInstructionTag ( ) )
359- else result = getChild ( 0 ) .getFirstInstruction ( )
360- }
361-
362366 override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
363367 tag = OnlyInstructionTag ( ) and
364368 kind = gotoEdge ( ) and
365- expr .getTarget ( ) instanceof AllocationFunction and
366- not exists ( NewOrNewArrayExpr newExpr |
367- // we synthesize allocator calls for `new` and `new[]`, so don't add instructions to
368- // the existing allocator call when it exists.
369- newExpr .getAllocatorCall ( ) = expr
370- ) and
371369 if exists ( getChild ( 0 ) )
372370 then result = getChild ( 0 ) .getFirstInstruction ( )
373371 else result = getParent ( ) .getChildSuccessor ( this )
@@ -381,23 +379,34 @@ class TranslatedSideEffects extends TranslatedElement, TTranslatedSideEffects {
381379
382380 override Instruction getPrimaryInstructionForSideEffect ( InstructionTag tag ) {
383381 tag = OnlyInstructionTag ( ) and
384- result = getTranslatedExpr ( expr ) .getInstruction ( CallTag ( ) )
382+ if expr instanceof NewOrNewArrayExpr
383+ then result = getTranslatedAllocatorCall ( expr ) .getInstruction ( CallTag ( ) )
384+ else result = getTranslatedExpr ( expr ) .getInstruction ( CallTag ( ) )
385385 }
386+ }
386387
387- /**
388- * Gets the `TranslatedFunction` containing this expression.
389- */
390- final TranslatedFunction getEnclosingFunction ( ) {
391- result = getTranslatedFunction ( expr .getEnclosingFunction ( ) )
392- }
388+ class TranslatedCallSideEffects extends TranslatedSideEffects , TTranslatedCallSideEffects {
389+ Call expr ;
393390
394- /**
395- * Gets the `Function` containing this expression.
396- */
397- override Function getFunction ( ) { result = expr .getEnclosingFunction ( ) }
391+ TranslatedCallSideEffects ( ) { this = TTranslatedCallSideEffects ( expr ) }
392+
393+ override string toString ( ) { result = "(side effects for " + expr .toString ( ) + ")" }
394+
395+ override Call getExpr ( ) { result = expr }
396+
397+ override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType type ) { none ( ) }
398+
399+ override Instruction getFirstInstruction ( ) { result = getChild ( 0 ) .getFirstInstruction ( ) }
400+
401+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) { none ( ) }
402+
403+ override Instruction getPrimaryInstructionForSideEffect ( InstructionTag tag ) {
404+ tag = OnlyInstructionTag ( ) and
405+ result = getTranslatedExpr ( expr ) .getInstruction ( CallTag ( ) )
406+ }
398407}
399408
400- class TranslatedStructorCallSideEffects extends TranslatedSideEffects {
409+ class TranslatedStructorCallSideEffects extends TranslatedCallSideEffects {
401410 TranslatedStructorCallSideEffects ( ) { getParent ( ) .( TranslatedStructorCall ) .hasQualifier ( ) }
402411
403412 override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType t ) {
0 commit comments