Skip to content

Commit 12c11d0

Browse files
authored
Merge pull request #2523 from jf205/mergeback-123-ql
Mergeback 1.23 -> master
2 parents 53988b4 + f6029bd commit 12c11d0

File tree

31 files changed

+232
-149
lines changed

31 files changed

+232
-149
lines changed

cpp/config/suites/c/correctness

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/FloatComparison.ql: /Correctness/Common Errors
2424
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/BitwiseSignCheck.ql: /Correctness/Common Errors
2525
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/BadAdditionOverflowCheck.ql: /Correctness/Common Errors
26+
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/SignedOverflowCheck.ql: /Correctness/Common Errors
27+
+ semmlecode-cpp-queries/Likely Bugs/Memory Management/PointerOverflow.ql: /Correctness/Common Errors
2628
+ semmlecode-cpp-queries/Likely Bugs/NestedLoopSameVar.ql: /Correctness/Common Errors
2729
+ semmlecode-cpp-queries/Likely Bugs/UseInOwnInitializer.ql: /Correctness/Common Errors
2830
+ semmlecode-cpp-queries/Critical/NewArrayDeleteMismatch.ql: /Correctness/Common Errors

cpp/config/suites/cpp/correctness

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/FloatComparison.ql: /Correctness/Common Errors
2525
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/BitwiseSignCheck.ql: /Correctness/Common Errors
2626
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/BadAdditionOverflowCheck.ql: /Correctness/Common Errors
27+
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/SignedOverflowCheck.ql: /Correctness/Common Errors
28+
+ semmlecode-cpp-queries/Likely Bugs/Memory Management/PointerOverflow.ql: /Correctness/Common Errors
2729
+ semmlecode-cpp-queries/Likely Bugs/NestedLoopSameVar.ql: /Correctness/Common Errors
2830
+ semmlecode-cpp-queries/Likely Bugs/UseInOwnInitializer.ql: /Correctness/Common Errors
2931
+ semmlecode-cpp-queries/Critical/NewArrayDeleteMismatch.ql: /Correctness/Common Errors

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Operand.qll

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,20 @@ cached
1111
private newtype TOperand =
1212
TRegisterOperand(Instruction useInstr, RegisterOperandTag tag, Instruction defInstr) {
1313
defInstr = Construction::getRegisterOperandDefinition(useInstr, tag) and
14-
not isInCycle(useInstr)
14+
not Construction::isInCycle(useInstr)
1515
} or
1616
TNonPhiMemoryOperand(
1717
Instruction useInstr, MemoryOperandTag tag, Instruction defInstr, Overlap overlap
1818
) {
1919
defInstr = Construction::getMemoryOperandDefinition(useInstr, tag, overlap) and
20-
not isInCycle(useInstr)
20+
not Construction::isInCycle(useInstr)
2121
} or
2222
TPhiOperand(
2323
PhiInstruction useInstr, Instruction defInstr, IRBlock predecessorBlock, Overlap overlap
2424
) {
2525
defInstr = Construction::getPhiOperandDefinition(useInstr, predecessorBlock, overlap)
2626
}
2727

28-
/** Gets a non-phi instruction that defines an operand of `instr`. */
29-
private Instruction getNonPhiOperandDef(Instruction instr) {
30-
result = Construction::getRegisterOperandDefinition(instr, _)
31-
or
32-
result = Construction::getMemoryOperandDefinition(instr, _, _)
33-
}
34-
35-
/**
36-
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
37-
* through a phi instruction and therefore should be impossible.
38-
*
39-
* If such cycles are present, either due to a programming error in the IR
40-
* generation or due to a malformed database, it can cause infinite loops in
41-
* analyses that assume a cycle-free graph of non-phi operands. Therefore it's
42-
* better to remove these operands than to leave cycles in the operand graph.
43-
*/
44-
pragma[noopt]
45-
private predicate isInCycle(Instruction instr) {
46-
instr instanceof Instruction and
47-
getNonPhiOperandDef+(instr) = instr
48-
}
49-
5028
/**
5129
* A source operand of an `Instruction`. The operand represents a value consumed by the instruction.
5230
*/

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ private module Cached {
133133
overlap instanceof MustExactlyOverlap
134134
}
135135

