|
1 | 1 | import SsaImplCommon
|
2 |
| -import SsaImplSpecific |
3 | 2 | private import cpp as Cpp
|
4 | 3 | private import semmle.code.cpp.ir.IR
|
5 | 4 | private import DataFlowUtil
|
6 |
| -private import DataFlowPrivate |
| 5 | +private import DataFlowImplCommon as DataFlowImplCommon |
7 | 6 | private import semmle.code.cpp.models.interfaces.Allocation as Alloc
|
8 | 7 | private import semmle.code.cpp.models.interfaces.DataFlow as DataFlow
|
9 | 8 |
|
| 9 | +private module SourceVariables { |
| 10 | + private newtype TSourceVariable = |
| 11 | + TSourceIRVariable(IRVariable var) or |
| 12 | + TSourceIRVariableIndirection(InitializeIndirectionInstruction init) |
| 13 | + |
| 14 | + abstract class SourceVariable extends TSourceVariable { |
| 15 | + IRVariable var; |
| 16 | + |
| 17 | + IRVariable getIRVariable() { result = var } |
| 18 | + |
| 19 | + abstract string toString(); |
| 20 | + |
| 21 | + predicate isIndirection() { none() } |
| 22 | + } |
| 23 | + |
| 24 | + private class SourceIRVariable extends SourceVariable, TSourceIRVariable { |
| 25 | + SourceIRVariable() { this = TSourceIRVariable(var) } |
| 26 | + |
| 27 | + override string toString() { result = this.getIRVariable().toString() } |
| 28 | + } |
| 29 | + |
| 30 | + private class SourceIRVariableIndirection extends SourceVariable, TSourceIRVariableIndirection { |
| 31 | + InitializeIndirectionInstruction init; |
| 32 | + |
| 33 | + SourceIRVariableIndirection() { |
| 34 | + this = TSourceIRVariableIndirection(init) and var = init.getIRVariable() |
| 35 | + } |
| 36 | + |
| 37 | + override string toString() { result = "*" + this.getIRVariable().toString() } |
| 38 | + |
| 39 | + override predicate isIndirection() { any() } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +import SourceVariables |
| 44 | + |
10 | 45 | cached
|
11 | 46 | private newtype TDefOrUse =
|
12 | 47 | TExplicitDef(Instruction store) { explicitWrite(_, store, _) } or
|
@@ -509,3 +544,28 @@ private module Cached {
|
509 | 544 | }
|
510 | 545 |
|
511 | 546 | import Cached
|
| 547 | + |
| 548 | +/** |
| 549 | + * Holds if the `i`'th write in block `bb` writes to the variable `v`. |
| 550 | + * `certain` is `true` if the write is guaranteed to overwrite the entire variable. |
| 551 | + */ |
| 552 | +predicate variableWrite(IRBlock bb, int i, SourceVariable v, boolean certain) { |
| 553 | + DataFlowImplCommon::forceCachingInSameStage() and |
| 554 | + exists(Def def | |
| 555 | + def.hasRankInBlock(bb, i) and |
| 556 | + v = def.getSourceVariable() and |
| 557 | + (if def.isCertain() then certain = true else certain = false) |
| 558 | + ) |
| 559 | +} |
| 560 | + |
| 561 | +/** |
| 562 | + * Holds if the `i`'th read in block `bb` reads to the variable `v`. |
| 563 | + * `certain` is `true` if the read is guaranteed. For C++, this is always the case. |
| 564 | + */ |
| 565 | +predicate variableRead(IRBlock bb, int i, SourceVariable v, boolean certain) { |
| 566 | + exists(Use use | |
| 567 | + use.hasRankInBlock(bb, i) and |
| 568 | + v = use.getSourceVariable() and |
| 569 | + certain = true |
| 570 | + ) |
| 571 | +} |
0 commit comments