Skip to content

Commit d24a05a

Browse files
committed
Merge branch 'main' into rdmarsh2/cpp/constant-array-overflow-tests
2 parents 60c0226 + f714de0 commit d24a05a

File tree

180 files changed

+3567
-2411
lines changed

Some content is hidden

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

180 files changed

+3567
-2411
lines changed

.github/workflows/check-implicit-this.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: "Check implicit this warnings"
22

3-
on: workflow_dispatch
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- "**qlpack.yml"
8+
branches:
9+
- main
10+
- "rc/*"
411

512
jobs:
613
check:
@@ -15,7 +22,7 @@ jobs:
1522
for pack_file in ${packs}; do
1623
option="$(yq '.warnOnImplicitThis' ${pack_file})"
1724
if [ "${option}" != "true" ]; then
18-
echo "warnOnImplicitThis property must be set to 'true' for pack ${pack_file}"
25+
echo "::error file=${pack_file}::warnOnImplicitThis property must be set to 'true' for pack ${pack_file}"
1926
EXIT_CODE=1
2027
fi
2128
done

.pre-commit-config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ repos:
55
rev: v3.2.0
66
hooks:
77
- id: trailing-whitespace
8-
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)
8+
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch
99
- id: end-of-file-fixer
10-
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)
10+
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch
1111

1212
- repo: https://github.com/pre-commit/mirrors-clang-format
1313
rev: v13.0.1
@@ -21,6 +21,11 @@ repos:
2121
- id: autopep8
2222
files: ^misc/codegen/.*\.py
2323