136+
/**
137+
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
138+
* through a phi instruction and therefore should be impossible.
139+
*
140+
* For performance reasons, this predicate is not implemented (never holds)
141+
* for the SSA stages of the IR.
142+
*/
143+
cached
144+
predicate isInCycle(Instruction instr) { none() }
145+
136146
cached
137147
Language::LanguageType getInstructionOperandType(Instruction instr, TypedOperandTag tag) {
138148
exists(OldInstruction oldInstruction, OldIR::TypedOperand oldOperand |

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Operand.qll

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,20 @@ cached
1111
private newtype TOperand =
1212
TRegisterOperand(Instruction useInstr, RegisterOperandTag tag, Instruction defInstr) {
1313
defInstr = Construction::getRegisterOperandDefinition(useInstr, tag) and
14-
not isInCycle(useInstr)
14+
not Construction::isInCycle(useInstr)
1515
} or
1616
TNonPhiMemoryOperand(
1717
Instruction useInstr, MemoryOperandTag tag, Instruction defInstr, Overlap overlap
1818
) {
1919
defInstr = Construction::getMemoryOperandDefinition(useInstr, tag, overlap) and
20-
not isInCycle(useInstr)
20+
not Construction::isInCycle(useInstr)
2121
} or
2222
TPhiOperand(
2323
PhiInstruction useInstr, Instruction defInstr, IRBlock predecessorBlock, Overlap overlap
2424
) {
2525
defInstr = Construction::getPhiOperandDefinition(useInstr, predecessorBlock, overlap)
2626
}
2727

28-
/** Gets a non-phi instruction that defines an operand of `instr`. */
29-
private Instruction getNonPhiOperandDef(Instruction instr) {
30-
result = Construction::getRegisterOperandDefinition(instr, _)
31-
or
32-
result = Construction::getMemoryOperandDefinition(instr, _, _)
33-
}
34-
35-
/**
36-
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
37-
* through a phi instruction and therefore should be impossible.
38-
*
39-
* If such cycles are present, either due to a programming error in the IR
40-
* generation or due to a malformed database, it can cause infinite loops in
41-
* analyses that assume a cycle-free graph of non-phi operands. Therefore it's
42-
* better to remove these operands than to leave cycles in the operand graph.
43-
*/
44-
pragma[noopt]
45-
private predicate isInCycle(Instruction instr) {
46-
instr instanceof Instruction and
47-
getNonPhiOperandDef+(instr) = instr
48-
}
49-
5028
/**
5129
* A source operand of an `Instruction`. The operand represents a value consumed by the instruction.
5230
*/

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,29 @@ private module Cached {
9393
overlap instanceof MustTotallyOverlap
9494
}
9595

96+
/** Gets a non-phi instruction that defines an operand of `instr`. */
97+
private Instruction getNonPhiOperandDef(Instruction instr) {
98+
result = getRegisterOperandDefinition(instr, _)
99+
or
100+
result = getMemoryOperandDefinition(instr, _, _)
101+
}
102+
103+
/**
104+
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
105+
* through a phi instruction and therefore should be impossible.
106+
*
107+
* If such cycles are present, either due to a programming error in the IR
108+
* generation or due to a malformed database, it can cause infinite loops in
109+
* analyses that assume a cycle-free graph of non-phi operands. Therefore it's
110+
* better to remove these operands than to leave cycles in the operand graph.
111+
*/
112+
pragma[noopt]
113+
cached
114+
predicate isInCycle(Instruction instr) {
115+
instr instanceof Instruction and
116+
getNonPhiOperandDef+(instr) = instr
117+
}
118+
96119
cached
97120
CppType getInstructionOperandType(Instruction instruction, TypedOperandTag tag) {
98121
// For all `LoadInstruction`s, the operand type of the `LoadOperand` is the same as

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,17 @@ abstract class TranslatedElement extends TTranslatedElement {
684684
* Gets the temporary variable generated by this element with tag `tag`.
685685
*/
686686
final IRTempVariable getTempVariable(TempVariableTag tag) {
687-
result.getAST() = getAST() and
688-
result.getTag() = tag and
689-
hasTempVariable(tag, _)
687+
exists(Locatable ast |
688+
result.getAST() = ast and
689+
result.getTag() = tag and
690+
hasTempVariableAndAST(tag, ast)
691+
)
692+
}
693+
694+
pragma[noinline]
695+
private predicate hasTempVariableAndAST(TempVariableTag tag, Locatable ast) {
696+
hasTempVariable(tag, _) and
697+
ast = getAST()
690698
}
691699

692700
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Operand.qll

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,20 @@ cached
1111
private newtype TOperand =
1212
TRegisterOperand(Instruction useInstr, RegisterOperandTag tag, Instruction defInstr) {
1313
defInstr = Construction::getRegisterOperandDefinition(useInstr, tag) and
14-
not isInCycle(useInstr)
14+
not Construction::isInCycle(useInstr)
1515
} or
1616
TNonPhiMemoryOperand(
1717
Instruction useInstr, MemoryOperandTag tag, Instruction defInstr, Overlap overlap
1818
) {
1919
defInstr = Construction::getMemoryOperandDefinition(useInstr, tag, overlap) and
20-
not isInCycle(useInstr)
20+
not Construction::isInCycle(useInstr)
2121
} or
2222
TPhiOperand(
2323
PhiInstruction useInstr, Instruction defInstr, IRBlock predecessorBlock, Overlap overlap
2424
) {
2525
defInstr = Construction::getPhiOperandDefinition(useInstr, predecessorBlock, overlap)
2626
}
2727

28-
/** Gets a non-phi instruction that defines an operand of `instr`. */
29-
private Instruction getNonPhiOperandDef(Instruction instr) {
30-
result = Construction::getRegisterOperandDefinition(instr, _)
31-
or
32-
result = Construction::getMemoryOperandDefinition(instr, _, _)
33-
}
34-
35-
/**
36-
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
37-
* through a phi instruction and therefore should be impossible.
38-
*
39-
* If such cycles are present, either due to a programming error in the IR
40-
* generation or due to a malformed database, it can cause infinite loops in
41-
* analyses that assume a cycle-free graph of non-phi operands. Therefore it's
42-
* better to remove these operands than to leave cycles in the operand graph.
43-
*/
44-
pragma[noopt]
45-
private predicate isInCycle(Instruction instr) {
46-
instr instanceof Instruction and
47-
getNonPhiOperandDef+(instr) = instr
48-
}
49-
5028
/**
5129
* A source operand of an `Instruction`. The operand represents a value consumed by the instruction.
5230
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ private module Cached {
133133
overlap instanceof MustExactlyOverlap
134134
}
135135

136+
/**
137+
* Holds if `instr` is part of a cycle in the operand graph that doesn't go
138+
* through a phi instruction and therefore should be impossible.
139+
*
140+
* For performance reasons, this predicate is not implemented (never holds)
141+
* for the SSA stages of the IR.
142+
*/
143+
cached
144+
predicate isInCycle(Instruction instr) { none() }
145+
136146
cached
137147
Language::LanguageType getInstructionOperandType(Instruction instr, TypedOperandTag tag) {
138148
exists(OldInstruction oldInstruction, OldIR::TypedOperand oldOperand |

csharp/ql/src/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ module Ssa {
17651765
*
17661766
* The write is live because of the implicit entry definition `def`, which can be
17671767
* reached using one or more calls (as indicated by `additionalCalls`), starting
1768-
* from call `c`. That is, data can flow from the write at index `i` into the the
1768+
* from call `c`. That is, data can flow from the write at index `i` into the
17691769
* callable containing `def`.
17701770
*
17711771
* Example:
@@ -2329,7 +2329,7 @@ module Ssa {
23292329
* ```
23302330
*
23312331
* If this definition is the update of `i` on line 5, then the value may be read inside
2332-
* `M2` via the the call on line 6.
2332+
* `M2` via the call on line 6.
23332333
*/
23342334
predicate isCapturedVariableDefinitionFlowIn(
23352335
ImplicitEntryDefinition def, ControlFlow::Nodes::ElementNode c, boolean additionalCalls
@@ -2356,7 +2356,7 @@ module Ssa {
23562356
* ```
23572357
*
23582358
* If this definition is the update of `i` on line 4, then the value may be read outside
2359-
* of `M2` via the the call on line 5.
2359+
* of `M2` via the call on line 5.
23602360
*/
23612361
predicate isCapturedVariableDefinitionFlowOut(
23622362
ImplicitCallDefinition cdef, boolean additionalCalls

0 commit comments

Comments
 (0)