From 0c6b60b2c6f9ee2e92aee80c3f1adcb6fa978084 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 22 Mar 2023 12:54:28 +0000 Subject: [PATCH] C++: Avoid two joins on value number. --- .../cpp/semantic/SemanticExprSpecific.qll | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll b/cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll index afffba57ae5..9d69154baa4 100644 --- a/cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll +++ b/cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll @@ -215,7 +215,7 @@ module SemanticExprConfig { newtype TSsaVariable = TSsaInstruction(IR::Instruction instr) { instr.hasMemoryResult() } or TSsaOperand(IR::Operand op) { op.isDefinitionInexact() } or - TSsaPointerArithmeticGuard(IR::PointerArithmeticInstruction instr) { + TSsaPointerArithmeticGuard(ValueNumber instr) { exists(Guard g, IR::Operand use | use = instr.getAUse() | g.comparesLt(use, _, _, _, _) or g.comparesLt(_, use, _, _, _) or @@ -231,7 +231,7 @@ module SemanticExprConfig { IR::Instruction asInstruction() { none() } - IR::PointerArithmeticInstruction asPointerArithGuard() { none() } + ValueNumber asPointerArithGuard() { none() } IR::Operand asOperand() { none() } } @@ -249,15 +249,15 @@ module SemanticExprConfig { } class SsaPointerArithmeticGuard extends SsaVariable, TSsaPointerArithmeticGuard { - IR::PointerArithmeticInstruction instr; + ValueNumber vn; - SsaPointerArithmeticGuard() { this = TSsaPointerArithmeticGuard(instr) } + SsaPointerArithmeticGuard() { this = TSsaPointerArithmeticGuard(vn) } - final override string toString() { result = instr.toString() } + final override string toString() { result = vn.toString() } - final override Location getLocation() { result = instr.getLocation() } + final override Location getLocation() { result = vn.getLocation() } - final override IR::PointerArithmeticInstruction asPointerArithGuard() { result = instr } + final override ValueNumber asPointerArithGuard() { result = vn } } class SsaOperand extends SsaVariable, TSsaOperand { @@ -289,7 +289,7 @@ module SemanticExprConfig { Expr getAUse(SsaVariable v) { result.getUnconverted().(IR::LoadInstruction).getSourceValue() = v.asInstruction() or - result.getUnconverted() = valueNumber(v.asPointerArithGuard()).getAnInstruction() + result.getUnconverted() = v.asPointerArithGuard().getAnInstruction() } SemType getSsaVariableType(SsaVariable v) { @@ -331,7 +331,7 @@ module SemanticExprConfig { final override predicate hasRead(SsaVariable v) { exists(IR::Operand operand | operand.getDef() = v.asInstruction() or - operand.getDef() = valueNumber(v.asPointerArithGuard()).getAnInstruction() + operand.getDef() = v.asPointerArithGuard().getAnInstruction() | not operand instanceof IR::PhiInputOperand and operand.getUse().getBlock() = block @@ -352,7 +352,7 @@ module SemanticExprConfig { final override predicate hasRead(SsaVariable v) { exists(IR::PhiInputOperand operand | operand.getDef() = v.asInstruction() or - operand.getDef() = valueNumber(v.asPointerArithGuard()).getAnInstruction() + operand.getDef() = v.asPointerArithGuard().getAnInstruction() | operand.getPredecessorBlock() = pred and operand.getUse().getBlock() = succ