24+
- repo: https://github.com/warchant/pre-commit-buildifier
25+
rev: 0.0.2
26+
hooks:
27+
- id: buildifier
28+
2429
- repo: local
2530
hooks:
2631
- id: codeql-format

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ module Impl<FullStateConfigSig Config> {
460460
* The Boolean `cc` records whether the node is reached through an
461461
* argument in a call.
462462
*/
463-
pragma[assume_small_delta]
464463
private predicate fwdFlow(NodeEx node, Cc cc) {
465464
sourceNode(node, _) and
466465
if hasSourceCallCtx() then cc = true else cc = false
@@ -570,7 +569,6 @@ module Impl<FullStateConfigSig Config> {
570569
/**
571570
* Holds if `c` is the target of a store in the flow covered by `fwdFlow`.
572571
*/
573-
pragma[assume_small_delta]
574572
pragma[nomagic]
575573
private predicate fwdFlowConsCand(Content c) {
576574
exists(NodeEx mid, NodeEx node |
@@ -1216,7 +1214,6 @@ module Impl<FullStateConfigSig Config> {
12161214
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
12171215
}
12181216

1219-
pragma[assume_small_delta]
12201217
pragma[nomagic]
12211218
private predicate fwdFlow0(
12221219
NodeEx node, FlowState state, Cc cc, ParamNodeOption summaryCtx, TypOption argT,
@@ -2777,7 +2774,6 @@ module Impl<FullStateConfigSig Config> {
27772774
/**
27782775
* Gets the number of `AccessPath`s that correspond to `apa`.
27792776
*/
2780-
pragma[assume_small_delta]
27812777
private int countAps(AccessPathApprox apa) {
27822778
evalUnfold(apa, false) and
27832779
result = 1 and
@@ -2796,7 +2792,6 @@ module Impl<FullStateConfigSig Config> {
27962792
* that it is expanded to a precise head-tail representation.
27972793
*/
27982794
language[monotonicAggregates]
2799-
pragma[assume_small_delta]
28002795
private int countPotentialAps(AccessPathApprox apa) {
28012796
apa instanceof AccessPathApproxNil and result = 1
28022797
or
@@ -2833,7 +2828,6 @@ module Impl<FullStateConfigSig Config> {
28332828
}
28342829

28352830
private newtype TPathNode =
2836-
pragma[assume_small_delta]
28372831
TPathNodeMid(
28382832
NodeEx node, FlowState state, CallContext cc, SummaryCtx sc, DataFlowType t, AccessPath ap
28392833
) {
@@ -2918,7 +2912,6 @@ module Impl<FullStateConfigSig Config> {
29182912

29192913
override AccessPathFrontHead getFront() { result = TFrontHead(head_) }
29202914

2921-
pragma[assume_small_delta]
29222915
override AccessPathApproxCons getApprox() {
29232916
result = TConsNil(head_, t) and tail_ = TAccessPathNil()
29242917
or
@@ -2927,7 +2920,6 @@ module Impl<FullStateConfigSig Config> {
29272920
result = TCons1(head_, this.length())
29282921
}
29292922

2930-
pragma[assume_small_delta]
29312923
override int length() { result = 1 + tail_.length() }
29322924

29332925
private string toStringImpl(boolean needsSuffix) {
@@ -3379,7 +3371,6 @@ module Impl<FullStateConfigSig Config> {
33793371
* Holds if data may flow from `mid` to `node`. The last step in or out of
33803372
* a callable is recorded by `cc`.
33813373
*/
3382-
pragma[assume_small_delta]
33833374
pragma[nomagic]
33843375
private predicate pathStep0(
33853376
PathNodeMid mid, NodeEx node, FlowState state, CallContext cc, SummaryCtx sc, DataFlowType t,
@@ -3592,7 +3583,6 @@ module Impl<FullStateConfigSig Config> {
35923583
)
35933584
}
35943585

3595-
pragma[assume_small_delta]
35963586
pragma[nomagic]
35973587
private predicate pathThroughCallable0(
35983588
DataFlowCall call, PathNodeMid mid, ReturnKindExt kind, FlowState state, CallContext cc,

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ private module LambdaFlow {
187187
else any()
188188
}
189189

190-
pragma[assume_small_delta]
191190
pragma[nomagic]
192191
predicate revLambdaFlow0(
193192
DataFlowCall lambdaCall, LambdaCallKind kind, Node node, DataFlowType t, boolean toReturn,
@@ -274,7 +273,6 @@ private module LambdaFlow {
274273
)
275274
}
276275

277-
pragma[assume_small_delta]
278276
pragma[nomagic]
279277
predicate revLambdaFlowOut(
280278
DataFlowCall lambdaCall, LambdaCallKind kind, TReturnPositionSimple pos, DataFlowType t,

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ module Impl<FullStateConfigSig Config> {
460460
* The Boolean `cc` records whether the node is reached through an
461461
* argument in a call.
462462
*/
463-
pragma[assume_small_delta]
464463
private predicate fwdFlow(NodeEx node, Cc cc) {
465464
sourceNode(node, _) and
466465
if hasSourceCallCtx() then cc = true else cc = false
@@ -570,7 +569,6 @@ module Impl<FullStateConfigSig Config> {
570569
/**
571570
* Holds if `c` is the target of a store in the flow covered by `fwdFlow`.
572571
*/
573-
pragma[assume_small_delta]
574572
pragma[nomagic]
575573
private predicate fwdFlowConsCand(Content c) {
576574
exists(NodeEx mid, NodeEx node |
@@ -1216,7 +1214,6 @@ module Impl<FullStateConfigSig Config> {
12161214
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
12171215
}
12181216

1219-
pragma[assume_small_delta]
12201217
pragma[nomagic]
12211218
private predicate fwdFlow0(
12221219
NodeEx node, FlowState state, Cc cc, ParamNodeOption summaryCtx, TypOption argT,
@@ -2777,7 +2774,6 @@ module Impl<FullStateConfigSig Config> {
27772774
/**
27782775
* Gets the number of `AccessPath`s that correspond to `apa`.
27792776
*/
2780-
pragma[assume_small_delta]
27812777
private int countAps(AccessPathApprox apa) {
27822778
evalUnfold(apa, false) and
27832779
result = 1 and
@@ -2796,7 +2792,6 @@ module Impl<FullStateConfigSig Config> {
27962792
* that it is expanded to a precise head-tail representation.
27972793
*/
27982794
language[monotonicAggregates]
2799-
pragma[assume_small_delta]
28002795
private int countPotentialAps(AccessPathApprox apa) {
28012796
apa instanceof AccessPathApproxNil and result = 1
28022797
or
@@ -2833,7 +2828,6 @@ module Impl<FullStateConfigSig Config> {
28332828
}
28342829

28352830
private newtype TPathNode =
2836-
pragma[assume_small_delta]
28372831
TPathNodeMid(
28382832
NodeEx node, FlowState state, CallContext cc, SummaryCtx sc, DataFlowType t, AccessPath ap
28392833
) {
@@ -2918,7 +2912,6 @@ module Impl<FullStateConfigSig Config> {
29182912

29192913
override AccessPathFrontHead getFront() { result = TFrontHead(head_) }
29202914

2921-
pragma[assume_small_delta]
29222915
override AccessPathApproxCons getApprox() {
29232916
result = TConsNil(head_, t) and tail_ = TAccessPathNil()
29242917
or
@@ -2927,7 +2920,6 @@ module Impl<FullStateConfigSig Config> {
29272920
result = TCons1(head_, this.length())
29282921
}
29292922

2930-
pragma[assume_small_delta]
29312923
override int length() { result = 1 + tail_.length() }
29322924

29332925
private string toStringImpl(boolean needsSuffix) {
@@ -3379,7 +3371,6 @@ module Impl<FullStateConfigSig Config> {
33793371
* Holds if data may flow from `mid` to `node`. The last step in or out of
33803372
* a callable is recorded by `cc`.
33813373
*/
3382-
pragma[assume_small_delta]
33833374
pragma[nomagic]
33843375
private predicate pathStep0(
33853376
PathNodeMid mid, NodeEx node, FlowState state, CallContext cc, SummaryCtx sc, DataFlowType t,
@@ -3592,7 +3583,6 @@ module Impl<FullStateConfigSig Config> {
35923583
)
35933584
}
35943585

3595-
pragma[assume_small_delta]
35963586
pragma[nomagic]
35973587
private predicate pathThroughCallable0(
35983588
DataFlowCall call, PathNodeMid mid, ReturnKindExt kind, FlowState state, CallContext cc,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ private module LambdaFlow {
187187
else any()
188188
}
189189

190-
pragma[assume_small_delta]
191190
pragma[nomagic]
192191
predicate revLambdaFlow0(
193192
DataFlowCall lambdaCall, LambdaCallKind kind, Node node, DataFlowType t, boolean toReturn,
@@ -274,7 +273,6 @@ private module LambdaFlow {
274273
)
275274
}
276275

277-
pragma[assume_small_delta]
278276
pragma[nomagic]
279277
predicate revLambdaFlowOut(
280278
DataFlowCall lambdaCall, LambdaCallKind kind, TReturnPositionSimple pos, DataFlowType t,

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

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ private class PrimaryArgumentNode extends ArgumentNode, OperandNode {
321321

322322
private class SideEffectArgumentNode extends ArgumentNode, SideEffectOperandNode {
323323
override predicate argumentOf(DataFlowCall dfCall, ArgumentPosition pos) {
324-
this.getCallInstruction() = dfCall and
325-
pos.(IndirectionPosition).getArgumentIndex() = this.getArgumentIndex() and
326-
super.hasAddressOperandAndIndirectionIndex(_, pos.(IndirectionPosition).getIndirectionIndex())
324+
exists(int indirectionIndex |
325+
pos = TIndirectionPosition(argumentIndex, pragma[only_bind_into](indirectionIndex)) and
326+
this.getCallInstruction() = dfCall and
327+
super.hasAddressOperandAndIndirectionIndex(_, pragma[only_bind_into](indirectionIndex))
328+
)
327329
}
328330
}
329331

@@ -854,7 +856,73 @@ class DataFlowCall extends CallInstruction {
854856
Function getEnclosingCallable() { result = this.getEnclosingFunction() }
855857
}
856858

857-
predicate isUnreachableInCall(Node n, DataFlowCall call) { none() } // stub implementation
859+
module IsUnreachableInCall {
860+
private import semmle.code.cpp.ir.ValueNumbering
861+
private import semmle.code.cpp.controlflow.IRGuards as G
862+
863+
private class ConstantIntegralTypeArgumentNode extends PrimaryArgumentNode {
864+
int value;
865+
866+
ConstantIntegralTypeArgumentNode() {
867+
value = op.getDef().(IntegerConstantInstruction).getValue().toInt()
868+
}
869+
870+
int getValue() { result = value }
871+
}
872+
873+
pragma[nomagic]
874+
private predicate ensuresEq(Operand left, Operand right, int k, IRBlock block, boolean areEqual) {
875+
any(G::IRGuardCondition guard).ensuresEq(left, right, k, block, areEqual)
876+
}
877+
878+
pragma[nomagic]
879+
private predicate ensuresLt(Operand left, Operand right, int k, IRBlock block, boolean areEqual) {
880+
any(G::IRGuardCondition guard).ensuresLt(left, right, k, block, areEqual)
881+
}
882+
883+
predicate isUnreachableInCall(Node n, DataFlowCall call) {
884+
exists(
885+
DirectParameterNode paramNode, ConstantIntegralTypeArgumentNode arg,
886+
IntegerConstantInstruction constant, int k, Operand left, Operand right, IRBlock block
887+
|
888+
// arg flows into `paramNode`
889+
DataFlowImplCommon::viableParamArg(call, paramNode, arg) and
890+
left = constant.getAUse() and
891+
right = valueNumber(paramNode.getInstruction()).getAUse() and
892+
block = n.getBasicBlock()
893+
|
894+
// and there's a guard condition which ensures that the result of `left == right + k` is `areEqual`
895+
exists(boolean areEqual |
896+
ensuresEq(pragma[only_bind_into](left), pragma[only_bind_into](right),
897+
pragma[only_bind_into](k), pragma[only_bind_into](block), areEqual)
898+
|
899+
// this block ensures that left = right + k, but it holds that `left != right + k`
900+
areEqual = true and
901+
constant.getValue().toInt() != arg.getValue() + k
902+
or
903+
// this block ensures that or `left != right + k`, but it holds that `left = right + k`
904+
areEqual = false and
905+
constant.getValue().toInt() = arg.getValue() + k
906+
)
907+
or
908+
// or there's a guard condition which ensures that the result of `left < right + k` is `isLessThan`
909+
exists(boolean isLessThan |
910+
ensuresLt(pragma[only_bind_into](left), pragma[only_bind_into](right),
911+
pragma[only_bind_into](k), pragma[only_bind_into](block), isLessThan)
912+
|
913+
isLessThan = true and
914+
// this block ensures that `left < right + k`, but it holds that `left >= right + k`
915+
constant.getValue().toInt() >= arg.getValue() + k
916+
or
917+
// this block ensures that `left >= right + k`, but it holds that `left < right + k`
918+
isLessThan = false and
919+
constant.getValue().toInt() < arg.getValue() + k
920+
)
921+
)
922+
}
923+
}
924+
925+
import IsUnreachableInCall
858926

859927
int accessPathLimit() { result = 5 }
860928

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ module ProductFlow {
359359
Config::isSinkPair(node1.getNode(), node1.getState(), node2.getNode(), node2.getState())
360360
}
361361

362-
pragma[assume_small_delta]
363362
pragma[nomagic]
364363
private predicate fwdReachableInterprocEntry(Flow1::PathNode node1, Flow2::PathNode node2) {
365364
isSourcePair(node1, node2)
@@ -396,7 +395,6 @@ module ProductFlow {
396395
fwdIsSuccessorExit(pragma[only_bind_into](mid1), pragma[only_bind_into](mid2), succ1, succ2)
397396
}
398397

399-
pragma[assume_small_delta]
400398
private predicate fwdIsSuccessor(
401399
Flow1::PathNode pred1, Flow2::PathNode pred2, Flow1::PathNode succ1, Flow2::PathNode succ2
402400
) {
@@ -406,7 +404,6 @@ module ProductFlow {
406404
)
407405
}
408406

409-
pragma[assume_small_delta]
410407
pragma[nomagic]
411408
private predicate revReachableInterprocEntry(Flow1::PathNode node1, Flow2::PathNode node2) {
412409
fwdReachableInterprocEntry(node1, node2) and

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,6 @@ private module Cached {
588588
)
589589
}
590590

591-
pragma[assume_small_delta]
592591
private predicate convertsIntoArgumentRev(Instruction instr) {
593592
convertsIntoArgumentFwd(instr) and
594593
(

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ private predicate binaryValueNumber0(
176176
)
177177
}
178178

179-
pragma[assume_small_delta]
180179
private predicate binaryValueNumber(
181180
BinaryInstruction instr, IRFunction irFunc, Opcode opcode, TValueNumber leftOperand,
182181
TValueNumber rightOperand
@@ -202,7 +201,6 @@ private predicate pointerArithmeticValueNumber0(
202201
)
203202
}
204203

205-
pragma[assume_small_delta]
206204
private predicate pointerArithmeticValueNumber(
207205
PointerArithmeticInstruction instr, IRFunction irFunc, Opcode opcode, int elementSize,
208206
TValueNumber leftOperand, TValueNumber rightOperand
@@ -249,7 +247,6 @@ private predicate loadTotalOverlapValueNumber0(
249247
)
250248
}
251249

252-
pragma[assume_small_delta]
253250
private predicate loadTotalOverlapValueNumber(
254251
LoadTotalOverlapInstruction instr, IRFunction irFunc, IRType type, TValueNumber memOperand,
255252
TValueNumber operand

0 commit comments

Comments
 (0)