Skip to content

Commit 28c2aca

Browse files
authored
Merge pull request github#3505 from dbartol/github/codeql-c-analysis-team/69
C++/C#: Remove `UnmodeledDefinition` instruction
2 parents 0a8b3ad + d6ef94a commit 28c2aca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5811
-6492
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/MemoryAccessKind.qll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,3 @@ class ChiTotalMemoryAccess extends MemoryAccessKind, TChiTotalMemoryAccess {
9292
class ChiPartialMemoryAccess extends MemoryAccessKind, TChiPartialMemoryAccess {
9393
override string toString() { result = "chi(partial)" }
9494
}
95-
96-
/**
97-
* The operand accesses memory not modeled in SSA. Used only on the result of
98-
* `UnmodeledDefinition` and on the operands of `UnmodeledUse`.
99-
*/
100-
class UnmodeledMemoryAccess extends MemoryAccessKind, TUnmodeledMemoryAccess {
101-
override string toString() { result = "unmodeled" }
102-
}

cpp/ql/src/semmle/code/cpp/ir/implementation/Opcode.qll

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ private newtype TOpcode =
6060
TThrowValue() or
6161
TReThrow() or
6262
TUnwind() or
63-
TUnmodeledDefinition() or
6463
TAliasedDefinition() or
6564
TInitializeNonLocal() or
6665
TAliasedUse() or
@@ -578,14 +577,6 @@ module Opcode {
578577
final override string toString() { result = "Unwind" }
579578
}
580579

581-
class UnmodeledDefinition extends Opcode, TUnmodeledDefinition {
582-
final override string toString() { result = "UnmodeledDefinition" }
583-
584-
final override MemoryAccessKind getWriteMemoryAccess() {
585-
result instanceof UnmodeledMemoryAccess
586-
}
587-
}
588-
589580
class AliasedDefinition extends Opcode, TAliasedDefinition {
590581
final override string toString() { result = "AliasedDefinition" }
591582

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRConsistency.qll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ module InstructionConsistency {
149149
}
150150

151151
/**
152-
* Holds if a memory operand is connected to a definition with an unmodeled result, other than
153-
* `UnmodeledDefinition` itself.
152+
* Holds if a memory operand is connected to a definition with an unmodeled result.
154153
*/
155154
query predicate memoryOperandDefinitionIsUnmodeled(
156155
Instruction instr, string message, IRFunction func, string funcText
@@ -159,9 +158,7 @@ module InstructionConsistency {
159158
operand = instr.getAnOperand() and
160159
def = operand.getAnyDef() and
161160
not def.isResultModeled() and
162-
not def instanceof UnmodeledDefinitionInstruction and
163-
message =
164-
"Memory operand definition has unmodeled result, but is not the `UnmodeledDefinition` instruction in function '$@'" and
161+
message = "Memory operand definition has unmodeled result in function '$@'" and
165162
func = instr.getEnclosingIRFunction() and
166163
funcText = Language::getIdentityString(func.getFunction())
167164
)
@@ -257,7 +254,6 @@ module InstructionConsistency {
257254
Operand useOperand, string message, IRFunction func, string funcText
258255
) {
259256
exists(IRBlock useBlock, int useIndex, Instruction defInstr, IRBlock defBlock, int defIndex |
260-
not defInstr instanceof UnmodeledDefinitionInstruction and
261257
pointOfEvaluation(useOperand, useBlock, useIndex) and
262258
defInstr = useOperand.getAnyDef() and
263259
(
@@ -306,8 +302,6 @@ module InstructionConsistency {
306302
private predicate shouldBeConflated(Instruction instr) {
307303
isOnAliasedDefinitionChain(instr)
308304
or
309-
instr instanceof UnmodeledDefinitionInstruction
310-
or
311305
instr.getOpcode() instanceof Opcode::InitializeNonLocal
312306
}
313307

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRFunction.qll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ class IRFunction extends TIRFunction {
4040
result.getEnclosingIRFunction() = this
4141
}
4242

43-
pragma[noinline]
44-
final UnmodeledDefinitionInstruction getUnmodeledDefinitionInstruction() {
45-
result.getEnclosingIRFunction() = this
46-
}
47-
4843
/**
4944
* Gets the single return instruction for this function.
5045
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,10 +1229,6 @@ class CatchAnyInstruction extends CatchInstruction {
12291229
CatchAnyInstruction() { getOpcode() instanceof Opcode::CatchAny }
12301230
}
12311231

1232-
class UnmodeledDefinitionInstruction extends Instruction {
1233-
UnmodeledDefinitionInstruction() { getOpcode() instanceof Opcode::UnmodeledDefinition }
1234-
}
1235-
12361232
/**
12371233
* An instruction that initializes all escaped memory.
12381234
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Operand.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,17 @@ class Operand extends TOperand {
147147
* For example: `this:r3_5`
148148
*/
149149
final string getDumpString() {
150-
result = getDumpLabel() + getInexactSpecifier() + getAnyDef().getResultId()
150+
result = getDumpLabel() + getInexactSpecifier() + getDefinitionId()
151+
}
152+
153+
/**
154+
* Gets a string containing the identifier of the definition of this use, or `m?` if the
155+
* definition is not modeled in SSA.
156+
*/
157+
private string getDefinitionId() {
158+
result = getAnyDef().getResultId()
159+
or
160+
not exists(getAnyDef()) and result = "m?"
151161
}
152162

153163
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ private module Cached {
6767

6868
cached
6969
predicate hasConflatedMemoryResult(Instruction instruction) {
70-
instruction instanceof UnmodeledDefinitionInstruction
71-
or
7270
instruction instanceof AliasedDefinitionInstruction
7371
or
7472
instruction.getOpcode() instanceof Opcode::InitializeNonLocal
@@ -127,14 +125,7 @@ private module Cached {
127125
oldInstruction = getOldInstruction(instruction) and
128126
oldOperand = oldInstruction.getAnOperand() and
129127
tag = oldOperand.getOperandTag() and
130-
(
131-
if exists(Alias::getOperandMemoryLocation(oldOperand))
132-
then hasMemoryOperandDefinition(oldInstruction, oldOperand, overlap, result)
133-
else (
134-
result = instruction.getEnclosingIRFunction().getUnmodeledDefinitionInstruction() and
135-
overlap instanceof MustTotallyOverlap
136-
)
137-
)
128+
hasMemoryOperandDefinition(oldInstruction, oldOperand, overlap, result)
138129
)
139130
or
140131
instruction = Chi(getOldInstruction(result)) and

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRConsistency.qll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ module InstructionConsistency {
149149
}
150150

151151
/**
152-
* Holds if a memory operand is connected to a definition with an unmodeled result, other than
153-
* `UnmodeledDefinition` itself.
152+
* Holds if a memory operand is connected to a definition with an unmodeled result.
154153
*/
155154
query predicate memoryOperandDefinitionIsUnmodeled(
156155
Instruction instr, string message, IRFunction func, string funcText
@@ -159,9 +158,7 @@ module InstructionConsistency {
159158
operand = instr.getAnOperand() and
160159
def = operand.getAnyDef() and
161160
not def.isResultModeled() and
162-
not def instanceof UnmodeledDefinitionInstruction and
163-
message =
164-
"Memory operand definition has unmodeled result, but is not the `UnmodeledDefinition` instruction in function '$@'" and
161+
message = "Memory operand definition has unmodeled result in function '$@'" and
165162
func = instr.getEnclosingIRFunction() and
166163
funcText = Language::getIdentityString(func.getFunction())
167164
)
@@ -257,7 +254,6 @@ module InstructionConsistency {
257254
Operand useOperand, string message, IRFunction func, string funcText
258255
) {
259256
exists(IRBlock useBlock, int useIndex, Instruction defInstr, IRBlock defBlock, int defIndex |
260-
not defInstr instanceof UnmodeledDefinitionInstruction and
261257
pointOfEvaluation(useOperand, useBlock, useIndex) and
262258
defInstr = useOperand.getAnyDef() and
263259
(
@@ -306,8 +302,6 @@ module InstructionConsistency {
306302
private predicate shouldBeConflated(Instruction instr) {
307303
isOnAliasedDefinitionChain(instr)
308304
or
309-
instr instanceof UnmodeledDefinitionInstruction
310-
or
311305
instr.getOpcode() instanceof Opcode::InitializeNonLocal
312306
}
313307

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRFunction.qll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ class IRFunction extends TIRFunction {
4040
result.getEnclosingIRFunction() = this
4141
}
4242

43-
pragma[noinline]
44-
final UnmodeledDefinitionInstruction getUnmodeledDefinitionInstruction() {
45-
result.getEnclosingIRFunction() = this
46-
}
47-
4843
/**
4944
* Gets the single return instruction for this function.
5045
*/

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,10 +1229,6 @@ class CatchAnyInstruction extends CatchInstruction {
12291229
CatchAnyInstruction() { getOpcode() instanceof Opcode::CatchAny }
12301230
}
12311231

1232-
class UnmodeledDefinitionInstruction extends Instruction {
1233-
UnmodeledDefinitionInstruction() { getOpcode() instanceof Opcode::UnmodeledDefinition }
1234-
}
1235-
12361232
/**
12371233
* An instruction that initializes all escaped memory.
12381234
*/

0 commit comments

Comments
 (0)