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

Skip to content

Commit 4977763

Browse files
author
AndreiDiaconu1
committed
Applied the review comments
1 parent ffb22bf commit 4977763

13 files changed

Lines changed: 50 additions & 201 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Most queries should operate on the aliased SSA IR, so that's what we expose
2-
// publically as the "IR".
3-
//import implementation.aliased_ssa.IR
1+
/**
2+
* Most queries should operate on the aliased SSA IR, so that's what we expose
3+
* publicly as the "IR".
4+
*/
45
import implementation.raw.IR

csharp/ql/src/semmle/code/csharp/ir/IRConfiguration.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Module used to configure the IR generation process.
3+
*/
4+
15
import csharp
26

37
private newtype TIRConfiguration = MkIRConfiguration()

csharp/ql/src/semmle/code/csharp/ir/Util.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import csharp
77
class ArrayInitWithMod extends ArrayInitializer {
88
predicate isInitialized(int entry) { entry in [0 .. this.getNumberOfElements() - 1] }
99

10-
pragma[inline]
1110
predicate isValueInitialized(int elementIndex) {
1211
isInitialized(elementIndex) and
1312
not exists(this.getElement(elementIndex))
@@ -20,7 +19,6 @@ class ObjectInitializerMod extends ObjectInitializer {
2019
this.getAMemberInitializer().getTargetVariable() = field
2120
}
2221

23-
pragma[inline]
2422
predicate isValueInitialized(Field field) {
2523
this.isInitialized(field) and
2624
not field = this.getAMemberInitializer().getInitializedMember()

csharp/ql/src/semmle/code/csharp/ir/implementation/IRConfiguration.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Module used to configure the IR generation process.
3+
*/
4+
15
private import internal.IRConfigurationInternal
26

37
private newtype TIRConfiguration = MkIRConfiguration()

csharp/ql/src/semmle/code/csharp/ir/implementation/SSA.md

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

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,10 @@ cached private module Cached {
5555
)
5656
}
5757

58-
// TODO: Conversion? Cast?
5958
cached Expr getInstructionUnconvertedResultExpression(Instruction instruction) {
6059
exists(Expr converted, TranslatedExpr translatedExpr |
61-
result = converted.(Cast).getExpr+()
62-
or
63-
result = converted
60+
result = converted.stripCasts()
6461
|
65-
not result instanceof Cast and
6662
translatedExpr = getTranslatedExpr(converted) and
6763
instruction = translatedExpr.getResult()
6864
)
@@ -73,21 +69,19 @@ cached private module Cached {
7369
getInstructionTag(instruction), tag)
7470
}
7571

76-
cached Instruction getMemoryOperandDefinition(Instruction instruction, MemoryOperandTag tag, Overlap overlap) {
72+
cached Instruction getMemoryOperandDefinition(Instruction instruction, MemoryOperandTag tag, MustTotallyOverlap overlap) {
7773
result = getInstructionTranslatedElement(instruction).getInstructionOperand(
78-
getInstructionTag(instruction), tag) and
79-
overlap instanceof MustTotallyOverlap
74+
getInstructionTag(instruction), tag)
8075
}
8176

8277
cached Type getInstructionOperandType(Instruction instruction, TypedOperandTag tag) {
8378
// For all `LoadInstruction`s, the operand type of the `LoadOperand` is the same as
8479
// the result type of the load.
85-
result = instruction.(LoadInstruction).getResultType() or
86-
(
87-
not instruction instanceof LoadInstruction and
80+
if instruction instanceof LoadInstruction then
81+
result = instruction.(LoadInstruction).getResultType()
82+
else
8883
result = getInstructionTranslatedElement(instruction).getInstructionOperandType(
8984
getInstructionTag(instruction), tag)
90-
)
9185
}
9286

9387
cached int getInstructionOperandSize(Instruction instruction, SideEffectOperandTag tag) {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ import csharp
22
import semmle.code.csharp.ir.Util
33

44

5-
// TODO: Both exists needed?
65
private predicate fieldIsInitialized(Field field) {
7-
exists(ObjectInitializer initList |
8-
exists(int i | field = initList.getMemberInitializer(i).getInitializedMember())
9-
) or
10-
exists(MemberInitializer init |
11-
field = init.getInitializedMember()
12-
)
6+
exists(field.getInitializer())
137
}
148

159
private predicate elementIsInitialized(int elementIndex) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import InstructionTag
55
private import TranslatedElement
66
private import TranslatedExpr
77
private import semmle.code.csharp.ir.Util
8+
private import semmle.code.csharp.ir.internal.IRCSharpLanguage as Language
89

910
/**
1011
* The IR translation of a call to a function. The call may be from an actual
@@ -45,12 +46,11 @@ abstract class TranslatedCall extends TranslatedExpr {
4546
(
4647
if hasWriteSideEffect() then (
4748
opcode instanceof Opcode::CallSideEffect and
48-
// Was UnknownType, fix after comp layer
49-
resultType instanceof VoidType
49+
resultType instanceof Language::UnknownType
5050
)
5151
else (
5252
opcode instanceof Opcode::CallReadSideEffect and
53-
resultType instanceof VoidType
53+
resultType instanceof Language::UnknownType
5454
)
5555
) and
5656
isLValue = false
@@ -126,8 +126,7 @@ abstract class TranslatedCall extends TranslatedExpr {
126126
tag = CallSideEffectTag() and
127127
hasSideEffect() and
128128
operandTag instanceof SideEffectOperandTag and
129-
// TODO: Was UnknownType, fix after comp layer
130-
result instanceof VoidType
129+
result instanceof Language::UnknownType
131130
}
132131

133132
override final Instruction getResult() {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ abstract class TranslatedBinaryLogicalOperation extends
152152
final TranslatedCondition getRightOperand() {
153153
result = getTranslatedCondition(expr.getRightOperand())
154154
}
155+
156+
final TranslatedCondition getAnOperand() {
157+
result = getLeftOperand() or
158+
result = getRightOperand()
159+
}
155160
}
156161

157162
class TranslatedLogicalAndExpr extends TranslatedBinaryLogicalOperation {
@@ -171,7 +176,7 @@ class TranslatedLogicalAndExpr extends TranslatedBinaryLogicalOperation {
171176
}
172177

173178
override Instruction getChildFalseSuccessor(TranslatedCondition child) {
174-
(child = getLeftOperand() or child = getRightOperand()) and
179+
child = getAnOperand() and
175180
result = getConditionContext().getChildFalseSuccessor(this)
176181
}
177182
}
@@ -180,7 +185,7 @@ class TranslatedLogicalOrExpr extends TranslatedBinaryLogicalOperation {
180185
override LogicalOrExpr expr;
181186

182187
override Instruction getChildTrueSuccessor(TranslatedCondition child) {
183-
(child = getLeftOperand() or child = getRightOperand()) and
188+
child = getAnOperand() and
184189
result = getConditionContext().getChildTrueSuccessor(this)
185190
}
186191

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TranslatedNonVariableDeclarationEntry extends TranslatedDeclarationEntry {
6060
Type resultType, boolean isLValue) {
6161
opcode instanceof Opcode::NoOp and
6262
tag = OnlyInstructionTag() and
63-
resultType instanceof VoidType and
63+
resultType instanceof Language::UnknownType and
6464
isLValue = false
6565
}
6666

0 commit comments

Comments
 (0)