Skip to content

Commit c00587d

Browse files
author
Robert Marsh
committed
C++/C#: Conflated memory as IR dump annotation
Removes the IR consistency checks for conflated memory and marks instructions that have a conflated result with a percent sign (%) instead. This avoids reimplementing part of the alias analysis logic in the consistency check.
1 parent 0e4d697 commit c00587d

30 files changed

+570
-688
lines changed

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,30 +441,6 @@ module InstructionConsistency {
441441
isOnAliasedDefinitionChain(instr.(PhiInstruction).getAnInputOperand().getAnyDef())
442442
}
443443

444-
private predicate shouldBeConflated(Instruction instr) { isOnAliasedDefinitionChain(instr) }
445-
446-
query predicate notMarkedAsConflated(
447-
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
448-
) {
449-
shouldBeConflated(instr) and
450-
not instr.isResultConflated() and
451-
message =
452-
"Instruction '" + instr.toString() +
453-
"' should be marked as having a conflated result in function '$@'." and
454-
irFunc = getInstructionIRFunction(instr, irFuncText)
455-
}
456-
457-
query predicate wronglyMarkedAsConflated(
458-
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
459-
) {
460-
instr.isResultConflated() and
461-
not shouldBeConflated(instr) and
462-
message =
463-
"Instruction '" + instr.toString() +
464-
"' should not be marked as having a conflated result in function '$@'." and
465-
irFunc = getInstructionIRFunction(instr, irFuncText)
466-
}
467-
468444
query predicate invalidOverlap(
469445
MemoryOperand useOperand, string message, OptionalIRFunction irFunc, string irFuncText
470446
) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class Instruction extends Construction::TStageInstruction {
9292
else result = "r"
9393
}
9494

95+
private string getConflationPrefix() {
96+
shouldGenerateDumpStrings() and
97+
if isResultConflated()
98+
then result = "%"
99+
else result = ""
100+
}
101+
95102
/**
96103
* Gets the zero-based index of this instruction within its block. This is
97104
* used by debugging and printing code only.
@@ -143,7 +150,7 @@ class Instruction extends Construction::TStageInstruction {
143150
*/
144151
final string getResultString() {
145152
shouldGenerateDumpStrings() and
146-
result = getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
153+
result = getConflationPrefix() + getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
147154
}
148155

149156
/**

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,30 +441,6 @@ module InstructionConsistency {
441441
isOnAliasedDefinitionChain(instr.(PhiInstruction).getAnInputOperand().getAnyDef())
442442
}
443443

444-
private predicate shouldBeConflated(Instruction instr) { isOnAliasedDefinitionChain(instr) }
445-
446-
query predicate notMarkedAsConflated(
447-
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
448-
) {
449-
shouldBeConflated(instr) and
450-
not instr.isResultConflated() and
451-
message =
452-
"Instruction '" + instr.toString() +
453-
"' should be marked as having a conflated result in function '$@'." and
454-
irFunc = getInstructionIRFunction(instr, irFuncText)
455-
}
456-
457-
query predicate wronglyMarkedAsConflated(
458-
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
459-
) {
460-
instr.isResultConflated() and
461-
not shouldBeConflated(instr) and
462-
message =
463-
"Instruction '" + instr.toString() +
464-
"' should not be marked as having a conflated result in function '$@'." and
465-
irFunc = getInstructionIRFunction(instr, irFuncText)
466-
}
467-
468444
query predicate invalidOverlap(
469445
MemoryOperand useOperand, string message, OptionalIRFunction irFunc, string irFuncText
470446
) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class Instruction extends Construction::TStageInstruction {
9292
else result = "r"
9393
}
9494

95+
private string getConflationPrefix() {
96+
shouldGenerateDumpStrings() and
97+
if isResultConflated()
98+
then result = "%"
99+
else result = ""
100+
}
101+
95102
/**
96103
* Gets the zero-based index of this instruction within its block. This is
97104
* used by debugging and printing code only.
@@ -143,7 +150,7 @@ class Instruction extends Construction::TStageInstruction {
143150
*/
144151
final string getResultString() {
145152
shouldGenerateDumpStrings() and
146-
result = getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
153+
result = getConflationPrefix() + getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
147154
}
148155

149156
/**

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -441,30 +441,6 @@ module InstructionConsistency {
441441
isOnAliasedDefinitionChain(instr.(PhiInstruction).getAnInputOperand().getAnyDef())
442442
}
443443

444-
private predicate shouldBeConflated(Instruction instr) { isOnAliasedDefinitionChain(instr) }
445-
446-
query predicate notMarkedAsConflated(
447-
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
448-
) {
449-
shouldBeConflated(instr) and
450-
not instr.isResultConflated() and
451-
message =
452-
"Instruction '" + instr.toString() +
453-
"' should be marked as having a conflated result in function '$@'." and
454-
irFunc = getInstructionIRFunction(instr, irFuncText)
455-
}
456-
457-
query predicate wronglyMarkedAsConflated(
458-
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
459-
) {
460-
instr.isResultConflated() and
461-
not shouldBeConflated(instr) and
462-
message =
463-
"Instruction '" + instr.toString() +
464-
"' should not be marked as having a conflated result in function '$@'." and
465-
irFunc = getInstructionIRFunction(instr, irFuncText)
466-
}
467-
468444
query predicate invalidOverlap(
469445
MemoryOperand useOperand, string message, OptionalIRFunction irFunc, string irFuncText
470446
) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class Instruction extends Construction::TStageInstruction {
9292
else result = "r"
9393
}
9494

95+
private string getConflationPrefix() {
96+
shouldGenerateDumpStrings() and
97+
if isResultConflated()
98+
then result = "%"
99+
else result = ""
100+
}
101+
95102
/**
96103
* Gets the zero-based index of this instruction within its block. This is
97104
* used by debugging and printing code only.
@@ -143,7 +150,7 @@ class Instruction extends Construction::TStageInstruction {
143150
*/
144151
final string getResultString() {
145152
shouldGenerateDumpStrings() and
146-
result = getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
153+
result = getConflationPrefix() + getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
147154
}
148155

149156
/**

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
switchInstructionWithoutDefaultEdge
24-
notMarkedAsConflated
25-
| ir.cpp:1237:5:1237:25 | Phi: return ... | Instruction 'Phi: return ...' should be marked as having a conflated result in function '$@'. | ir.cpp:1231:5:1231:19 | int staticLocalInit(int) | int staticLocalInit(int) |
26-
wronglyMarkedAsConflated
2724
invalidOverlap
2825
nonUniqueEnclosingIRFunction
2926
missingCanonicalLanguageType

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency_unsound.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
switchInstructionWithoutDefaultEdge
24-
notMarkedAsConflated
25-
| ir.cpp:1237:5:1237:25 | Phi: return ... | Instruction 'Phi: return ...' should be marked as having a conflated result in function '$@'. | ir.cpp:1231:5:1231:19 | int staticLocalInit(int) | int staticLocalInit(int) |
26-
wronglyMarkedAsConflated
2724
invalidOverlap
2825
nonUniqueEnclosingIRFunction
2926
missingCanonicalLanguageType

cpp/ql/test/library-tests/ir/ir/raw_consistency.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
switchInstructionWithoutDefaultEdge
24-
notMarkedAsConflated
25-
wronglyMarkedAsConflated
2624
invalidOverlap
2725
nonUniqueEnclosingIRFunction
2826
missingCanonicalLanguageType

0 commit comments

Comments
 (0)