Skip to content

Commit 66948b4

Browse files
author
AndreiDiaconu1
committed
Fixed PR errors
1 parent c74898e commit 66948b4

28 files changed

+1711
-1980
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
* Temporary file that has stubs for various functionalities in the IR conversion.
33
*/
44

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/Instruction.qll

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,55 @@ module InstructionSanity {
215215
) and
216216
fromInstr != fromBlock
217217
}
218+
219+
/**
220+
* Gets the point in the function at which the specified operand is evaluated. For most operands,
221+
* this is at the instruction that consumes the use. For a `PhiInputOperand`, the effective point
222+
* of evaluation is at the end of the corresponding predecessor block.
223+
*/
224+
private predicate pointOfEvaluation(Operand operand, IRBlock block, int index) {
225+
(
226+
block = operand.(PhiInputOperand).getPredecessorBlock() and
227+
index = block.getInstructionCount()
228+
) or
229+
exists (Instruction use |
230+
use = operand.(NonPhiOperand).getUse() and
231+
block.getInstruction(index) = use
232+
)
233+
}
234+
235+
/**
236+
* Holds if `useOperand` has a definition that does not dominate the use.
237+
*/
238+
query predicate useNotDominatedByDefinition(Operand useOperand, string message, IRFunction func,
239+
string funcText) {
240+
241+
exists (IRBlock useBlock, int useIndex, Instruction defInstr, IRBlock defBlock, int defIndex |
242+
not useOperand.getUse() instanceof UnmodeledUseInstruction and
243+
pointOfEvaluation(useOperand, useBlock, useIndex) and
244+
defInstr = useOperand.getAnyDef() and
245+
(
246+
(
247+
defInstr instanceof PhiInstruction and
248+
defBlock = defInstr.getBlock() and
249+
defIndex = -1
250+
)
251+
or
252+
defBlock.getInstruction(defIndex) = defInstr
253+
) and
254+
not (
255+
defBlock.strictlyDominates(useBlock) or
256+
(
257+
defBlock = useBlock and
258+
defIndex < useIndex
259+
)
260+
) and
261+
message = "Operand '" + useOperand.toString() +
262+
"' is not dominated by its definition in function '$@'." and
263+
func = useOperand.getEnclosingIRFunction() and
264+
funcText = Language::getIdentityString(func.getFunction())
265+
)
266+
}
218267
}
219268

