@@ -2017,6 +2017,66 @@ TranslatedAllocatorCall getTranslatedAllocatorCall(NewOrNewArrayExpr newExpr) {
20172017 result .getAst ( ) = newExpr
20182018}
20192019
2020+ /**
2021+ * The IR translation of a `delete` or `delete[]`
2022+ * expression.
2023+ */
2024+ class TranslatedDeleteOrDeleteArrayExpr extends TranslatedNonConstantExpr , TranslatedCall {
2025+ override DeleteOrDeleteArrayExpr expr ;
2026+
2027+ final override Instruction getFirstCallTargetInstruction ( ) {
2028+ result = this .getInstruction ( CallTargetTag ( ) )
2029+ }
2030+
2031+ final override Instruction getCallTargetResult ( ) { result = this .getInstruction ( CallTargetTag ( ) ) }
2032+
2033+ override predicate hasInstruction ( Opcode opcode , InstructionTag tag , CppType resultType ) {
2034+ TranslatedCall .super .hasInstruction ( opcode , tag , resultType )
2035+ or
2036+ tag = CallTargetTag ( ) and
2037+ resultType = getFunctionGLValueType ( ) and
2038+ if exists ( expr .getDeallocator ( ) )
2039+ then opcode instanceof Opcode:: FunctionAddress
2040+ else opcode instanceof Opcode:: VirtualDeleteFunctionAddress
2041+ }
2042+
2043+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
2044+ result = TranslatedCall .super .getInstructionSuccessor ( tag , kind )
2045+ or
2046+ tag = CallTargetTag ( ) and
2047+ kind instanceof GotoEdge and
2048+ result = this .getFirstArgumentOrCallInstruction ( )
2049+ }
2050+
2051+ override Function getInstructionFunction ( InstructionTag tag ) {
2052+ tag = CallTargetTag ( ) and result = expr .getDeallocator ( )
2053+ }
2054+
2055+ final override Type getCallResultType ( ) { result = expr .getType ( ) }
2056+
2057+ final override TranslatedExpr getQualifier ( ) { none ( ) }
2058+
2059+ final override predicate hasArguments ( ) {
2060+ // All deallocator calls have at least one argument.
2061+ any ( )
2062+ }
2063+
2064+ final override int getNumberOfArguments ( ) {
2065+ // We ignore the other arguments for now as we would have to synthesize them.
2066+ result = 1
2067+ }
2068+
2069+ final override TranslatedExpr getArgument ( int index ) {
2070+ // The only argument we define is the pointer to be deallocated.
2071+ index = 0 and
2072+ result = getTranslatedExpr ( expr .getExpr ( ) .getFullyConverted ( ) )
2073+ }
2074+ }
2075+
2076+ TranslatedDeleteOrDeleteArrayExpr getTranslatedDeleteOrDeleteArray ( DeleteOrDeleteArrayExpr newExpr ) {
2077+ result .getAst ( ) = newExpr
2078+ }
2079+
20202080/**
20212081 * Abstract class implemented by any `TranslatedElement` that has a child
20222082 * expression that is a call to a constructor or destructor, in order to
@@ -2954,78 +3014,6 @@ class TranslatedNewArrayExpr extends TranslatedNewOrNewArrayExpr {
29543014 }
29553015}
29563016
2957- /**
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.
2962- */
2963- class TranslatedDeleteArrayExprPlaceHolder extends TranslatedSingleInstructionExpr {
2964- override DeleteArrayExpr expr ;
2965-
2966- final override Instruction getFirstInstruction ( ) {
2967- result = this .getOperand ( ) .getFirstInstruction ( )
2968- }
2969-
2970- final override TranslatedElement getChild ( int id ) { id = 0 and result = this .getOperand ( ) }
2971-
2972- final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
2973- tag = OnlyInstructionTag ( ) and
2974- result = this .getParent ( ) .getChildSuccessor ( this ) and
2975- kind instanceof GotoEdge
2976- }
2977-
2978- final override Instruction getChildSuccessor ( TranslatedElement child ) {
2979- child = this .getOperand ( ) and result = this .getInstruction ( OnlyInstructionTag ( ) )
2980- }
2981-
2982- final override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
2983- none ( )
2984- }
2985-
2986- final override Opcode getOpcode ( ) { result instanceof Opcode:: NoOp }
2987-
2988- private TranslatedExpr getOperand ( ) {
2989- result = getTranslatedExpr ( expr .getExpr ( ) .getFullyConverted ( ) )
2990- }
2991- }
2992-
2993- /**
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.
2998- */
2999- class TranslatedDeleteExprPlaceHolder extends TranslatedSingleInstructionExpr {
3000- override DeleteExpr expr ;
3001-
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- }
3027- }
3028-
30293017/**
30303018 * The IR translation of a `ConditionDeclExpr`, which represents the value of the declared variable
30313019 * after conversion to `bool` in code such as:
0 commit comments