Skip to content

Commit a2741da

Browse files
author
Dave Bartolomeo
committed
C++/C#: Add sanity test for invalid overlap from getDefinitionOverlap()
The result of `getDefinitionOverlap()` should never be `MayPartiallyOverlap`, because if that were the case, we should have inserted as `Chi` instruction and hooked the definition up to that instead. There are quite a few existing failures.
1 parent 1346592 commit a2741da

26 files changed

+772
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import IRTypeSanity // module is in IRType.qll
55
module InstructionSanity {
66
private import internal.InstructionImports as Imports
77
private import Imports::OperandTag
8+
private import Imports::Overlap
89
private import internal.IRInternal
910

1011
/**
@@ -272,4 +273,18 @@ module InstructionSanity {
272273
func = switchInstr.getEnclosingIRFunction() and
273274
funcText = Language::getIdentityString(func.getFunction())
274275
}
276+
277+
query predicate invalidOverlap(
278+
MemoryOperand useOperand, string message, IRFunction func, string funcText
279+
) {
280+
exists(Overlap overlap |
281+
overlap = useOperand.getDefinitionOverlap() and
282+
overlap instanceof MayPartiallyOverlap and
283+
message =
284+
"MemoryOperand '" + useOperand.toString() + "' has a `getDefinitionOverlap()` of '" +
285+
overlap.toString() + "'." and
286+
func = useOperand.getEnclosingIRFunction() and
287+
funcText = Language::getIdentityString(func.getFunction())
288+
)
289+
}
275290
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ class PositionalArgumentOperand extends ArgumentOperand {
384384

385385
class SideEffectOperand extends TypedOperand {
386386
override SideEffectOperandTag tag;
387+
388+
override string toString() { result = "SideEffect" }
387389
}
388390

389391
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ import semmle.code.cpp.ir.implementation.IRType as IRType
33
import semmle.code.cpp.ir.implementation.MemoryAccessKind as MemoryAccessKind
44
import semmle.code.cpp.ir.implementation.Opcode as Opcode
55
import semmle.code.cpp.ir.implementation.internal.OperandTag as OperandTag
6+
import semmle.code.cpp.ir.internal.Overlap as Overlap

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import IRTypeSanity // module is in IRType.qll
55
module InstructionSanity {
66
private import internal.InstructionImports as Imports
77
private import Imports::OperandTag
8+
private import Imports::Overlap
89
private import internal.IRInternal
910

1011
/**
@@ -272,4 +273,18 @@ module InstructionSanity {
272273
func = switchInstr.getEnclosingIRFunction() and
273274
funcText = Language::getIdentityString(func.getFunction())
274275
}
276+
277+
query predicate invalidOverlap(
278+
MemoryOperand useOperand, string message, IRFunction func, string funcText
279+
) {
280+
exists(Overlap overlap |
281+
overlap = useOperand.getDefinitionOverlap() and
282+
overlap instanceof MayPartiallyOverlap and
283+
message =
284+
"MemoryOperand '" + useOperand.toString() + "' has a `getDefinitionOverlap()` of '" +
285+
overlap.toString() + "'." and
286+
func = useOperand.getEnclosingIRFunction() and
287+
funcText = Language::getIdentityString(func.getFunction())
288+
)
289+
}
275290
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ class PositionalArgumentOperand extends ArgumentOperand {
384384

385385
class SideEffectOperand extends TypedOperand {
386386
override SideEffectOperandTag tag;
387+
388+
override string toString() { result = "SideEffect" }
387389
}
388390

389391
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/InstructionImports.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ import semmle.code.cpp.ir.implementation.IRType as IRType
33
import semmle.code.cpp.ir.implementation.MemoryAccessKind as MemoryAccessKind
44
import semmle.code.cpp.ir.implementation.Opcode as Opcode
55
import semmle.code.cpp.ir.implementation.internal.OperandTag as OperandTag
6+
import semmle.code.cpp.ir.internal.Overlap as Overlap

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import IRTypeSanity // module is in IRType.qll
55
module InstructionSanity {
66
private import internal.InstructionImports as Imports
77
private import Imports::OperandTag
8+
private import Imports::Overlap
89
private import internal.IRInternal
910

1011
/**
@@ -272,4 +273,18 @@ module InstructionSanity {
272273
func = switchInstr.getEnclosingIRFunction() and
273274
funcText = Language::getIdentityString(func.getFunction())
274275
}
276+
277+
query predicate invalidOverlap(
278+
MemoryOperand useOperand, string message, IRFunction func, string funcText
279+
) {
280+
exists(Overlap overlap |
281+
overlap = useOperand.getDefinitionOverlap() and
282+
overlap instanceof MayPartiallyOverlap and
283+
message =
284+
"MemoryOperand '" + useOperand.toString() + "' has a `getDefinitionOverlap()` of '" +
285+
overlap.toString() + "'." and
286+
func = useOperand.getEnclosingIRFunction() and
287+
funcText = Language::getIdentityString(func.getFunction())
288+
)
289+
}
275290
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ class PositionalArgumentOperand extends ArgumentOperand {
384384

385385
class SideEffectOperand extends TypedOperand {
386386
override SideEffectOperandTag tag;
387+
388+
override string toString() { result = "SideEffect" }
387389
}
388390

389391
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/InstructionImports.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ import semmle.code.cpp.ir.implementation.IRType as IRType
33
import semmle.code.cpp.ir.implementation.MemoryAccessKind as MemoryAccessKind
44
import semmle.code.cpp.ir.implementation.Opcode as Opcode
55
import semmle.code.cpp.ir.implementation.internal.OperandTag as OperandTag
6+
import semmle.code.cpp.ir.internal.Overlap as Overlap

0 commit comments

Comments
 (0)