Merge pull request #2045 from AndreiDiaconu1/ircsharp-various-fixes

C# IR: Minor sanity fixes
This commit is contained in:
Calum Grant
2019-09-27 15:51:07 +01:00
committed by GitHub
5 changed files with 106 additions and 108 deletions

View File

@@ -843,6 +843,9 @@ class TranslatedNonFieldVariableAccess extends TranslatedVariableAccess {
implies
expr = expr.getParent().(LocalVariableDeclAndInitExpr).getInitializer()
)
or
// Static field accesses should be modeled as `TranslatedNonFieldAccess`
expr.(FieldAccess).getTarget().isStatic()
}
override Instruction getFirstInstruction() {
@@ -875,6 +878,11 @@ class TranslatedNonFieldVariableAccess extends TranslatedVariableAccess {
class TranslatedFieldAccess extends TranslatedVariableAccess {
override FieldAccess expr;
TranslatedFieldAccess() {
// Static field accesses should be modeled as `TranslatedNonFieldAccess`
not expr.getTarget().isStatic()
}
override Instruction getFirstInstruction() {
// If there is a qualifier
if exists(this.getQualifier())

View File

@@ -75,7 +75,7 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
else
if exists(getParameter(0))
then result = this.getParameter(0).getFirstInstruction()
else result = this.getBody().getFirstInstruction()
else result = this.getBodyOrReturn()
)
or
(
@@ -85,7 +85,7 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
else
if exists(getConstructorInitializer())
then result = this.getConstructorInitializer().getFirstInstruction()
else result = this.getBody().getFirstInstruction()
else result = this.getBodyOrReturn()
)
or
tag = ReturnValueAddressTag() and
@@ -110,16 +110,22 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
else
if exists(getConstructorInitializer())
then result = this.getConstructorInitializer().getFirstInstruction()
else result = this.getBody().getFirstInstruction()
else result = this.getBodyOrReturn()
)
or
child = this.getConstructorInitializer() and
result = this.getBody().getFirstInstruction()
result = this.getBodyOrReturn()
or
child = this.getBody() and
result = this.getReturnSuccessorInstruction()
}
private Instruction getBodyOrReturn() {
if exists(this.getBody())
then result = this.getBody().getFirstInstruction()
else result = this.getReturnSuccessorInstruction()
}
final override predicate hasInstruction(
Opcode opcode, InstructionTag tag, Type resultType, boolean isLValue
) {