Skip to content

Commit 51ff262

Browse files
dave-bartolomeoDave Bartolomeo
authored andcommitted
C++/C#: Add IR SSA sanity tests
1 parent bc48c25 commit 51ff262

File tree

16 files changed

+77
-0
lines changed

16 files changed

+77
-0
lines changed

config/identical-files.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@
143143
"cpp/ql/src/semmle/code/cpp/ir/implementation/Opcode.qll",
144144
"csharp/ql/src/semmle/code/csharp/ir/implementation/Opcode.qll"
145145
],
146+
"IR SSASanity": [
147+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSASanity.qll",
148+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSASanity.qll",
149+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSASanity.qll"
150+
],
146151
"C++ IR InstructionImports": [
147152
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/InstructionImports.qll",
148153
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/InstructionImports.qll",

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,16 @@ private module CachedForDebugging {
865865
result.getTag() = var.getTag()
866866
}
867867
}
868+
869+
module SSASanity {
870+
query predicate multipleOperandMemoryLocations(OldIR::MemoryOperand operand, string message,
871+
OldIR::IRFunction func, string funcText) {
872+
exists(int locationCount |
873+
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
874+
locationCount > 1 and
875+
func = operand.getEnclosingIRFunction() and
876+
funcText = Language::getIdentityString(func.getFunction()) and
877+
message = "Operand has " + locationCount.toString() + " memory accesses in function '$@'."
878+
)
879+
}
880+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @name Aliased SSA Sanity Check
3+
* @description Performs sanity checks on the SSA construction. This query should have no results.
4+
* @kind table
5+
* @id cpp/aliased-ssa-sanity-check
6+
*/
7+
8+
import SSASanity
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
private import SSAConstruction as SSA
2+
import SSA::SSASanity

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,16 @@ private module CachedForDebugging {
865865
result.getTag() = var.getTag()
866866
}
867867
}
868+
869+
module SSASanity {
870+
query predicate multipleOperandMemoryLocations(OldIR::MemoryOperand operand, string message,
871+
OldIR::IRFunction func, string funcText) {
872+
exists(int locationCount |
873+
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
874+
locationCount > 1 and
875+
func = operand.getEnclosingIRFunction() and
876+
funcText = Language::getIdentityString(func.getFunction()) and
877+
message = "Operand has " + locationCount.toString() + " memory accesses in function '$@'."
878+
)
879+
}
880+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @name Unaliased SSA Sanity Check
3+
* @description Performs sanity checks on the SSA construction. This query should have no results.
4+
* @kind table
5+
* @id cpp/unaliased-ssa-sanity-check
6+
*/
7+
8+
import SSASanity
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
private import SSAConstruction as SSA
2+
import SSA::SSASanity

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_ssa_sanity.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSASanity.ql

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_ssa_sanity.expected

Whitespace-only changes.

0 commit comments

Comments
 (0)