Skip to content

Commit e1eeecf

Browse files
committed
C++: Make 'TranslatedBinaryOperation' no longer a single-instruction producing translated element. We need this for the next commit.
1 parent bc1412b commit e1eeecf

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/InstructionTag.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ newtype TInstructionTag =
9797
exists(Stmt s | exists(s.getImplicitDestructorCall(index)))
9898
} or
9999
CoAwaitBranchTag() or
100+
BinaryOperationOperationTag() or
100101
NotExprConversionTag()
101102

102103
class InstructionTag extends TInstructionTag {
@@ -288,5 +289,7 @@ string getInstructionTagId(TInstructionTag tag) {
288289
or
289290
tag = CoAwaitBranchTag() and result = "CoAwaitBranch"
290291
or
292+
tag = BinaryOperationOperationTag() and result = "BinaryOperationOperation"
293+
or
291294
tag = NotExprConversionTag() and result = "NotExprConversion"
292295
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,19 +1853,29 @@ private Opcode spaceShipOpcode(SpaceshipExpr expr) {
18531853
/**
18541854
* IR translation of a simple binary operation.
18551855
*/
1856-
class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
1856+
class TranslatedBinaryOperation extends TranslatedNonConstantExpr {
18571857
TranslatedBinaryOperation() {
18581858
expr instanceof BinaryArithmeticOperation or
18591859
expr instanceof BinaryBitwiseOperation or
18601860
expr instanceof ComparisonOperation
18611861
}
18621862

1863+
final override Instruction getResult() {
1864+
result = this.getInstruction(BinaryOperationOperationTag())
1865+
}
1866+
1867+
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
1868+
opcode = this.getOpcode() and
1869+
tag = BinaryOperationOperationTag() and
1870+
resultType = this.getResultType()
1871+
}
1872+
18631873
override Instruction getFirstInstruction(EdgeKind kind) {
18641874
result = this.getLeftOperand().getFirstInstruction(kind)
18651875
}
18661876

18671877
override Instruction getALastInstructionInternal() {
1868-
result = this.getInstruction(OnlyInstructionTag())
1878+
result = this.getInstruction(BinaryOperationOperationTag())
18691879
}
18701880

18711881
final override TranslatedElement getChildInternal(int id) {
@@ -1875,7 +1885,7 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
18751885
}
18761886

18771887
final override Instruction getInstructionRegisterOperand(InstructionTag tag, OperandTag operandTag) {
1878-
tag = OnlyInstructionTag() and
1888+
tag = BinaryOperationOperationTag() and
18791889
if this.swapOperandsOnOp()
18801890
then (
18811891
operandTag instanceof RightOperandTag and
@@ -1893,7 +1903,7 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
18931903
}
18941904

18951905
override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) {
1896-
tag = OnlyInstructionTag() and
1906+
tag = BinaryOperationOperationTag() and
18971907
result = this.getParent().getChildSuccessor(this, kind)
18981908
}
18991909

@@ -1903,10 +1913,10 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
19031913
or
19041914
kind instanceof GotoEdge and
19051915
child = this.getRightOperand() and
1906-
result = this.getInstruction(OnlyInstructionTag())
1916+
result = this.getInstruction(BinaryOperationOperationTag())
19071917
}
19081918

1909-
override Opcode getOpcode() {
1919+
Opcode getOpcode() {
19101920
result = binaryArithmeticOpcode(expr) or
19111921
result = binaryBitwiseOpcode(expr) or
19121922
result = comparisonOpcode(expr) or
@@ -1920,7 +1930,7 @@ class TranslatedBinaryOperation extends TranslatedSingleInstructionExpr {
19201930
}
19211931

19221932
override int getInstructionElementSize(InstructionTag tag) {
1923-
tag = OnlyInstructionTag() and
1933+
tag = BinaryOperationOperationTag() and
19241934
exists(Opcode opcode |
19251935
opcode = this.getOpcode() and
19261936
(

0 commit comments

Comments
 (0)