Skip to content

Commit 44a9cf9

Browse files
author
Stephan Brandauer
authored
Merge branch 'main' into kaeluka/add-provenance-to-metadata
2 parents 808dc3e + 20254c3 commit 44a9cf9

File tree

444 files changed

+9438
-7342
lines changed

Some content is hidden

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

444 files changed

+9438
-7342
lines changed

config/identical-files.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImpl5.qll",
2323
"go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl1.qll",
2424
"go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl2.qll",
25-
"go/ql/lib/semmle/go/dataflow/internal/DataFlowImplForStringsNewReplacer.qll",
2625
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl1.qll",
2726
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl2.qll",
2827
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl3.qll",
@@ -572,4 +571,4 @@
572571
"python/ql/lib/semmle/python/security/internal/EncryptionKeySizes.qll",
573572
"java/ql/lib/semmle/code/java/security/internal/EncryptionKeySizes.qll"
574573
]
575-
}
574+
}

cpp/ql/lib/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 0.9.0
2+
3+
### Breaking Changes
4+
5+
* The `shouldPrintFunction` predicate from `PrintAstConfiguration` has been replaced by `shouldPrintDeclaration`. Users should now override `shouldPrintDeclaration` if they want to limit the declarations that should be printed.
6+
* The `shouldPrintFunction` predicate from `PrintIRConfiguration` has been replaced by `shouldPrintDeclaration`. Users should now override `shouldPrintDeclaration` if they want to limit the declarations that should be printed.
7+
8+
### Major Analysis Improvements
9+
10+
* The `PrintAST` library now also prints global and namespace variables and their initializers.
11+
12+
### Minor Analysis Improvements
13+
14+
* The `_Float128x` type is no longer exposed as a builtin type. As this type could not occur any code base, this should only affect queries that explicitly looked at the builtin types.
15+
116
## 0.8.1
217

318
### Deprecated APIs

cpp/ql/lib/change-notes/2023-07-20-print-global-variables.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/ql/lib/change-notes/2023-08-07-removal-of-float128x.md

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
---
2-
category: breaking
3-
---
1+
## 0.9.0
2+
3+
### Breaking Changes
4+
45
* The `shouldPrintFunction` predicate from `PrintAstConfiguration` has been replaced by `shouldPrintDeclaration`. Users should now override `shouldPrintDeclaration` if they want to limit the declarations that should be printed.
56
* The `shouldPrintFunction` predicate from `PrintIRConfiguration` has been replaced by `shouldPrintDeclaration`. Users should now override `shouldPrintDeclaration` if they want to limit the declarations that should be printed.
7+
8+
### Major Analysis Improvements
9+
10+
* The `PrintAST` library now also prints global and namespace variables and their initializers.
11+
12+
### Minor Analysis Improvements
13+
14+
* The `_Float128x` type is no longer exposed as a builtin type. As this type could not occur any code base, this should only affect queries that explicitly looked at the builtin types.

cpp/ql/lib/codeql-pack.release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 0.8.1
2+
lastReleaseVersion: 0.9.0

cpp/ql/lib/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cpp-all
2-
version: 0.8.2-dev
2+
version: 0.9.1-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,25 @@ private module Cached {
15201520
)
15211521
}
15221522

1523+
/**
1524+
* Holds if `operand.getDef() = instr`, but there exists a `StoreInstruction` that
1525+
* writes to an address that is equivalent to the value computed by `instr` in
1526+
* between `instr` and `operand`, and therefore there should not be flow from `*instr`
1527+
* to `*operand`.
1528+
*/
1529+
pragma[nomagic]
1530+
private predicate isStoredToBetween(Instruction instr, Operand operand) {
1531+
simpleOperandLocalFlowStep(pragma[only_bind_into](instr), pragma[only_bind_into](operand)) and
1532+
exists(StoreInstruction store, IRBlock block, int storeIndex, int instrIndex, int operandIndex |
1533+
store.getDestinationAddress() = instr and
1534+
block.getInstruction(storeIndex) = store and
1535+
block.getInstruction(instrIndex) = instr and
1536+
block.getInstruction(operandIndex) = operand.getUse() and
1537+
instrIndex < storeIndex and
1538+
storeIndex < operandIndex
1539+
)
1540+
}
1541+
15231542
private predicate indirectionInstructionFlow(
15241543
RawIndirectInstruction nodeFrom, IndirectOperand nodeTo
15251544
) {
@@ -1529,7 +1548,8 @@ private module Cached {
15291548
simpleOperandLocalFlowStep(pragma[only_bind_into](instr), pragma[only_bind_into](operand))
15301549
|
15311550
hasOperandAndIndex(nodeTo, operand, pragma[only_bind_into](indirectionIndex)) and
1532-
hasInstructionAndIndex(nodeFrom, instr, pragma[only_bind_into](indirectionIndex))
1551+
hasInstructionAndIndex(nodeFrom, instr, pragma[only_bind_into](indirectionIndex)) and
1552+
not isStoredToBetween(instr, operand)
15331553
)
15341554
}
15351555

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

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
9494

