mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
CPP: Remove uneeded indirection around delete calls in the IR.
This commit is contained in:
@@ -352,7 +352,7 @@ class TranslatedCallSideEffects extends TranslatedSideEffects, TTranslatedCallSi
|
||||
result = getTranslatedAllocatorCall(expr).getInstruction(CallTag())
|
||||
or
|
||||
expr instanceof DeleteOrDeleteArrayExpr and
|
||||
result = getTranslatedDeallocatorCall(expr).getInstruction(CallTag())
|
||||
result = getTranslatedDeleteOrDeleteArray(expr).getInstruction(CallTag())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -723,8 +723,6 @@ newtype TTranslatedElement =
|
||||
} or
|
||||
// An allocator call in a `new` or `new[]` expression
|
||||
TTranslatedAllocatorCall(NewOrNewArrayExpr newExpr) { not ignoreExpr(newExpr) } or
|
||||
// An deallocator call in a `delete` or `delete[]` expression
|
||||
TTranslatedDeallocatorCall(DeleteOrDeleteArrayExpr newExpr) { not ignoreExpr(newExpr) } or
|
||||
// An allocation size for a `new` or `new[]` expression
|
||||
TTranslatedAllocationSize(NewOrNewArrayExpr newExpr) { not ignoreExpr(newExpr) } or
|
||||
// The declaration/initialization part of a `ConditionDeclExpr`
|
||||
|
||||
@@ -2018,16 +2018,12 @@ TranslatedAllocatorCall getTranslatedAllocatorCall(NewOrNewArrayExpr newExpr) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The IR translation of a call to `operator delete` as part of a `delete` or `delete[]`
|
||||
* The IR translation of a `delete` or `delete[]`
|
||||
* expression.
|
||||
*/
|
||||
class TranslatedDeallocatorCall extends TTranslatedDeallocatorCall, TranslatedCall {
|
||||
class TranslatedDeleteOrDeleteArrayExpr extends TranslatedNonConstantExpr, TranslatedCall {
|
||||
override DeleteOrDeleteArrayExpr expr;
|
||||
|
||||
TranslatedDeallocatorCall() { this = TTranslatedDeallocatorCall(expr) }
|
||||
|
||||
final override string toString() { result = "Deallocator call for " + expr.toString() }
|
||||
|
||||
final override Instruction getFirstCallTargetInstruction() {
|
||||
result = this.getInstruction(CallTargetTag())
|
||||
}
|
||||
@@ -2052,8 +2048,6 @@ class TranslatedDeallocatorCall extends TTranslatedDeallocatorCall, TranslatedCa
|
||||
result = this.getFirstArgumentOrCallInstruction()
|
||||
}
|
||||
|
||||
final override predicate producesExprResult() { none() }
|
||||
|
||||
override Function getInstructionFunction(InstructionTag tag) {
|
||||
tag = CallTargetTag() and result = expr.getDeallocator()
|
||||
}
|
||||
@@ -2079,7 +2073,7 @@ class TranslatedDeallocatorCall extends TTranslatedDeallocatorCall, TranslatedCa
|
||||
}
|
||||
}
|
||||
|
||||
TranslatedDeallocatorCall getTranslatedDeallocatorCall(DeleteOrDeleteArrayExpr newExpr) {
|
||||
TranslatedDeleteOrDeleteArrayExpr getTranslatedDeleteOrDeleteArray(DeleteOrDeleteArrayExpr newExpr) {
|
||||
result.getAst() = newExpr
|
||||
}
|
||||
|
||||
@@ -3020,63 +3014,6 @@ class TranslatedNewArrayExpr extends TranslatedNewOrNewArrayExpr {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The IR translation of a `delete` or `delete[]` expression.
|
||||
*/
|
||||
abstract class TranslatedDeleteOrDeleteArrayExpr extends TranslatedNonConstantExpr {
|
||||
override DeleteOrDeleteArrayExpr expr;
|
||||
|
||||
final override TranslatedElement getChild(int id) {
|
||||
id = 0 and result = this.getDeallocatorCall()
|
||||
}
|
||||
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = OnlyInstructionTag() and
|
||||
opcode instanceof Opcode::Convert and
|
||||
resultType = this.getResultType()
|
||||
}
|
||||
|
||||
final override Instruction getFirstInstruction() {
|
||||
result = this.getDeallocatorCall().getFirstInstruction()
|
||||
}
|
||||
|
||||
final override Instruction getResult() { result = this.getInstruction(OnlyInstructionTag()) }
|
||||
|
||||
final override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
|
||||
kind instanceof GotoEdge and
|
||||
tag = OnlyInstructionTag() and
|
||||
result = this.getParent().getChildSuccessor(this)
|
||||
}
|
||||
|
||||
final override Instruction getChildSuccessor(TranslatedElement child) {
|
||||
child = this.getDeallocatorCall() and result = this.getInstruction(OnlyInstructionTag())
|
||||
}
|
||||
|
||||
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
|
||||
tag = OnlyInstructionTag() and
|
||||
operandTag instanceof UnaryOperandTag and
|
||||
result = this.getDeallocatorCall().getResult()
|
||||
}
|
||||
|
||||
private TranslatedDeallocatorCall getDeallocatorCall() {
|
||||
result = getTranslatedDeallocatorCall(expr)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The IR translation of a `delete` expression.
|
||||
*/
|
||||
class TranslatedDeleteExpr extends TranslatedDeleteOrDeleteArrayExpr {
|
||||
override DeleteExpr expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* The IR translation of a `delete[]` expression.
|
||||
*/
|
||||
class TranslatedDeleteArrayExpr extends TranslatedDeleteOrDeleteArrayExpr {
|
||||
override DeleteArrayExpr expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* The IR translation of a `ConditionDeclExpr`, which represents the value of the declared variable
|
||||
* after conversion to `bool` in code such as:
|
||||
|
||||
Reference in New Issue
Block a user