Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dae37e5

Browse files
Andrei DiaconuAndreiDiaconu1
authored andcommitted
Fixed bugs, updated tests
Fixed a bug in TranslatedExpr: decl + init where the rhs is a reference now work as expected Uncommented the code for the switch statement
1 parent be01b03 commit dae37e5

5 files changed

Lines changed: 374 additions & 893 deletions

File tree

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ abstract class TranslatedCoreExpr extends TranslatedExpr {
9898
* All exprs produce a final value, apart from reads. They first need an access,
9999
* then a load.
100100
*/
101+
// TODO: When the compatibility layer is in place,
102+
// create a special class for the following cases
101103
override final predicate producesExprResult() {
102-
// TODO: When the compatibility layer is in place,
103-
// create a special class for the following cases
104104
not (expr instanceof AssignableRead) or
105-
expr.getParent() instanceof ArrayAccess
105+
expr.getParent() instanceof ArrayAccess or
106+
// TODO: Make sure this is enough
107+
// Ref types need no loads
108+
// Eg. `Object obj = oldObj`;
109+
expr.getType() instanceof RefType
106110
}
107111

108112
/**
@@ -976,10 +980,13 @@ abstract class TranslatedVariableAccess extends TranslatedNonConstantExpr {
976980

977981
class TranslatedNonFieldVariableAccess extends TranslatedVariableAccess {
978982
TranslatedNonFieldVariableAccess() {
979-
// TODO: Make sure those are enough and correct
980983
not expr instanceof FieldAccess and
981-
// Init should take care of this access (check with cpp)
982-
(not expr.getParent() instanceof LocalVariableDeclAndInitExpr)
984+
// If the parent expression is a declaration + initialization
985+
// expr, then translate only the variables that are initializers (on the RHS)
986+
// and not the LHS (the address of the LHS is generated during
987+
// the translation of the initialization
988+
(expr.getParent() instanceof LocalVariableDeclAndInitExpr implies
989+
expr = expr.getParent().(LocalVariableDeclAndInitExpr).getInitializer())
983990
}
984991

985992
override Instruction getFirstInstruction() {

csharp/ql/test/library-tests/ir/ir/array_acc.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)