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

Skip to content

Commit fa74ed3

Browse files
author
AndreiDiaconu1
committed
Address PR comments
1 parent 515642e commit fa74ed3

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ predicate ignoreLoad(Expr expr) {
196196
or
197197
// No load is needed for the lvalue in an assignment such as:
198198
// Eg. `Object obj = oldObj`;
199-
expr.getParent().(Assignment).getLValue() = expr and
199+
expr = any(Assignment a).getLValue() and
200200
expr.getType() instanceof RefType
201201
or
202202
// Since the loads for a crement operation is handled by the translation
@@ -211,11 +211,10 @@ predicate ignoreLoad(Expr expr) {
211211
// its target variable is a value type variable,
212212
// ignore the load since the address of a variable that is a value type is
213213
// given by a single `VariableAddress` instruction.
214-
expr.getParent().(FieldAccess).getQualifier() = expr and
215-
expr.(VariableAccess).getType().isValueType() and
216-
not (
217-
expr.(VariableAccess).getTarget().(Parameter).isOutOrRef() or
218-
expr.(VariableAccess).getTarget().(Parameter).isIn()
214+
expr = any(FieldAccess fa).getQualifier() and
215+
expr = any(VariableAccess va |
216+
va.getType().isValueType() and
217+
not va.getTarget() = any(Parameter p | p.isOutOrRef() or p.isIn())
219218
)
220219
or
221220
// If expr is passed as an `out,`ref` or `in` argument,

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -715,19 +715,13 @@ abstract class TranslatedPointerOps extends TranslatedNonConstantExpr {
715715
}
716716

717717
class TranslatedPointerIndirectionExpr extends TranslatedPointerOps {
718-
TranslatedPointerIndirectionExpr() {
719-
// *p is the same as p until the result is loaded.
720-
expr instanceof PointerIndirectionExpr
721-
}
718+
override PointerIndirectionExpr expr;
722719

723720
override TranslatedExpr getOperand() { result = getTranslatedExpr(expr.getOperand()) }
724721
}
725722

726723
class TranslatedAddressExpr extends TranslatedPointerOps {
727-
TranslatedAddressExpr() {
728-
// &x is the same as x.
729-
expr instanceof AddressOfExpr
730-
}
724+
override AddressOfExpr expr;
731725

732726
override TranslatedExpr getOperand() { result = getTranslatedExpr(expr.getOperand()) }
733727
}
@@ -834,7 +828,7 @@ abstract class TranslatedVariableAccess extends TranslatedNonConstantExpr {
834828
* Some variable accesses need an extra load, eg. ref parameters,
835829
* out parameters
836830
*/
837-
final predicate needsExtraLoad() {
831+
final private predicate needsExtraLoad() {
838832
(
839833
expr.getTarget().(Parameter).isOutOrRef() or
840834
expr.getTarget().(Parameter).isIn()
@@ -2068,9 +2062,9 @@ abstract class TranslatedCreation extends TranslatedCoreExpr, TTranslatedCreatio
20682062
final override Instruction getFirstInstruction() { result = this.getInstruction(NewObjTag()) }
20692063

20702064
override Instruction getResult() {
2071-
if not this.needsLoad()
2072-
then result = this.getInstruction(NewObjTag())
2073-
else result = this.getInstruction(LoadTag())
2065+
if this.needsLoad()
2066+
then result = this.getInstruction(LoadTag())
2067+
else result = this.getInstruction(NewObjTag())
20742068
}
20752069

20762070
override Instruction getReceiver() { result = getInstruction(NewObjTag()) }
@@ -2111,9 +2105,9 @@ abstract class TranslatedCreation extends TranslatedCoreExpr, TTranslatedCreatio
21112105
}
21122106

21132107
private Instruction getLoadOrChildSuccessor() {
2114-
if not this.needsLoad()
2115-
then result = this.getParent().getChildSuccessor(this)
2116-
else result = this.getInstruction(LoadTag())
2108+
if this.needsLoad()
2109+
then result = this.getInstruction(LoadTag())
2110+
else result = this.getParent().getChildSuccessor(this)
21172111
}
21182112

21192113
abstract TranslatedElement getConstructorCall();

0 commit comments

Comments
 (0)