Merge pull request #12583 from jketema/move-print

C++: Move SsaConsistency to its own file
This commit is contained in:
Jeroen Ketema
2023-03-20 13:41:29 +01:00
committed by GitHub
37 changed files with 235 additions and 197 deletions

View File

@@ -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.

View File

@@ -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
@@ -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() {

View File

@@ -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 =

View File

@@ -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

View File

@@ -0,0 +1 @@
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

View File

@@ -1 +1,2 @@
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

View File

@@ -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(), ", "
) + ")."
)
}
}

View File

@@ -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

View File

@@ -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
@@ -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.

View File

@@ -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
@@ -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() {

View File

@@ -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 =

View File

@@ -0,0 +1 @@
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

View File

@@ -1 +1,2 @@
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

View File

@@ -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
@@ -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() {

View File

@@ -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 =

View File

@@ -0,0 +1 @@
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

View File

@@ -1 +1,2 @@
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

View File

@@ -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(), ", "
) + ")."
)
}
}

View File

@@ -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

View File

@@ -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
@@ -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.

View File

@@ -1,5 +1,4 @@
private import cpp
private import semmle.code.cpp.Print
private import semmle.code.cpp.ir.implementation.IRType
private import semmle.code.cpp.ir.implementation.raw.internal.IRConstruction::Raw as Raw
@@ -538,12 +537,14 @@ CppType getCanonicalOpaqueType(Type tag, int byteSize) {
}
/**
* Gets a string that uniquely identifies an `IROpaqueType` tag. This may be different from the usual
* `toString()` of the tag in order to ensure uniqueness.
* Gets a string that uniquely identifies an `IROpaqueType` tag. Using `toString` here might
* not be sufficient to ensure uniqueness, but suffices for our current debugging purposes.
* To ensure uniqueness `getOpaqueTagIdentityString` from `semmle.code.cpp.Print` could be used,
* but that comes at the cost of importing all the `Dump` classes defined in that library.
*/
string getOpaqueTagIdentityString(Type tag) {
hasOpaqueType(tag, _) and
result = getTypeIdentityString(tag)
result = tag.toString()
}
module LanguageTypeConsistency {

View File

@@ -1,5 +1,4 @@
private import cpp as Cpp
private import semmle.code.cpp.Print as Print
private import IRUtilities
private import semmle.code.cpp.ir.implementation.IRType
private import semmle.code.cpp.ir.implementation.raw.internal.IRConstruction as IRConstruction
@@ -65,8 +64,6 @@ class Expr = Cpp::Expr;
class Class = Cpp::Class; // Used for inheritance conversions
predicate getIdentityString = Print::getIdentityString/1;
predicate hasCaseEdge(string minValue, string maxValue) { hasCaseEdge(_, minValue, maxValue) }
predicate hasPositionalArgIndex(int argIndex) {

View File

@@ -0,0 +1,3 @@
private import semmle.code.cpp.Print as Print
predicate getIdentityString = Print::getIdentityString/1;