Skip to content

Commit

Permalink
C++: Move SsaConsistency to its own file
Browse files Browse the repository at this point in the history
This removes the import of the `Print` library in places that are used in
production and not just debugging.
  • Loading branch information
jketema committed Mar 20, 2023
1 parent 75746cb commit 91b0696
Show file tree
Hide file tree
Showing 37 changed files with 235 additions and 197 deletions.
5 changes: 5 additions & 0 deletions config/identical-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRBlockImports.qll",
"cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/IRBlockImports.qll"
],
"C++ IR IRConsistencyImports": [
"cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConsistencyImports.qll",
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRConsistencyImports.qll",
"cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/IRConsistencyImports.qll"
],
"C++ IR IRFunctionImports": [
"cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRFunctionImports.qll",
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRFunctionImports.qll",
Expand Down
4 changes: 4 additions & 0 deletions cpp/ql/lib/change-notes/2013-03-20-ssa-consistency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: breaking
---
* The internal `SsaConsistency` module has been moved from `SSAConstruction` to `SSAConsitency`, and the deprecated `SSAConsistency` module has been removed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
private import IR
import InstructionConsistency // module is below
import IRTypeConsistency // module is in IRType.qll
import internal.IRConsistencyImports

module InstructionConsistency {
private import internal.InstructionImports as Imports
Expand Down Expand Up @@ -28,7 +29,7 @@ module InstructionConsistency {
PresentIRFunction() { this = TPresentIRFunction(irFunc) }

override string toString() {
result = concat(Language::getIdentityString(irFunc.getFunction()), "; ")
result = concat(LanguageDebug::getIdentityString(irFunc.getFunction()), "; ")
}

override Language::Location getLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction

override Language::Location getLocation() { result = irFunc.getLocation() }

override string getLabel() { result = Language::getIdentityString(irFunc.getFunction()) }
override string getLabel() {
result = Imports::LanguageDebug::getIdentityString(irFunc.getFunction())
}

override int getOrder() {
this =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AliasAnalysis
import semmle.code.cpp.Location
import semmle.code.cpp.ir.internal.Overlap
private import semmle.code.cpp.ir.internal.IRCppLanguage as Language
private import semmle.code.cpp.Print
private import semmle.code.cpp.ir.implementation.unaliased_ssa.IR
private import semmle.code.cpp.ir.implementation.unaliased_ssa.internal.SSAConstruction as OldSsa
private import semmle.code.cpp.ir.internal.IntegerConstant as Ints
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
private import SSAConstruction as Ssa
import Ssa::SsaConsistency
import SsaConsistency
import SSAConsistencyImports

module SsaConsistency {
/**
* Holds if a `MemoryOperand` has more than one `MemoryLocation` assigned by alias analysis.
*/
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 = LanguageDebug::getIdentityString(func.getFunction()) and
message =
operand.getUse().toString() + " " + "Operand has " + locationCount.toString() +
" memory accesses in function '$@': " +
strictconcat(Alias::getOperandMemoryLocation(operand).toString(), ", ")
)
}

/**
* Holds if a `MemoryLocation` does not have an associated `VirtualVariable`.
*/
query predicate missingVirtualVariableForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
not exists(location.getVirtualVariable()) and
func = location.getIRFunction() and
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
message = "Memory location has no virtual variable in function '$@'."
}

/**
* Holds if a `MemoryLocation` is a member of more than one `VirtualVariable`.
*/
query predicate multipleVirtualVariablesForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
exists(int vvarCount |
vvarCount = strictcount(location.getVirtualVariable()) and
vvarCount > 1 and
func = location.getIRFunction() and
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
message =
"Memory location has " + vvarCount.toString() + " virtual variables in function '$@': (" +
concat(Alias::VirtualVariable vvar |
vvar = location.getVirtualVariable()
|
vvar.toString(), ", "
) + ")."
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import semmle.code.cpp.ir.implementation.raw.IR as OldIR
import AliasedSSA as Alias
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ deprecated predicate canReuseSSAForMemoryResult = canReuseSsaForMemoryResult/1;

/**
* Expose some of the internal predicates to PrintSSA.qll. We do this by publicly importing those modules in the
* `DebugSSA` module, which is then imported by PrintSSA.
* `DebugSsa` module, which is then imported by PrintSSA.
*/
module DebugSsa {
import PhiInsertion
Expand Down Expand Up @@ -1063,62 +1063,6 @@ private module CachedForDebugging {
int maxValue() { result = 2147483647 }
}

module SsaConsistency {
/**
* Holds if a `MemoryOperand` has more than one `MemoryLocation` assigned by alias analysis.
*/
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.getUse().toString() + " " + "Operand has " + locationCount.toString() +
" memory accesses in function '$@': " +
strictconcat(Alias::getOperandMemoryLocation(operand).toString(), ", ")
)
}

/**
* Holds if a `MemoryLocation` does not have an associated `VirtualVariable`.
*/
query predicate missingVirtualVariableForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
not exists(location.getVirtualVariable()) and
func = location.getIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message = "Memory location has no virtual variable in function '$@'."
}

/**
* Holds if a `MemoryLocation` is a member of more than one `VirtualVariable`.
*/
query predicate multipleVirtualVariablesForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
exists(int vvarCount |
vvarCount = strictcount(location.getVirtualVariable()) and
vvarCount > 1 and
func = location.getIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message =
"Memory location has " + vvarCount.toString() + " virtual variables in function '$@': (" +
concat(Alias::VirtualVariable vvar |
vvar = location.getVirtualVariable()
|
vvar.toString(), ", "
) + ")."
)
}
}

