Skip to content

Commit

Permalink
C++/C#: Add IR SSA sanity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-bartolomeo authored and dbartol committed Nov 22, 2019
1 parent bc48c25 commit 51ff262
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/identical-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '$@'."
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
private import SSAConstruction as SSA
import SSA::SSASanity
Original file line number Diff line number Diff line change
Expand Up @@ -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 '$@'."
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
private import SSAConstruction as SSA
import SSA::SSASanity
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSASanity.ql
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSASanity.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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 '$@'."
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
private import SSAConstruction as SSA
import SSA::SSASanity
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SSASanity.ql

0 comments on commit 51ff262

Please sign in to comment.