220269
/**
@@ -618,7 +667,7 @@ class FieldInstruction extends Instruction {
618667
}
619668

620669
override final string getImmediateString() {
621-
result = field.getQualifiedNameWithTypes()
670+
result = field.toString()
622671
}
623672

624673
final Language::Field getField() {
@@ -634,7 +683,7 @@ class FunctionInstruction extends Instruction {
634683
}
635684

636685
override final string getImmediateString() {
637-
result = funcSymbol.getQualifiedNameWithTypes()
686+
result = funcSymbol.toString()
638687
}
639688

640689
final Language::Function getFunctionSymbol() {
@@ -1594,7 +1643,7 @@ class CatchByTypeInstruction extends CatchInstruction {
15941643
}
15951644

15961645
final override string getImmediateString() {
1597-
result = exceptionType.getQualifiedNameWithTypes()
1646+
result = exceptionType.toString()
15981647
}
15991648

16001649
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ cached private module Cached {
6969
getInstructionTag(instruction), tag)
7070
}
7171

72-
cached Instruction getMemoryOperandDefinition(Instruction instruction, MemoryOperandTag tag, MustTotallyOverlap overlap) {
72+
cached Instruction getMemoryOperandDefinition(Instruction instruction, MemoryOperandTag tag, Overlap overlap) {
73+
overlap instanceof MustTotallyOverlap and
7374
result = getInstructionTranslatedElement(instruction).getInstructionOperand(
7475
getInstructionTag(instruction), tag)
7576
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ newtype TInstructionTag =
7878
NewObjTag() or
7979
// TODO: remove the need for indexing
8080
PointerAddTag(int index) {
81-
index in [0 .. 255]
81+
index in [0 .. 255]
8282
} or
8383
ElementsAddressTag(int index) {
84-
index in [0 .. 255]
84+
index in [0 .. 255]
8585
} or
8686
ConvertTag() or
8787
GeneratedNEQTag() or

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

Lines changed: 74 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ abstract class TranslatedCall extends TranslatedExpr {
1818
// The qualifier is evaluated before the call target, because the value of
1919
// the call target may depend on the value of the qualifier for virtual
2020
// calls.
21-
id = -2 and result = getQualifier()
22-
or
23-
id = -1 and result = getCallTarget()
24-
or
25-
result = getArgument(id)
21+
id = -2 and result = this.getQualifier() or
22+
id = -1 and result = this.getCallTarget() or
23+
result = this.getArgument(id)
2624
}
2725

28-
final override Instruction getFirstInstruction() {
29-
if exists(getQualifier())
30-
then result = getQualifier().getFirstInstruction()
31-
else result = getFirstCallTargetInstruction()
26+
override final Instruction getFirstInstruction() {
27+
if exists(this.getQualifier()) then
28+
result = this.getQualifier().getFirstInstruction()
29+
else
30+
result = this.getFirstCallTargetInstruction()
3231
}
3332

3433
override predicate hasInstruction(
@@ -60,20 +59,19 @@ abstract class TranslatedCall extends TranslatedExpr {
6059

6160
override Instruction getChildSuccessor(TranslatedElement child) {
6261
(
63-
child = getQualifier() and
64-
result = getFirstCallTargetInstruction()
65-
)
66-
or
62+
child = this.getQualifier() and
63+
result = this.getFirstCallTargetInstruction()
64+
) or
6765
(
68-
child = getCallTarget() and
69-
result = getFirstArgumentOrCallInstruction()
70-
)
71-
or
66+
child = this.getCallTarget() and
67+
result = this.getFirstArgumentOrCallInstruction()
68+
) or
7269
exists(int argIndex |
73-
child = getArgument(argIndex) and
74-
if exists(getArgument(argIndex + 1))
75-
then result = getArgument(argIndex + 1).getFirstInstruction()
76-
else result = getInstruction(CallTag())
70+
child = this.getArgument(argIndex) and
71+
if exists(this.getArgument(argIndex + 1)) then
72+
result = this.getArgument(argIndex + 1).getFirstInstruction()
73+
else
74+
result = this.getInstruction(CallTag())
7775
)
7876
}
7977

@@ -82,32 +80,43 @@ abstract class TranslatedCall extends TranslatedExpr {
8280
(
8381
(
8482
tag = CallTag() and
85-
if hasSideEffect()
86-
then result = getInstruction(CallSideEffectTag())
87-
else result = getParent().getChildSuccessor(this)
88-
)
89-
or
83+
if this.hasSideEffect() then
84+
result = this.getInstruction(CallSideEffectTag())
85+
else
86+
result = this.getParent().getChildSuccessor(this)
87+
) or
9088
(
91-
hasSideEffect() and
89+
this.hasSideEffect() and
9290
tag = CallSideEffectTag() and
93-
result = getParent().getChildSuccessor(this)
91+
result = this.getParent().getChildSuccessor(this)
9492
)
9593
)
9694
}
9795

9896
override Instruction getInstructionOperand(InstructionTag tag, OperandTag operandTag) {
9997
tag = CallTag() and
10098
(
101-
operandTag instanceof CallTargetOperandTag and
102-
result = getCallTargetResult()
103-
or
104-
operandTag instanceof ThisArgumentOperandTag and
105-
result = getQualifierResult()
106-
or
107-
exists(PositionalArgumentOperandTag argTag |
108-
argTag = operandTag and
109-
result = getArgument(argTag.getArgIndex()).getResult()
99+
tag = CallTag() and
100+
(
101+
(
102+
operandTag instanceof CallTargetOperandTag and
103+
result = this.getCallTargetResult()
104+
) or
105+
(
106+
operandTag instanceof ThisArgumentOperandTag and
107+
result = this.getQualifierResult()
108+
) or
109+
exists(PositionalArgumentOperandTag argTag |
110+
argTag = operandTag and
111+
result = this.getArgument(argTag.getArgIndex()).getResult()
112+
)
110113
)
114+
) or
115+
(
116+
tag = CallSideEffectTag() and
117+
this.hasSideEffect() and
118+
operandTag instanceof SideEffectOperandTag and
119+
result = this.getEnclosingFunction().getUnmodeledDefinitionInstruction()
111120
)
112121
or
113122
tag = CallSideEffectTag() and
@@ -118,12 +127,14 @@ abstract class TranslatedCall extends TranslatedExpr {
118127

119128
final override Type getInstructionOperandType(InstructionTag tag, TypedOperandTag operandTag) {
120129
tag = CallSideEffectTag() and
121-
hasSideEffect() and
130+
this.hasSideEffect() and
122131
operandTag instanceof SideEffectOperandTag and
123132
result instanceof Language::UnknownType
124133
}
125134

126-
final override Instruction getResult() { result = getInstruction(CallTag()) }
135+
override final Instruction getResult() {
136+
result = this.getInstruction(CallTag())
137+
}
127138

128139
/**
129140
* Gets the result type of the call.
@@ -133,7 +144,9 @@ abstract class TranslatedCall extends TranslatedExpr {
133144
/**
134145
* Holds if the call has a `this` argument.
135146
*/
136-
predicate hasQualifier() { exists(getQualifier()) }
147+
predicate hasQualifier() {
148+
exists(this.getQualifier())
149+
}
137150

