Skip to content

Commit 2968c12

Browse files
authored
Merge pull request github#12583 from jketema/move-print
C++: Move SsaConsistency to its own file
2 parents 9aa83d7 + 91b0696 commit 2968c12

37 files changed

+235
-197
lines changed

config/identical-files.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@
279279
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRBlockImports.qll",
280280
"cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/IRBlockImports.qll"
281281
],
282+
"C++ IR IRConsistencyImports": [
283+
"cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConsistencyImports.qll",
284+
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRConsistencyImports.qll",
285+
"cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/IRConsistencyImports.qll"
286+
],
282287
"C++ IR IRFunctionImports": [
283288
"cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRFunctionImports.qll",
284289
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/IRFunctionImports.qll",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: breaking
3+
---
4+
* The internal `SsaConsistency` module has been moved from `SSAConstruction` to `SSAConsitency`, and the deprecated `SSAConsistency` module has been removed.

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/IRConsistency.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
private import IR
22
import InstructionConsistency // module is below
33
import IRTypeConsistency // module is in IRType.qll
4+
import internal.IRConsistencyImports
45

56
module InstructionConsistency {
67
private import internal.InstructionImports as Imports
@@ -28,7 +29,7 @@ module InstructionConsistency {
2829
PresentIRFunction() { this = TPresentIRFunction(irFunc) }
2930

3031
override string toString() {
31-
result = concat(Language::getIdentityString(irFunc.getFunction()), "; ")
32+
result = concat(LanguageDebug::getIdentityString(irFunc.getFunction()), "; ")
3233
}
3334

3435
override Language::Location getLocation() {

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction
149149

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

152-
override string getLabel() { result = Language::getIdentityString(irFunc.getFunction()) }
152+
override string getLabel() {
153+
result = Imports::LanguageDebug::getIdentityString(irFunc.getFunction())
154+
}
153155

154156
override int getOrder() {
155157
this =

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasedSSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AliasAnalysis
2+
import semmle.code.cpp.Location
23
import semmle.code.cpp.ir.internal.Overlap
34
private import semmle.code.cpp.ir.internal.IRCppLanguage as Language
4-
private import semmle.code.cpp.Print
55
private import semmle.code.cpp.ir.implementation.unaliased_ssa.IR
66
private import semmle.code.cpp.ir.implementation.unaliased_ssa.internal.SSAConstruction as OldSsa
77
private import semmle.code.cpp.ir.internal.IntegerConstant as Ints
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
import semmle.code.cpp.ir.IRConfiguration as IRConfiguration
2+
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug
Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
private import SSAConstruction as Ssa
2-
import Ssa::SsaConsistency
1+
import SsaConsistency
2+
import SSAConsistencyImports
3+
4+
module SsaConsistency {
5+
/**
6+
* Holds if a `MemoryOperand` has more than one `MemoryLocation` assigned by alias analysis.
7+
*/
8+
query predicate multipleOperandMemoryLocations(
9+
OldIR::MemoryOperand operand, string message, OldIR::IRFunction func, string funcText
10+
) {
11+
exists(int locationCount |
12+
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
13+
locationCount > 1 and
14+
func = operand.getEnclosingIRFunction() and
15+
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
16+
message =
17+
operand.getUse().toString() + " " + "Operand has " + locationCount.toString() +
18+
" memory accesses in function '$@': " +
19+
strictconcat(Alias::getOperandMemoryLocation(operand).toString(), ", ")
20+
)
21+
}
22+
23+
/**
24+
* Holds if a `MemoryLocation` does not have an associated `VirtualVariable`.
25+
*/
26+
query predicate missingVirtualVariableForMemoryLocation(
27+
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
28+
) {
29+
not exists(location.getVirtualVariable()) and
30+
func = location.getIRFunction() and
31+
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
32+
message = "Memory location has no virtual variable in function '$@'."
33+
}
34+
35+
/**
36+
* Holds if a `MemoryLocation` is a member of more than one `VirtualVariable`.
37+
*/
38+
query predicate multipleVirtualVariablesForMemoryLocation(
39+
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
40+
) {
41+
exists(int vvarCount |
42+
vvarCount = strictcount(location.getVirtualVariable()) and
43+
vvarCount > 1 and
44+
func = location.getIRFunction() and
45+
funcText = LanguageDebug::getIdentityString(func.getFunction()) and
46+
message =
47+
"Memory location has " + vvarCount.toString() + " virtual variables in function '$@': (" +
48+
concat(Alias::VirtualVariable vvar |
49+
vvar = location.getVirtualVariable()
50+
|
51+
vvar.toString(), ", "
52+
) + ")."
53+
)
54+
}
55+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import semmle.code.cpp.ir.implementation.raw.IR as OldIR
2+
import AliasedSSA as Alias
3+
import semmle.code.cpp.ir.internal.IRCppLanguageDebug as LanguageDebug

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

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ deprecated predicate canReuseSSAForMemoryResult = canReuseSsaForMemoryResult/1;
996996

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

1066-
module SsaConsistency {
1067-
/**
1068-
* Holds if a `MemoryOperand` has more than one `MemoryLocation` assigned by alias analysis.
1069-
*/
1070-
query predicate multipleOperandMemoryLocations(
1071-
OldIR::MemoryOperand operand, string message, OldIR::IRFunction func, string funcText
1072-
) {
1073-
exists(int locationCount |
1074-
locationCount = strictcount(Alias::getOperandMemoryLocation(operand)) and
1075-
locationCount > 1 and
1076-
func = operand.getEnclosingIRFunction() and
1077-
funcText = Language::getIdentityString(func.getFunction()) and
1078-
message =
1079-
operand.getUse().toString() + " " + "Operand has " + locationCount.toString() +
1080-
" memory accesses in function '$@': " +
1081-
strictconcat(Alias::getOperandMemoryLocation(operand).toString(), ", ")
1082-
)
1083-
}
1084-
1085-
/**
1086-
* Holds if a `MemoryLocation` does not have an associated `VirtualVariable`.
1087-
*/
1088-
query predicate missingVirtualVariableForMemoryLocation(
1089-
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
1090-
) {
1091-
not exists(location.getVirtualVariable()) and
1092-
func = location.getIRFunction() and
1093-
funcText = Language::getIdentityString(func.getFunction()) and
1094-
message = "Memory location has no virtual variable in function '$@'."
1095-
}
1096-
1097-
/**
1098-
* Holds if a `MemoryLocation` is a member of more than one `VirtualVariable`.
1099-
*/
1100-
query predicate multipleVirtualVariablesForMemoryLocation(
1101-
Alias::MemoryLocation location, string message, OldIR::IRFunction func, string funcText
1102-
) {
1103-
exists(int vvarCount |
1104-
vvarCount = strictcount(location.getVirtualVariable()) and
1105-
vvarCount > 1 and
1106-
func = location.getIRFunction() and
1107-
funcText = Language::getIdentityString(func.getFunction()) and
1108-
message =
1109-
"Memory location has " + vvarCount.toString() + " virtual variables in function '$@': (" +
1110-
concat(Alias::VirtualVariable vvar |
1111-
vvar = location.getVirtualVariable()
1112-
|
1113-
vvar.toString(), ", "
1114-
) + ")."
1115-
)
1116-
}
1117-
}
1118-
1119-
/** DEPRECATED: Alias for SsaConsistency */
1120-
deprecated module SSAConsistency = SsaConsistency;
1121-
11221066
/**
11231067
* Provides the portion of the parameterized IR interface that is used to construct the SSA stages
11241068
* of the IR. The raw stage of the IR does not expose these predicates.

0 commit comments

Comments
 (0)