Skip to content

Commit 9190b10

Browse files
author
Dave Bartolomeo
authored
Merge branch 'main' into post-release-prep/codeql-cli-2.16.2
2 parents 7a2332c + e596862 commit 9190b10

File tree

105 files changed

+11686
-2523
lines changed

Some content is hidden

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

105 files changed

+11686
-2523
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added an abstract class `FlowOutBarrierFunction` that can be used to block flow out of a function.

cpp/ql/lib/semmle/code/cpp/exprs/Assignment.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,15 @@ class ConditionDeclExpr extends Expr, @condition_decl {
244244

245245
/**
246246
* Gets the compiler-generated variable access that conceptually occurs after
247-
* the initialization of the declared variable.
247+
* the initialization of the declared variable, if any.
248248
*/
249-
VariableAccess getVariableAccess() { result = this.getChild(0) }
249+
VariableAccess getVariableAccess() { result = this.getExpr() }
250+
251+
/**
252+
* Gets the expression that is evaluated after the initialization of the declared
253+
* variable.
254+
*/
255+
Expr getExpr() { result = this.getChild(0) }
250256

251257
/**
252258
* Gets the expression that initializes the declared variable. This predicate

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ private import codeql.ssa.Ssa as SsaImplCommon
22
private import semmle.code.cpp.ir.IR
33
private import DataFlowUtil
44
private import DataFlowImplCommon as DataFlowImplCommon
5+
private import semmle.code.cpp.ir.dataflow.internal.ModelUtil
56
private import semmle.code.cpp.models.interfaces.Allocation as Alloc
67
private import semmle.code.cpp.models.interfaces.DataFlow as DataFlow
8+
private import semmle.code.cpp.models.interfaces.FlowOutBarrier as FOB
9+
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs as FIO
710
private import semmle.code.cpp.ir.internal.IRCppLanguage
811
private import DataFlowPrivate
912
private import ssa0.SsaInternals as SsaInternals0
@@ -784,10 +787,30 @@ private Node getAPriorDefinition(SsaDefOrUse defOrUse) {
784787
)
785788
}
786789

790+
/**
791+
* Holds if there should not be use-use flow out of `n` (or a conversion that
792+
* flows to `n`).
793+
*/
794+
private predicate modeledFlowBarrier(Node n) {
795+
exists(FIO::FunctionInput input, CallInstruction call |
796+
call.getStaticCallTarget().(FOB::FlowOutBarrierFunction).isFlowOutBarrier(input) and
797+
n = callInput(call, input)
798+
)
799+
or
800+
exists(Operand operand, Instruction instr, Node n0, int indirectionIndex |
801+
modeledFlowBarrier(n0) and
802+
nodeHasInstruction(n0, instr, indirectionIndex) and
803+
conversionFlow(operand, instr, false, _) and
804+
nodeHasOperand(n, operand, indirectionIndex)
805+
)
806+
}
807+
787808
/** Holds if there is def-use or use-use flow from `nodeFrom` to `nodeTo`. */
788809
predicate ssaFlow(Node nodeFrom, Node nodeTo) {
789810
exists(Node nFrom, boolean uncertain, SsaDefOrUse defOrUse |
790-
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain) and nodeFrom != nodeTo
811+
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain) and
812+
not modeledFlowBarrier(nFrom) and
813+
nodeFrom != nodeTo
791814
|
792815
if uncertain = true then nodeFrom = [nFrom, getAPriorDefinition(defOrUse)] else nodeFrom = nFrom
793816
)

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,13 +2125,6 @@ class ChiInstruction extends Instruction {
21252125
*/
21262126
final Instruction getPartial() { result = this.getPartialOperand().getDef() }
21272127

2128-
/**
2129-
* Gets the bit range `[startBit, endBit)` updated by the partial operand of this `ChiInstruction`, relative to the start address of the total operand.
2130-
*/
2131-
final predicate getUpdatedInterval(int startBit, int endBit) {
2132-
Construction::getIntervalUpdatedByChi(this, startBit, endBit)
2133-
}
2134-
21352128
/**
21362129
* Holds if the `ChiPartialOperand` totally, but not exactly, overlaps with the `ChiTotalOperand`.
21372130
* This means that the `ChiPartialOperand` will not override the entire memory associated with the

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,6 @@ private module Cached {
233233
)
234234
}
235235

236-
/**
237-
* Holds if the partial operand of this `ChiInstruction` updates the bit range
238-
* `[startBitOffset, endBitOffset)` of the total operand.
239-
*/
240-
cached
241-
predicate getIntervalUpdatedByChi(ChiInstruction chi, int startBitOffset, int endBitOffset) {
242-
exists(Alias::MemoryLocation location, OldInstruction oldInstruction |
243-
oldInstruction = getOldInstruction(chi.getPartial()) and
244-
location = Alias::getResultMemoryLocation(oldInstruction) and
245-
startBitOffset = Alias::getStartBitOffset(location) and
246-
endBitOffset = Alias::getEndBitOffset(location)
247-
)
248-
}
249-
250236
/**
251237
* Holds if `operand` totally overlaps with its definition and consumes the bit range
252238
* `[startBitOffset, endBitOffset)`.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,13 +2125,6 @@ class ChiInstruction extends Instruction {
21252125
*/
21262126
final Instruction getPartial() { result = this.getPartialOperand().getDef() }
21272127

2128-
/**
2129-
* Gets the bit range `[startBit, endBit)` updated by the partial operand of this `ChiInstruction`, relative to the start address of the total operand.
2130-
*/
2131-
final predicate getUpdatedInterval(int startBit, int endBit) {
2132-
Construction::getIntervalUpdatedByChi(this, startBit, endBit)
2133-
}
2134-
21352128
/**
21362129
* Holds if the `ChiPartialOperand` totally, but not exactly, overlaps with the `ChiTotalOperand`.
21372130
* This means that the `ChiPartialOperand` will not override the entire memory associated with the

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,6 @@ Instruction getMemoryOperandDefinition(
202202
none()
203203
}
204204

205-
/**
206-
* Holds if the partial operand of this `ChiInstruction` updates the bit range
207-
* `[startBitOffset, endBitOffset)` of the total operand.
208-
*/
209-
predicate getIntervalUpdatedByChi(ChiInstruction chi, int startBit, int endBit) { none() }
210-
211205
/**
212206
* Holds if the operand totally overlaps with its definition and consumes the
213207
* bit range `[startBitOffset, endBitOffset)`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ class TranslatedConditionDeclExpr extends TranslatedNonConstantExpr {
31733173
private TranslatedConditionDecl getDecl() { result = getTranslatedConditionDecl(expr) }
31743174

31753175
private TranslatedExpr getConditionExpr() {
3176-
result = getTranslatedExpr(expr.getVariableAccess().getFullyConverted())
3176+
result = getTranslatedExpr(expr.getExpr().getFullyConverted())
31773177
}
31783178
}
31793179

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,13 +2125,6 @@ class ChiInstruction extends Instruction {
21252125
*/
21262126
final Instruction getPartial() { result = this.getPartialOperand().getDef() }
21272127

2128-
/**
2129-
* Gets the bit range `[startBit, endBit)` updated by the partial operand of this `ChiInstruction`, relative to the start address of the total operand.
2130-
*/
2131-
final predicate getUpdatedInterval(int startBit, int endBit) {
2132-
Construction::getIntervalUpdatedByChi(this, startBit, endBit)
2133-
}
2134-
21352128
/**
21362129
* Holds if the `ChiPartialOperand` totally, but not exactly, overlaps with the `ChiTotalOperand`.
21372130
* This means that the `ChiPartialOperand` will not override the entire memory associated with the

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,6 @@ private module Cached {
233233
)
234234
}
235235

236-
/**
237-
* Holds if the partial operand of this `ChiInstruction` updates the bit range
238-
* `[startBitOffset, endBitOffset)` of the total operand.
239-
*/
240-
cached
241-
predicate getIntervalUpdatedByChi(ChiInstruction chi, int startBitOffset, int endBitOffset) {
242-
exists(Alias::MemoryLocation location, OldInstruction oldInstruction |
243-
oldInstruction = getOldInstruction(chi.getPartial()) and
244-
location = Alias::getResultMemoryLocation(oldInstruction) and
245-
startBitOffset = Alias::getStartBitOffset(location) and
246-
endBitOffset = Alias::getEndBitOffset(location)
247-
)
248-
}
249-
250236
/**
251237
* Holds if `operand` totally overlaps with its definition and consumes the bit range
252238
* `[startBitOffset, endBitOffset)`.

0 commit comments

Comments
 (0)