138151
/**
139152
* Gets the `TranslatedExpr` for the indirect target of the call, if any.
@@ -146,15 +159,19 @@ abstract class TranslatedCall extends TranslatedExpr {
146159
* it can be overridden by a subclass for cases where there is a call target
147160
* that is not computed from an expression (e.g. a direct call).
148161
*/
149-
Instruction getFirstCallTargetInstruction() { result = getCallTarget().getFirstInstruction() }
162+
Instruction getFirstCallTargetInstruction() {
163+
result = this.getCallTarget().getFirstInstruction()
164+
}
150165

151166
/**
152167
* Gets the instruction whose result value is the target of the call. By
153168
* default, this is just the result of `getCallTarget()`, but it can be
154169
* overridden by a subclass for cases where there is a call target that is not
155170
* computed from an expression (e.g. a direct call).
156171
*/
157-
Instruction getCallTargetResult() { result = getCallTarget().getResult() }
172+
Instruction getCallTargetResult() {
173+
result = this.getCallTarget().getResult()
174+
}
158175

159176
/**
160177
* Gets the `TranslatedExpr` for the qualifier of the call (i.e. the value
@@ -168,7 +185,9 @@ abstract class TranslatedCall extends TranslatedExpr {
168185
* overridden by a subclass for cases where there is a `this` argument that is
169186
* not computed from a child expression (e.g. a constructor call).
170187
*/
171-
Instruction getQualifierResult() { result = getQualifier().getResult() }
188+
Instruction getQualifierResult() {
189+
result = this.getQualifier().getResult()
190+
}
172191

173192
/**
174193
* Gets the argument with the specified `index`. Does not include the `this`
@@ -181,9 +200,10 @@ abstract class TranslatedCall extends TranslatedExpr {
181200
* argument. Otherwise, returns the call instruction.
182201
*/
183202
final Instruction getFirstArgumentOrCallInstruction() {
184-
if hasArguments()
185-
then result = getArgument(0).getFirstInstruction()
186-
else result = getInstruction(CallTag())
203+
if this.hasArguments() then
204+
result = this.getArgument(0).getFirstInstruction()
205+
else
206+
result = this.getInstruction(CallTag())
187207
}
188208

189209
/**
@@ -199,9 +219,9 @@ abstract class TranslatedCall extends TranslatedExpr {
199219
private predicate hasSideEffect() { hasReadSideEffect() or hasWriteSideEffect() }
200220

201221
override Instruction getPrimaryInstructionForSideEffect(InstructionTag tag) {
202-
hasSideEffect() and
203-
tag = CallSideEffectTag() and
204-
result = getResult()
222+
this.hasSideEffect() and
223+
tag = CallSideEffectTag() and
224+
result = this.getResult()
205225
}
206226
}
207227

@@ -211,10 +231,10 @@ abstract class TranslatedCall extends TranslatedExpr {
211231
*/
212232
abstract class TranslatedDirectCall extends TranslatedCall {
213233
final override Instruction getFirstCallTargetInstruction() {
214-
result = getInstruction(CallTargetTag())
234+
result = this.getInstruction(CallTargetTag())
215235
}
216236

217-
final override Instruction getCallTargetResult() { result = getInstruction(CallTargetTag()) }
237+
final override Instruction getCallTargetResult() { result = this.getInstruction(CallTargetTag()) }
218238

219239
override predicate hasInstruction(
220240
Opcode opcode, InstructionTag tag, Type resultType, boolean isLValue
@@ -232,7 +252,7 @@ abstract class TranslatedDirectCall extends TranslatedCall {
232252
or
233253
tag = CallTargetTag() and
234254
kind instanceof GotoEdge and
235-
result = getFirstArgumentOrCallInstruction()
255+
result = this.getFirstArgumentOrCallInstruction()
236256
}
237257
}
238258

@@ -242,7 +262,7 @@ abstract class TranslatedDirectCall extends TranslatedCall {
242262
abstract class TranslatedCallExpr extends TranslatedNonConstantExpr, TranslatedCall {
243263
override Call expr;
244264

245-
override Type getCallResultType() { result = getResultType() }
265+
override Type getCallResultType() { result = this.getResultType() }
246266

247267
final override predicate hasArguments() { exists(expr.getArgument(0)) }
248268

@@ -290,7 +310,7 @@ class TranslatedConstructorCall extends TranslatedFunctionCall {
290310
// We must retrieve the qualifier from the context the
291311
// constructor call happened
292312
exists(StructorCallContext context |
293-
context = getParent() and
313+
context = this.getParent() and
294314
result = context.getReceiver()
295315
)
296316
}

0 commit comments

Comments
 (0)