@@ -2017,6 +2017,48 @@ TranslatedAllocatorCall getTranslatedAllocatorCall(NewOrNewArrayExpr newExpr) {
20172017 result .getAst ( ) = newExpr
20182018}
20192019
2020+ /**
2021+ * The IR translation of a call to `operator delete` as part of a `delete` or `delete[]`
2022+ * expression.
2023+ */
2024+ class TranslatedDeallocatorCall extends TTranslatedDeallocatorCall , TranslatedDirectCall {
2025+ override DeleteOrDeleteArrayExpr expr ;
2026+
2027+ TranslatedDeallocatorCall ( ) { this = TTranslatedDeallocatorCall ( expr ) }
2028+
2029+ final override string toString ( ) { result = "Deallocator call for " + expr .toString ( ) }
2030+
2031+ final override predicate producesExprResult ( ) { none ( ) }
2032+
2033+ override Function getInstructionFunction ( InstructionTag tag ) {
2034+ tag = CallTargetTag ( ) and result = expr .getDeallocator ( )
2035+ }
2036+
2037+ final override Type getCallResultType ( ) { result = expr .getType ( ) }
2038+
2039+ final override TranslatedExpr getQualifier ( ) { none ( ) }
2040+
2041+ final override predicate hasArguments ( ) {
2042+ // All deallocator calls have at least one argument.
2043+ any ( )
2044+ }
2045+
2046+ final override int getNumberOfArguments ( ) {
2047+ // We ignore the other arguments for now as we would have to synthesize them.
2048+ result = 1
2049+ }
2050+
2051+ final override TranslatedExpr getArgument ( int index ) {
2052+ // The only argument we define is the pointer to be deallocated.
2053+ index = 0 and
2054+ result = getTranslatedExpr ( expr .getExpr ( ) .getFullyConverted ( ) )
2055+ }
2056+ }
2057+
2058+ TranslatedDeallocatorCall getTranslatedDeallocatorCall ( DeleteOrDeleteArrayExpr newExpr ) {
2059+ result .getAst ( ) = newExpr
2060+ }
2061+
20202062/**
20212063 * Abstract class implemented by any `TranslatedElement` that has a child
20222064 * expression that is a call to a constructor or destructor, in order to
@@ -2955,75 +2997,60 @@ class TranslatedNewArrayExpr extends TranslatedNewOrNewArrayExpr {
29552997}
29562998
29572999/**
2958- * A placeholder for the translation of a `delete[]` expression.
2959- *
2960- * Proper translation is not yet implemented, but this stub implementation
2961- * ensures that code following a `delete[]` is not unreachable.
3000+ * The IR translation of a `delete` or `delete[]` expression.
29623001 */
2963- class TranslatedDeleteArrayExprPlaceHolder extends TranslatedSingleInstructionExpr {
2964- override DeleteArrayExpr expr ;
3002+ abstract class TranslatedDeleteOrDeleteArrayExpr extends TranslatedNonConstantExpr {
3003+ override DeleteOrDeleteArrayExpr expr ;
3004+
3005+ final override TranslatedElement getChild ( int id ) {
3006+ id = 0 and result = this .getDeallocatorCall ( )
3007+ }
3008+
3009+ final override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
3010+ tag = OnlyInstructionTag ( ) and
3011+ opcode instanceof Opcode:: Convert and
3012+ resultType = this .getResultType ( )
3013+ }
29653014
29663015 final override Instruction getFirstInstruction ( ) {
2967- result = this .getOperand ( ) .getFirstInstruction ( )
3016+ result = this .getDeallocatorCall ( ) .getFirstInstruction ( )
29683017 }
29693018
2970- final override TranslatedElement getChild ( int id ) { id = 0 and result = this .getOperand ( ) }
3019+ final override Instruction getResult ( ) { result = this .getInstruction ( OnlyInstructionTag ( ) ) }
29713020
29723021 final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
3022+ kind instanceof GotoEdge and
29733023 tag = OnlyInstructionTag ( ) and
2974- result = this .getParent ( ) .getChildSuccessor ( this ) and
2975- kind instanceof GotoEdge
3024+ result = this .getParent ( ) .getChildSuccessor ( this )
29763025 }
29773026
29783027 final override Instruction getChildSuccessor ( TranslatedElement child ) {
2979- child = this .getOperand ( ) and result = this .getInstruction ( OnlyInstructionTag ( ) )
3028+ child = this .getDeallocatorCall ( ) and result = this .getInstruction ( OnlyInstructionTag ( ) )
29803029 }
29813030
29823031 final override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
2983- none ( )
3032+ tag = OnlyInstructionTag ( ) and
3033+ operandTag instanceof UnaryOperandTag and
3034+ result = this .getDeallocatorCall ( ) .getResult ( )
29843035 }
29853036
2986- final override Opcode getOpcode ( ) { result instanceof Opcode:: NoOp }
2987-
2988- private TranslatedExpr getOperand ( ) {
2989- result = getTranslatedExpr ( expr .getExpr ( ) .getFullyConverted ( ) )
3037+ private TranslatedDeallocatorCall getDeallocatorCall ( ) {
3038+ result = getTranslatedDeallocatorCall ( expr )
29903039 }
29913040}
29923041
29933042/**
2994- * A placeholder for the translation of a `delete` expression.
2995- *
2996- * Proper translation is not yet implemented, but this stub implementation
2997- * ensures that code following a `delete` is not unreachable.
3043+ * The IR translation of a `delete` expression.
29983044 */
2999- class TranslatedDeleteExprPlaceHolder extends TranslatedSingleInstructionExpr {
3045+ class TranslatedDeleteExpr extends TranslatedDeleteOrDeleteArrayExpr {
30003046 override DeleteExpr expr ;
3047+ }
30013048
3002- final override Instruction getFirstInstruction ( ) {
3003- result = this .getOperand ( ) .getFirstInstruction ( )
3004- }
3005-
3006- final override TranslatedElement getChild ( int id ) { id = 0 and result = this .getOperand ( ) }
3007-
3008- final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
3009- tag = OnlyInstructionTag ( ) and
3010- result = this .getParent ( ) .getChildSuccessor ( this ) and
3011- kind instanceof GotoEdge
3012- }
3013-
3014- final override Instruction getChildSuccessor ( TranslatedElement child ) {
3015- child = this .getOperand ( ) and result = this .getInstruction ( OnlyInstructionTag ( ) )
3016- }
3017-
3018- final override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
3019- none ( )
3020- }
3021-
3022- final override Opcode getOpcode ( ) { result instanceof Opcode:: NoOp }
3023-
3024- private TranslatedExpr getOperand ( ) {
3025- result = getTranslatedExpr ( expr .getExpr ( ) .getFullyConverted ( ) )
3026- }
3049+ /**
3050+ * The IR translation of a `delete[]` expression.
3051+ */
3052+ class TranslatedDeleteArrayExpr extends TranslatedDeleteOrDeleteArrayExpr {
3053+ override DeleteArrayExpr expr ;
30273054}
30283055
30293056/**
0 commit comments