Skip to content

Commit a86ddd5

Browse files
committed
C++ IR: Translate ErrorExpr to NoOp
1 parent e2a43ee commit a86ddd5

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,3 +2862,36 @@ class TranslatedStmtExpr extends TranslatedNonConstantExpr {
28622862
result = getTranslatedStmt(expr.getStmt())
28632863
}
28642864
}
2865+
2866+
class TranslatedErrorExpr extends TranslatedSingleInstructionExpr {
2867+
override ErrorExpr expr;
2868+
2869+
TranslatedErrorExpr() {
2870+
// The extractor deliberately emits an `ErrorExpr` as the first argument to
2871+
// the allocator call, if any, of a `NewOrNewArrayExpr`. That `ErrorExpr`
2872+
// should not be translated.
2873+
not exists(NewOrNewArrayExpr new | expr = new.getAllocatorCall().getArgument(0))
2874+
}
2875+
2876+
override final Instruction getFirstInstruction() {
2877+
result = getInstruction(OnlyInstructionTag())
2878+
}
2879+
2880+
override final TranslatedElement getChild(int id) { none() }
2881+
2882+
override final Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
2883+
tag = OnlyInstructionTag() and
2884+
result = getParent().getChildSuccessor(this) and
2885+
kind instanceof GotoEdge
2886+
}
2887+
2888+
override final Instruction getChildSuccessor(TranslatedElement child) { none() }
2889+
2890+
override final Instruction getInstructionOperand(InstructionTag tag, OperandTag operandTag) {
2891+
none()
2892+
}
2893+
2894+
override final Opcode getOpcode() {
2895+
result instanceof Opcode::NoOp
2896+
}
2897+
}

cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ duplicateOperand
44
missingPhiOperand
55
missingOperandType
66
instructionWithoutSuccessor
7-
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
87
ambiguousSuccessors
98
unexplainedLoop
109
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,22 @@ bad_asts.cpp:
5050

5151
# 30| void Bad::errorExpr()
5252
# 30| Block 0
53-
# 30| v0_0(void) = EnterFunction :
54-
# 30| mu0_1(unknown) = AliasedDefinition :
55-
# 30| mu0_2(unknown) = UnmodeledDefinition :
56-
57-
#-----| Block 1
58-
#-----| r1_0(error) = Load : ~mu0_2
59-
# 33| r1_1(glval<int>) = VariableAddress[x] :
60-
# 33| mu1_2(int) = Store : &:r1_1, r1_0
61-
# 34| v1_3(void) = NoOp :
62-
# 30| v1_4(void) = ReturnVoid :
63-
# 30| v1_5(void) = UnmodeledUse : mu*
64-
# 30| v1_6(void) = ExitFunction :
65-
66-
#-----| Block 2
67-
#-----| r2_0(error) = Load : ~mu0_2
68-
# 32| r2_1(glval<int>) = VariableAddress[x] :
69-
70-
# 32| Block 3
71-
# 32| mu3_0(int) = Store : &:r2_1
53+
# 30| v0_0(void) = EnterFunction :
54+
# 30| mu0_1(unknown) = AliasedDefinition :
55+
# 30| mu0_2(unknown) = UnmodeledDefinition :
56+
#-----| r0_3(glval<error>) = NoOp :
57+
#-----| r0_4(error) = Load : &:r0_3, ~mu0_2
58+
# 32| r0_5(glval<int>) = VariableAddress[x] :
59+
# 32| r0_6(error) = NoOp :
60+
# 32| mu0_7(int) = Store : &:r0_5, r0_6
61+
#-----| r0_8(glval<error>) = NoOp :
62+
#-----| r0_9(error) = Load : &:r0_8, ~mu0_2
63+
# 33| r0_10(glval<int>) = VariableAddress[x] :
64+
# 33| mu0_11(int) = Store : &:r0_10, r0_9
65+
# 34| v0_12(void) = NoOp :
66+
# 30| v0_13(void) = ReturnVoid :
67+
# 30| v0_14(void) = UnmodeledUse : mu*
68+
# 30| v0_15(void) = ExitFunction :
7269

7370
clang.cpp:
7471
# 5| int* globalIntAddress()

cpp/ql/test/library-tests/ir/ir/raw_sanity.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
missingOperand
2-
| bad_asts.cpp:32:12:32:16 | Store: <error expr> | Instruction 'Store' is missing an expected operand with tag 'StoreValue' in function '$@'. | bad_asts.cpp:30:8:30:16 | IR: errorExpr | void Bad::errorExpr() |
3-
| file://:0:0:0:0 | Load: <error expr> | Instruction 'Load' is missing an expected operand with tag 'Address' in function '$@'. | bad_asts.cpp:30:8:30:16 | IR: errorExpr | void Bad::errorExpr() |
4-
| file://:0:0:0:0 | Load: <error expr> | Instruction 'Load' is missing an expected operand with tag 'Address' in function '$@'. | bad_asts.cpp:30:8:30:16 | IR: errorExpr | void Bad::errorExpr() |
52
unexpectedOperand
63
duplicateOperand
74
missingPhiOperand
85
missingOperandType
96
instructionWithoutSuccessor
10-
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
11-
| bad_asts.cpp:32:9:32:9 | VariableAddress: definition of x |
12-
| bad_asts.cpp:32:12:32:16 | Store: <error expr> |
137
ambiguousSuccessors
148
unexplainedLoop
159
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ duplicateOperand
44
missingPhiOperand
55
missingOperandType
66
instructionWithoutSuccessor
7-
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
87
ambiguousSuccessors
98
unexplainedLoop
109
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)