Skip to content

Commit dab9a85

Browse files
committed
Merge branch 'main' into rdmarsh2/swift/autoclosure-cfg
2 parents 30a9656 + 8af7277 commit dab9a85

File tree

122 files changed

+13484
-865
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+13484
-865
lines changed

cpp/BUILD.bazel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
package(default_visibility = ["//visibility:public"])
2-
31
load("@rules_pkg//:mappings.bzl", "pkg_filegroup")
42

3+
package(default_visibility = ["//visibility:public"])
4+
55
alias(
66
name = "dbscheme",
77
actual = "//cpp/ql/lib:dbscheme",
88
)
99

10+
alias(
11+
name = "dbscheme-stats",
12+
actual = "//cpp/ql/lib:dbscheme-stats",
13+
)
14+
1015
pkg_filegroup(
1116
name = "db-files",
1217
srcs = [

cpp/ql/lib/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package(default_visibility = ["//cpp:__pkg__"])
2-
31
load("@rules_pkg//:mappings.bzl", "pkg_files")
42

3+
package(default_visibility = ["//cpp:__pkg__"])
4+
55
pkg_files(
66
name = "dbscheme",
77
srcs = ["semmlecode.cpp.dbscheme"],

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,16 +1696,7 @@ private module Cached {
16961696
// Reverse flow: data that flows from the definition node back into the indirection returned
16971697
// by a function. This allows data to flow 'in' through references returned by a modeled
16981698
// function such as `operator[]`.
1699-
exists(Operand address, int indirectionIndex |
1700-
nodeHasOperand(nodeTo.(IndirectReturnOutNode), address, indirectionIndex)
1701-
|
1702-
exists(StoreInstruction store |
1703-
nodeHasInstruction(nodeFrom, store, indirectionIndex - 1) and
1704-
store.getDestinationAddressOperand() = address
1705-
)
1706-
or
1707-
Ssa::outNodeHasAddressAndIndex(nodeFrom, address, indirectionIndex)
1708-
)
1699+
reverseFlow(nodeFrom, nodeTo)
17091700
}
17101701

17111702
private predicate simpleInstructionLocalFlowStep(Operand opFrom, Instruction iTo) {
@@ -1736,6 +1727,39 @@ private module Cached {
17361727
)
17371728
)
17381729
}
1730+
1731+
private predicate reverseFlow(Node nodeFrom, Node nodeTo) {
1732+
reverseFlowOperand(nodeFrom, nodeTo)
1733+
or
1734+
reverseFlowInstruction(nodeFrom, nodeTo)
1735+
}
1736+
1737+
private predicate reverseFlowOperand(Node nodeFrom, IndirectReturnOutNode nodeTo) {
1738+
exists(Operand address, int indirectionIndex |
1739+
nodeHasOperand(nodeTo, address, indirectionIndex)
1740+
|
1741+
exists(StoreInstruction store |
1742+
nodeHasInstruction(nodeFrom, store, indirectionIndex - 1) and
1743+
store.getDestinationAddressOperand() = address
1744+
)
1745+
or
1746+
// We also want a write coming out of an `OutNode` to flow `nodeTo`.
1747+
// This is different from `reverseFlowInstruction` since `nodeFrom` can never
1748+
// be an `OutNode` when it's defined by an instruction.
1749+
Ssa::outNodeHasAddressAndIndex(nodeFrom, address, indirectionIndex)
1750+
)
1751+
}
1752+
1753+
private predicate reverseFlowInstruction(Node nodeFrom, IndirectReturnOutNode nodeTo) {
1754+
exists(Instruction address, int indirectionIndex |
1755+
nodeHasInstruction(nodeTo, address, indirectionIndex)
1756+
|
1757+
exists(StoreInstruction store |
1758+
nodeHasInstruction(nodeFrom, store, indirectionIndex - 1) and
1759+
store.getDestinationAddress() = address
1760+
)
1761+
)
1762+
}
17391763
}
17401764

17411765
import Cached

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/ProductFlow.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ module ProductFlow {
374374

375375
predicate isBarrier(DataFlow::Node node, FlowState state) { Config::isBarrier1(node, state) }
376376

377+
predicate isBarrier(DataFlow::Node node) { Config::isBarrier1(node) }
378+
377379
predicate isBarrierOut(DataFlow::Node node) { Config::isBarrierOut1(node) }
378380

379381
predicate isAdditionalFlowStep(
@@ -408,6 +410,8 @@ module ProductFlow {
408410

409411
predicate isBarrier(DataFlow::Node node, FlowState state) { Config::isBarrier2(node, state) }
410412

413+
predicate isBarrier(DataFlow::Node node) { Config::isBarrier2(node) }
414+
411415
predicate isBarrierOut(DataFlow::Node node) { Config::isBarrierOut2(node) }
412416

413417
predicate isAdditionalFlowStep(

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ private module Cached {
815815
) {
816816
indirectionIndex = [1 .. countIndirectionsForCppType(getResultLanguageType(instr))] and
817817
exists(Instruction load, Operand address |
818-
address.getDef() = instr and
818+
address = unique( | | getAUse(instr)) and
819819
isDereference(load, address, false) and
820820
instrRepr = load and
821821
indirectionIndexRepr = indirectionIndex - 1

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
88
import Imports::EdgeKind
99
private import Cached
1010

11+
/**
12+
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
13+
* sort keys of the block (derived from its first instruction)
14+
*/
15+
pragma[nomagic]
16+
private predicate blockSortKeys(
17+
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
18+
) {
19+
block.getEnclosingIRFunction() = func and
20+
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
21+
// Ensure that the block containing `EnterFunction` always comes first.
22+
if block.getFirstInstruction() instanceof EnterFunctionInstruction
23+
then sortOverride = 0
24+
else sortOverride = 1
25+
}
26+
1127
/**
1228
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
1329
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
3753
exists(IRConfiguration::IRConfiguration config |
3854
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
3955
) and
40-
this =
41-
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
42-
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
43-
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
44-
// Ensure that the block containing `EnterFunction` always comes first.
45-
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
46-
then sortOverride = 0
47-
else sortOverride = 1
48-
|
49-
funcBlock order by sortOverride, sortKey1, sortKey2
50-
)
56+
exists(IRFunction func |
57+
this =
58+
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
59+
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
60+
|
61+
funcBlock order by sortOverride, sortKey1, sortKey2
62+
)
63+
)
5164
}
5265

5366
/**

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
116116

117117
private int getLineRank() {
118118
this.shouldGenerateDumpStrings() and
119-
this =
120-
rank[result](Instruction instr |
121-
instr =
122-
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
123-
this.getLocation().getStartLine())
124-
|
125-
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
126-
)
119+
exists(IRFunction enclosing, Language::File file, int line |
120+
this =
121+
rank[result](Instruction instr |
122+
instr = getAnInstructionAtLine(enclosing, file, line)
123+
|
124+
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
125+
)
126+
)
127127
}
128128

129129
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/IRBlock.qll

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ private import internal.IRBlockImports as Imports
88
import Imports::EdgeKind
99
private import Cached
1010

11+
/**
12+
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
13+
* sort keys of the block (derived from its first instruction)
14+
*/
15+
pragma[nomagic]
16+
private predicate blockSortKeys(
17+
IRFunction func, IRBlockBase block, int sortOverride, int sortKey1, int sortKey2
18+
) {
19+
block.getEnclosingIRFunction() = func and
20+
block.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
21+
// Ensure that the block containing `EnterFunction` always comes first.
22+
if block.getFirstInstruction() instanceof EnterFunctionInstruction
23+
then sortOverride = 0
24+
else sortOverride = 1
25+
}
26+
1127
/**
1228
* A basic block in the IR. A basic block consists of a sequence of `Instructions` with the only
1329
* incoming edges at the beginning of the sequence and the only outgoing edges at the end of the
@@ -37,17 +53,14 @@ class IRBlockBase extends TIRBlock {
3753
exists(IRConfiguration::IRConfiguration config |
3854
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
3955
) and
40-
this =
41-
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
42-
funcBlock.getEnclosingFunction() = this.getEnclosingFunction() and
43-
funcBlock.getFirstInstruction().hasSortKeys(sortKey1, sortKey2) and
44-
// Ensure that the block containing `EnterFunction` always comes first.
45-
if funcBlock.getFirstInstruction() instanceof EnterFunctionInstruction
46-
then sortOverride = 0
47-
else sortOverride = 1
48-
|
49-
funcBlock order by sortOverride, sortKey1, sortKey2
50-
)
56+
exists(IRFunction func |
57+
this =
58+
rank[result + 1](IRBlock funcBlock, int sortOverride, int sortKey1, int sortKey2 |
59+
blockSortKeys(func, funcBlock, sortOverride, sortKey1, sortKey2)
60+
|
61+
funcBlock order by sortOverride, sortKey1, sortKey2
62+
)
63+
)
5164
}
5265

5366
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ class Instruction extends Construction::TStageInstruction {
116116

117117
private int getLineRank() {
118118
this.shouldGenerateDumpStrings() and
119-
this =
120-
rank[result](Instruction instr |
121-
instr =
122-
getAnInstructionAtLine(this.getEnclosingIRFunction(), this.getLocation().getFile(),
123-
this.getLocation().getStartLine())
124-
|
125-
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
126-
)
119+
exists(IRFunction enclosing, Language::File file, int line |
120+
this =
121+
rank[result](Instruction instr |
122+
instr = getAnInstructionAtLine(enclosing, file, line)
123+
|
124+
instr order by instr.getBlock().getDisplayIndex(), instr.getDisplayIndexInBlock()
125+
)
126+
)
127127
}
128128

129129
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ private module CachedForDebugging {
423423
cached
424424
predicate instructionHasSortKeys(Instruction instruction, int key1, int key2) {
425425
key1 = getInstructionTranslatedElement(instruction).getId() and
426-
getInstructionTag(instruction) =
426+
getInstructionTag(instruction) = tagByRank(key2)
427+
}
428+
429+
pragma[nomagic]
430+
private InstructionTag tagByRank(int key2) {
431+
result =
427432
rank[key2](InstructionTag tag, string tagId |
428433
tagId = getInstructionTagId(tag)
429434
|

0 commit comments

Comments
 (0)