/** DEPRECATED: Alias for SsaConsistency */
deprecated module SSAConsistency = SsaConsistency;

/**
* Provides the portion of the parameterized IR interface that is used to construct the SSA stages
* of the IR. The raw stage of the IR does not expose these predicates.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
private import IR
import InstructionConsistency // module is below
import IRTypeConsistency // module is in IRType.qll
import internal.IRConsistencyImports

module InstructionConsistency {
private import internal.InstructionImports as Imports
Expand Down Expand Up @@ -28,7 +29,7 @@ module InstructionConsistency {
PresentIRFunction() { this = TPresentIRFunction(irFunc) }

override string toString() {
result = concat(Language::getIdentityString(irFunc.getFunction()), "; ")
result = concat(LanguageDebug::getIdentityString(irFunc.getFunction()), "; ")
}

override Language::Location getLocation() {
Expand Down
4 changes: 3 additions & 1 deletion cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/PrintIR.qll
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction

override Language::Location getLocation() { result = irFunc.getLocation() }

override string getLabel() { result = Language::getIdentityString(irFunc.getFunction()) }
override string getLabel() {
result = Imports::LanguageDebug::getIdentityString(irFunc.getFunction())
}

override int getOrder() {
this =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
private import IR
import InstructionConsistency // module is below
import IRTypeConsistency // module is in IRType.qll
import internal.IRConsistencyImports

module InstructionConsistency {
private import internal.InstructionImports as Imports
Expand Down Expand Up @@ -28,7 +29,7 @@ module InstructionConsistency {
PresentIRFunction() { this = TPresentIRFunction(irFunc) }

override string toString() {
result = concat(Language::getIdentityString(irFunc.getFunction()), "; ")
result = concat(LanguageDebug::getIdentityString(irFunc.getFunction()), "; ")
}

override Language::Location getLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction

override Language::Location getLocation() { result = irFunc.getLocation() }

override string getLabel() { result = Language::getIdentityString(irFunc.getFunction()) }
override string getLabel() {
result = Imports::LanguageDebug::getIdentityString(irFunc.getFunction())
}

override int getOrder() {
this =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
private import SSAConstruction as Ssa
import Ssa::SsaConsistency
import SsaConsistency
import SSAConsistencyImports

module SsaConsistency {
/**
* Holds if a `MemoryOperand` has more than one `MemoryLocation` assigned by alias analysis.
*/
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 = LanguageDebug::getIdentityString(func.getFunction()) and
message =
operand.getUse().toString() + " " + "Operand has " + locationCount.toString() +
" memory accesses in function '$@': " +
strictconcat(Alias::getOperandMemoryLocation(operand).toString(), ", ")
)
}

/**
* Holds if a `MemoryLocation` does not have an associated `VirtualVariable`.
*/
query predicate missingVirtualVariableForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
not exists(location.getVirtualVariable()) and
func = location.getIRFunction() and
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
message = "Memory location has no virtual variable in function '$@'."
}

/**
* Holds if a `MemoryLocation` is a member of more than one `VirtualVariable`.
*/
query predicate multipleVirtualVariablesForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
exists(int vvarCount |
vvarCount = strictcount(location.getVirtualVariable()) and
vvarCount > 1 and
func = location.getIRFunction() and
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
message =
"Memory location has " + vvarCount.toString() + " virtual variables in function '$@': (" +
concat(Alias::VirtualVariable vvar |
vvar = location.getVirtualVariable()
|
vvar.toString(), ", "
) + ")."
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import semmle.code.cpp.ir.implementation.raw.IR as OldIR
import SimpleSSA as Alias
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ deprecated predicate canReuseSSAForMemoryResult = canReuseSsaForMemoryResult/1;

/**
* Expose some of the internal predicates to PrintSSA.qll. We do this by publicly importing those modules in the
* `DebugSSA` module, which is then imported by PrintSSA.
* `DebugSsa` module, which is then imported by PrintSSA.
*/
module DebugSsa {
import PhiInsertion
Expand Down Expand Up @@ -1063,62 +1063,6 @@ private module CachedForDebugging {
int maxValue() { result = 2147483647 }
}

module SsaConsistency {
/**
* Holds if a `MemoryOperand` has more than one `MemoryLocation` assigned by alias analysis.
*/
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.getUse().toString() + " " + "Operand has " + locationCount.toString() +
" memory accesses in function '$@': " +
strictconcat(Alias::getOperandMemoryLocation(operand).toString(), ", ")
)
}

/**
* Holds if a `MemoryLocation` does not have an associated `VirtualVariable`.
*/
query predicate missingVirtualVariableForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
not exists(location.getVirtualVariable()) and
func = location.getIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message = "Memory location has no virtual variable in function '$@'."
}

/**
* Holds if a `MemoryLocation` is a member of more than one `VirtualVariable`.
*/
query predicate multipleVirtualVariablesForMemoryLocation(
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
) {
exists(int vvarCount |
vvarCount = strictcount(location.getVirtualVariable()) and
vvarCount > 1 and
func = location.getIRFunction() and
funcText = Language::getIdentityString(func.getFunction()) and
message =
"Memory location has " + vvarCount.toString() + " virtual variables in function '$@': (" +
concat(Alias::VirtualVariable vvar |
vvar = location.getVirtualVariable()
|
vvar.toString(), ", "
) + ")."
)
}
}

/** DEPRECATED: Alias for SsaConsistency */
deprecated module SSAConsistency = SsaConsistency;

/**
* Provides the portion of the parameterized IR interface that is used to construct the SSA stages
* of the IR. The raw stage of the IR does not expose these predicates.
Expand Down
Loading

0 comments on commit 91b0696

Please sign in to comment.