C++ IR: Translate ErrorExpr to NoOp

This commit is contained in:
Jonas Jensen
2019-07-05 13:45:14 +02:00
parent e2a43eeed6
commit a86ddd50de
5 changed files with 49 additions and 27 deletions

View File

@@ -2862,3 +2862,36 @@ class TranslatedStmtExpr extends TranslatedNonConstantExpr {
result = getTranslatedStmt(expr.getStmt())
}
}
class TranslatedErrorExpr extends TranslatedSingleInstructionExpr {
override ErrorExpr expr;
TranslatedErrorExpr() {
// The extractor deliberately emits an `ErrorExpr` as the first argument to
// the allocator call, if any, of a `NewOrNewArrayExpr`. That `ErrorExpr`
// should not be translated.
not exists(NewOrNewArrayExpr new | expr = new.getAllocatorCall().getArgument(0))
}
override final Instruction getFirstInstruction() {
result = getInstruction(OnlyInstructionTag())
}
override final TranslatedElement getChild(int id) { none() }
override final Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
tag = OnlyInstructionTag() and
result = getParent().getChildSuccessor(this) and
kind instanceof GotoEdge
}
override final Instruction getChildSuccessor(TranslatedElement child) { none() }
override final Instruction getInstructionOperand(InstructionTag tag, OperandTag operandTag) {
none()
}
override final Opcode getOpcode() {
result instanceof Opcode::NoOp
}
}

View File

@@ -4,7 +4,6 @@ duplicateOperand
missingPhiOperand
missingOperandType
instructionWithoutSuccessor
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -50,25 +50,22 @@ bad_asts.cpp:
# 30| void Bad::errorExpr()
# 30| Block 0
# 30| v0_0(void) = EnterFunction :
# 30| mu0_1(unknown) = AliasedDefinition :
# 30| mu0_2(unknown) = UnmodeledDefinition :
#-----| Block 1
#-----| r1_0(error) = Load : ~mu0_2
# 33| r1_1(glval<int>) = VariableAddress[x] :
# 33| mu1_2(int) = Store : &:r1_1, r1_0
# 34| v1_3(void) = NoOp :
# 30| v1_4(void) = ReturnVoid :
# 30| v1_5(void) = UnmodeledUse : mu*
# 30| v1_6(void) = ExitFunction :
#-----| Block 2
#-----| r2_0(error) = Load : ~mu0_2
# 32| r2_1(glval<int>) = VariableAddress[x] :
# 32| Block 3
# 32| mu3_0(int) = Store : &:r2_1
# 30| v0_0(void) = EnterFunction :
# 30| mu0_1(unknown) = AliasedDefinition :
# 30| mu0_2(unknown) = UnmodeledDefinition :
#-----| r0_3(glval<error>) = NoOp :
#-----| r0_4(error) = Load : &:r0_3, ~mu0_2
# 32| r0_5(glval<int>) = VariableAddress[x] :
# 32| r0_6(error) = NoOp :
# 32| mu0_7(int) = Store : &:r0_5, r0_6
#-----| r0_8(glval<error>) = NoOp :
#-----| r0_9(error) = Load : &:r0_8, ~mu0_2
# 33| r0_10(glval<int>) = VariableAddress[x] :
# 33| mu0_11(int) = Store : &:r0_10, r0_9
# 34| v0_12(void) = NoOp :
# 30| v0_13(void) = ReturnVoid :
# 30| v0_14(void) = UnmodeledUse : mu*
# 30| v0_15(void) = ExitFunction :
clang.cpp:
# 5| int* globalIntAddress()

View File

@@ -1,15 +1,9 @@
missingOperand
| 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() |
| 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() |
| 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() |
unexpectedOperand
duplicateOperand
missingPhiOperand
missingOperandType
instructionWithoutSuccessor
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
| bad_asts.cpp:32:9:32:9 | VariableAddress: definition of x |
| bad_asts.cpp:32:12:32:16 | Store: <error expr> |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction

View File

@@ -4,7 +4,6 @@ duplicateOperand
missingPhiOperand
missingOperandType
instructionWithoutSuccessor
| bad_asts.cpp:30:8:30:16 | UnmodeledDefinition: errorExpr |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction