C++/C#: Add IR SSA sanity tests

This commit is contained in:
Dave Bartolomeo
2019-08-14 13:53:48 -07:00
committed by Dave Bartolomeo
parent bc48c25690
commit 51ff262cbc
16 changed files with 77 additions and 0 deletions

View File

@@ -143,6 +143,11 @@
"cpp/ql/src/semmle/code/cpp/ir/implementation/Opcode.qll",
"csharp/ql/src/semmle/code/csharp/ir/implementation/Opcode.qll"
],
"IR SSASanity": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSASanity.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSASanity.qll",
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSASanity.qll"
],
"C++ IR InstructionImports": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/InstructionImports.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/InstructionImports.qll",

View File

@@ -865,3 +865,16 @@ private module CachedForDebugging {
result.getTag() = var.getTag()
}
}
module SSASanity {
query predicate multipleOperandMemoryLocations(OldIR::MemoryOperand operand, string message,
OldIR::IRFunction func, string funcText) {
exists(int locationCount |
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
locationCount > 1 and
func = operand.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message = "Operand has " + locationCount.toString() + " memory accesses in function '$@'."
)
}
}

View File

@@ -0,0 +1,8 @@
/**
* @name Aliased SSA Sanity Check
* @description Performs sanity checks on the SSA construction. This query should have no results.
* @kind table
* @id cpp/aliased-ssa-sanity-check
*/
import SSASanity

View File

@@ -0,0 +1,2 @@
private import SSAConstruction as SSA
import SSA::SSASanity

View File

@@ -865,3 +865,16 @@ private module CachedForDebugging {
result.getTag() = var.getTag()
}
}
module SSASanity {
query predicate multipleOperandMemoryLocations(OldIR::MemoryOperand operand, string message,
OldIR::IRFunction func, string funcText) {
exists(int locationCount |
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
locationCount > 1 and
func = operand.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message = "Operand has " + locationCount.toString() + " memory accesses in function '$@'."
)
}
}

View File

@@ -0,0 +1,8 @@
/**
* @name Unaliased SSA Sanity Check
* @description Performs sanity checks on the SSA construction. This query should have no results.
* @kind table
* @id cpp/unaliased-ssa-sanity-check
*/
import SSASanity

View File

@@ -0,0 +1,2 @@
private import SSAConstruction as SSA
import SSA::SSASanity

View File

@@ -0,0 +1 @@
semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSASanity.ql

View File

@@ -0,0 +1 @@
semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSASanity.ql

View File

@@ -865,3 +865,16 @@ private module CachedForDebugging {
result.getTag() = var.getTag()
}
}
module SSASanity {
query predicate multipleOperandMemoryLocations(OldIR::MemoryOperand operand, string message,
OldIR::IRFunction func, string funcText) {
exists(int locationCount |
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
locationCount > 1 and
func = operand.getEnclosingIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message = "Operand has " + locationCount.toString() + " memory accesses in function '$@'."
)
}
}

View File

@@ -0,0 +1,8 @@
/**
* @name Unaliased SSA Sanity Check
* @description Performs sanity checks on the SSA construction. This query should have no results.
* @kind table
* @id csharp/unaliased-ssa-sanity-check
*/
import SSASanity

View File

@@ -0,0 +1,2 @@
private import SSAConstruction as SSA
import SSA::SSASanity

View File

@@ -0,0 +1 @@
semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSASanity.ql