9595
cached
9696
private newtype TDefOrUseImpl =
97-
TDefImpl(Operand address, int indirectionIndex) {
98-
exists(Instruction base | isDef(_, _, address, base, _, indirectionIndex) |
97+
TDefImpl(BaseSourceVariableInstruction base, Operand address, int indirectionIndex) {
98+
isDef(_, _, address, base, _, indirectionIndex) and
99+
(
99100
// We only include the definition if the SSA pruning stage
100101
// concluded that the definition is live after the write.
101102
any(SsaInternals0::Def def).getAddressOperand() = address
@@ -105,8 +106,8 @@ private newtype TDefOrUseImpl =
105106
base.(VariableAddressInstruction).getAstVariable() instanceof GlobalLikeVariable
106107
)
107108
} or
108-
TUseImpl(Operand operand, int indirectionIndex) {
109-
isUse(_, operand, _, _, indirectionIndex) and
109+
TUseImpl(BaseSourceVariableInstruction base, Operand operand, int indirectionIndex) {
110+
isUse(_, operand, base, _, indirectionIndex) and
110111
not isDef(_, _, operand, _, _, _)
111112
} or
112113
TGlobalUse(GlobalLikeVariable v, IRFunction f, int indirectionIndex) {
@@ -193,7 +194,7 @@ abstract private class DefOrUseImpl extends TDefOrUseImpl {
193194

194195
/**
195196
* Gets the instruction that computes the base of this definition or use.
196-
* This is always a `VariableAddressInstruction` or an `AllocationInstruction`.
197+
* This is always a `VariableAddressInstruction` or an `CallInstruction`.
197198
*/
198199
abstract BaseSourceVariableInstruction getBase();
199200

@@ -265,15 +266,17 @@ abstract class DefImpl extends DefOrUseImpl {
265266
}
266267

267268
private class DirectDef extends DefImpl, TDefImpl {
268-
DirectDef() { this = TDefImpl(address, ind) }
269+
BaseSourceVariableInstruction base;
270+
271+
DirectDef() { this = TDefImpl(base, address, ind) }
269272

270-
override BaseSourceVariableInstruction getBase() { isDef(_, _, address, result, _, _) }
273+
override BaseSourceVariableInstruction getBase() { result = base }
271274

272-
override int getIndirection() { isDef(_, _, address, _, result, ind) }
275+
override int getIndirection() { isDef(_, _, address, base, result, ind) }
273276

274-
override Node0Impl getValue() { isDef(_, result, address, _, _, _) }
277+
override Node0Impl getValue() { isDef(_, result, address, base, _, _) }
275278

276-
override predicate isCertain() { isDef(true, _, address, _, _, ind) }
279+
override predicate isCertain() { isDef(true, _, address, base, _, ind) }
277280
}
278281

279282
private class IteratorDef extends DefImpl, TIteratorDef {
@@ -316,57 +319,52 @@ abstract class UseImpl extends DefOrUseImpl {
316319

317320
abstract private class OperandBasedUse extends UseImpl {
318321
Operand operand;
322+
BaseSourceVariableInstruction base;
319323

320324
bindingset[ind]
321325
OperandBasedUse() { any() }
322326

323327
final override predicate hasIndexInBlock(IRBlock block, int index) {
324328
// See the comment in `ssa0`'s `OperandBasedUse` for an explanation of this
325329
// predicate's implementation.
326-
exists(BaseSourceVariableInstruction base | base = this.getBase() |
327-
if base.getAst() = any(Cpp::PostfixCrementOperation c).getOperand()
328-
then
329-
exists(Operand op, int indirectionIndex, int indirection |
330-
indirectionIndex = this.getIndirectionIndex() and
331-
indirection = this.getIndirection() and
332-
op =
333-
min(Operand cand, int i |
334-
isUse(_, cand, base, indirection, indirectionIndex) and
335-
block.getInstruction(i) = cand.getUse()
336-
|
337-
cand order by i
338-
) and
339-
block.getInstruction(index) = op.getUse()
340-
)
341-
else operand.getUse() = block.getInstruction(index)
342-
)
330+
if base.getAst() = any(Cpp::PostfixCrementOperation c).getOperand()
331+
then
332+
exists(Operand op, int indirectionIndex, int indirection |
333+
indirectionIndex = this.getIndirectionIndex() and
334+
indirection = this.getIndirection() and
335+
op =
336+
min(Operand cand, int i |
337+
isUse(_, cand, base, indirection, indirectionIndex) and
338+
block.getInstruction(i) = cand.getUse()
339+
|
340+
cand order by i
341+
) and
342+
block.getInstruction(index) = op.getUse()
343+
)
344+
else operand.getUse() = block.getInstruction(index)
343345
}
344346

347+
final override BaseSourceVariableInstruction getBase() { result = base }
348+
345349
final Operand getOperand() { result = operand }
346350

347351
final override Cpp::Location getLocation() { result = operand.getLocation() }
348352
}
349353

350354
private class DirectUse extends OperandBasedUse, TUseImpl {
351-
DirectUse() { this = TUseImpl(operand, ind) }
352-
353-
override int getIndirection() { isUse(_, operand, _, result, ind) }
355+
DirectUse() { this = TUseImpl(base, operand, ind) }
354356

355-
override BaseSourceVariableInstruction getBase() { isUse(_, operand, result, _, ind) }
357+
override int getIndirection() { isUse(_, operand, base, result, ind) }
356358

357-
override predicate isCertain() { isUse(true, operand, _, _, ind) }
359+
override predicate isCertain() { isUse(true, operand, base, _, ind) }
358360

359361
override Node getNode() { nodeHasOperand(result, operand, ind) }
360362
}
361363

362364
private class IteratorUse extends OperandBasedUse, TIteratorUse {
363-
BaseSourceVariableInstruction container;
364-
365-
IteratorUse() { this = TIteratorUse(operand, container, ind) }
365+
IteratorUse() { this = TIteratorUse(operand, base, ind) }
366366

367-
override int getIndirection() { isIteratorUse(container, operand, result, ind) }
368-
369-
override BaseSourceVariableInstruction getBase() { result = container }
367+
override int getIndirection() { isIteratorUse(base, operand, result, ind) }
370368

371369
override predicate isCertain() { none() }
372370

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import DataFlowImplCommon as DataFlowImplCommon
66
private import DataFlowUtil
77
private import semmle.code.cpp.models.interfaces.PointerWrapper
88
private import DataFlowPrivate
9+
private import semmle.code.cpp.ir.ValueNumbering
910

1011
/**
1112
* Holds if `operand` is an operand that is not used by the dataflow library.
@@ -146,14 +147,6 @@ int countIndirectionsForCppType(LanguageType langType) {
146147
)
147148
}
148149

149-
/**
150-
* A `CallInstruction` that calls an allocation function such
151-
* as `malloc` or `operator new`.
152-
*/
153-
class AllocationInstruction extends CallInstruction {
154-
AllocationInstruction() { this.getStaticCallTarget() instanceof Cpp::AllocationFunction }
155-
}
156-
157150
private predicate isIndirectionType(Type t) { t instanceof Indirection }
158151

159152
private predicate hasUnspecifiedBaseType(Indirection t, Type base) {
@@ -368,7 +361,7 @@ newtype TBaseSourceVariable =
368361
// Each IR variable gets its own source variable
369362
TBaseIRVariable(IRVariable var) or
370363
// Each allocation gets its own source variable
371-
TBaseCallVariable(AllocationInstruction call)
364+
TBaseCallVariable(CallInstruction call) { not call.getResultIRType() instanceof IRVoidType }
372365

373366
abstract private class AbstractBaseSourceVariable extends TBaseSourceVariable {
374367
/** Gets a textual representation of this element. */
@@ -396,11 +389,11 @@ class BaseIRVariable extends AbstractBaseSourceVariable, TBaseIRVariable {
396389
}
397390

398391
class BaseCallVariable extends AbstractBaseSourceVariable, TBaseCallVariable {
399-
AllocationInstruction call;
392+
CallInstruction call;
400393

401394
BaseCallVariable() { this = TBaseCallVariable(call) }
402395

403-
AllocationInstruction getCallInstruction() { result = call }
396+
CallInstruction getCallInstruction() { result = call }
404397

405398
override string toString() { result = call.toString() }
406399

@@ -504,8 +497,7 @@ private class BaseIRVariableInstruction extends BaseSourceVariableInstruction,
504497
override BaseIRVariable getBaseSourceVariable() { result.getIRVariable() = this.getIRVariable() }
505498
}
506499

507-
private class BaseAllocationInstruction extends BaseSourceVariableInstruction, AllocationInstruction
508-
{
500+
private class BaseCallInstruction extends BaseSourceVariableInstruction, CallInstruction {
509501
override BaseCallVariable getBaseSourceVariable() { result.getCallInstruction() = this }
510502
}
511503

@@ -873,7 +865,7 @@ private module Cached {
873865
* to a specific address.
874866
*/
875867
private predicate isCertainAddress(Operand operand) {
876-
operand.getDef() instanceof VariableAddressInstruction
868+
valueNumberOfOperand(operand).getAnInstruction() instanceof VariableAddressInstruction
877869
or
878870
operand.getType() instanceof Cpp::ReferenceType
879871
}

0 commit comments

Comments
 (0)