@@ -2017,6 +2017,48 @@ TranslatedAllocatorCall getTranslatedAllocatorCall(NewOrNewArrayExpr newExpr) {
2017
2017
result .getAst ( ) = newExpr
2018
2018
}
2019
2019
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
+
2020
2062
/**
2021
2063
* Abstract class implemented by any `TranslatedElement` that has a child
2022
2064
* expression that is a call to a constructor or destructor, in order to
@@ -2955,75 +2997,60 @@ class TranslatedNewArrayExpr extends TranslatedNewOrNewArrayExpr {
2955
2997
}
2956
2998
2957
2999
/**
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.
2962
3001
*/
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
+ }
2965
3014
2966
3015
final override Instruction getFirstInstruction ( ) {
2967
- result = this .getOperand ( ) .getFirstInstruction ( )
3016
+ result = this .getDeallocatorCall ( ) .getFirstInstruction ( )
2968
3017
}
2969
3018
2970
- final override TranslatedElement getChild ( int id ) { id = 0 and result = this .getOperand ( ) }
3019
+ final override Instruction getResult ( ) { result = this .getInstruction ( OnlyInstructionTag ( ) ) }
2971
3020
2972
3021
final override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
3022
+ kind instanceof GotoEdge and
2973
3023
tag = OnlyInstructionTag ( ) and
2974
- result = this .getParent ( ) .getChildSuccessor ( this ) and
2975
- kind instanceof GotoEdge
3024
+ result = this .getParent ( ) .getChildSuccessor ( this )
2976
3025
}
2977
3026
2978
3027
final override Instruction getChildSuccessor ( TranslatedElement child ) {
2979
- child = this .getOperand ( ) and result = this .getInstruction ( OnlyInstructionTag ( ) )
3028
+ child = this .getDeallocatorCall ( ) and result = this .getInstruction ( OnlyInstructionTag ( ) )
2980
3029
}
2981
3030
2982
3031
final override Instruction getInstructionRegisterOperand ( InstructionTag tag , OperandTag operandTag ) {
2983
- none ( )
3032
+ tag = OnlyInstructionTag ( ) and
3033
+ operandTag instanceof UnaryOperandTag and
3034
+ result = this .getDeallocatorCall ( ) .getResult ( )
2984
3035
}
2985
3036
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 )
2990
3039
}
2991
3040
}
2992
3041
2993
3042
/**
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.
2998
3044
*/
2999
- class TranslatedDeleteExprPlaceHolder extends TranslatedSingleInstructionExpr {
3045
+ class TranslatedDeleteExpr extends TranslatedDeleteOrDeleteArrayExpr {
3000
3046
override DeleteExpr expr ;
3047
+ }
3001
3048
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 ;
3027
3054
}
3028
3055
3029
3056
/**
0 commit comments