mirror of
https://github.com/github/codeql.git
synced 2026-04-22 15:25:18 +02:00
Merge branch 'main' into shared-bb-dominates
This commit is contained in:
@@ -67,9 +67,6 @@ signature module InputSig<LocationSig Location> {
|
||||
/** Holds if `bb` is a control-flow entry point. */
|
||||
default predicate entryBlock(BasicBlock bb) { not exists(getImmediateBasicBlockDominator(bb)) }
|
||||
|
||||
/** Holds if `bb` is a control-flow exit point. */
|
||||
default predicate exitBlock(BasicBlock bb) { not exists(getABasicBlockSuccessor(bb)) }
|
||||
|
||||
/** A variable that is captured in a closure. */
|
||||
class CapturedVariable {
|
||||
/** Gets a textual representation of this variable. */
|
||||
@@ -699,10 +696,6 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
|
||||
result = Input::getABasicBlockSuccessor(bb)
|
||||
}
|
||||
|
||||
class ExitBasicBlock extends BasicBlock {
|
||||
ExitBasicBlock() { exitBlock(this) }
|
||||
}
|
||||
|
||||
class SourceVariable = CaptureContainer;
|
||||
|
||||
predicate variableWrite(BasicBlock bb, int i, SourceVariable cc, boolean certain) {
|
||||
|
||||
@@ -60,12 +60,6 @@ signature module InputSig<LocationSig Location> {
|
||||
/** Gets an immediate successor of basic block `bb`, if any. */
|
||||
BasicBlock getABasicBlockSuccessor(BasicBlock bb);
|
||||
|
||||
/**
|
||||
* An exit basic block, that is, a basic block whose last node is
|
||||
* an exit node.
|
||||
*/
|
||||
class ExitBasicBlock extends BasicBlock;
|
||||
|
||||
/** A variable that can be SSA converted. */
|
||||
class SourceVariable {
|
||||
/** Gets a textual representation of this variable. */
|
||||
@@ -855,6 +849,9 @@ module Make<LocationSig Location, InputSig<Location> Input> {
|
||||
lastRefRedef(inp, _, _, def)
|
||||
}
|
||||
|
||||
/** Holds if `bb` is a control-flow exit point. */
|
||||
private predicate exitBlock(BasicBlock bb) { not exists(getABasicBlockSuccessor(bb)) }
|
||||
|
||||
/**
|
||||
* NB: If this predicate is exposed, it should be cached.
|
||||
*
|
||||
@@ -866,14 +863,14 @@ module Make<LocationSig Location, InputSig<Location> Input> {
|
||||
* another read.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
predicate lastRefExt(DefinitionExt def, BasicBlock bb, int i) {
|
||||
deprecated predicate lastRefExt(DefinitionExt def, BasicBlock bb, int i) {
|
||||
// Can reach another definition
|
||||
lastRefRedefExt(def, _, bb, i, _)
|
||||
or
|
||||
lastSsaRefExt(def, _, bb, i) and
|
||||
(
|
||||
// Can reach exit directly
|
||||
bb instanceof ExitBasicBlock
|
||||
exitBlock(bb)
|
||||
or
|
||||
// Can reach a block using one or more steps, where `def` is no longer live
|
||||
varBlockReachesExitExt(def, bb)
|
||||
@@ -886,14 +883,14 @@ module Make<LocationSig Location, InputSig<Location> Input> {
|
||||
* Same as `lastRefExt`, but ignores phi-reads.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
predicate lastRef(Definition def, BasicBlock bb, int i) {
|
||||
deprecated predicate lastRef(Definition def, BasicBlock bb, int i) {
|
||||
// Can reach another definition
|
||||
lastRefRedef(def, bb, i, _)
|
||||
or
|
||||
lastSsaRef(def, _, bb, i) and
|
||||
(
|
||||
// Can reach exit directly
|
||||
bb instanceof ExitBasicBlock
|
||||
exitBlock(bb)
|
||||
or
|
||||
// Can reach a block using one or more steps, where `def` is no longer live
|
||||
varBlockReachesExit(def, bb)
|
||||
|
||||
@@ -85,12 +85,13 @@ module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
|
||||
pragma[nomagic]
|
||||
private predicate typeBound(Type t) { typeFlow(_, t) }
|
||||
|
||||
private predicate hasSupertype(Type sub, Type ancestor) { sub.getASupertype() = ancestor }
|
||||
|
||||
/**
|
||||
* Gets a direct or indirect supertype of this type.
|
||||
* This does not include itself, unless this type is part of a cycle
|
||||
* in the type hierarchy.
|
||||
* Holds if `ancestor` is a direct or indirect supertype of `sub`.
|
||||
*/
|
||||
private Type getAStrictAncestor(Type sub) { result = getAnAncestor(sub.getASupertype()) }
|
||||
private predicate hasAncestorBound(Type sub, Type ancestor) =
|
||||
doublyBoundedFastTC(hasSupertype/2, typeBound/1, typeBound/1)(sub, ancestor)
|
||||
|
||||
/**
|
||||
* Holds if we have a bound for `n` that is better than `t`.
|
||||
@@ -98,10 +99,9 @@ module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
|
||||
pragma[nomagic]
|
||||
private predicate irrelevantBound(TypeFlowNode n, Type t) {
|
||||
exists(Type bound |
|
||||
typeFlow(n, bound) and
|
||||
t = getAStrictAncestor(bound) and
|
||||
typeBound(t) and
|
||||
typeFlow(n, pragma[only_bind_into](t)) and
|
||||
typeFlow(n, pragma[only_bind_into](bound)) and
|
||||
hasAncestorBound(bound, t) and
|
||||
typeFlow(n, t) and
|
||||
not getAnAncestor(t) = bound
|
||||
or
|
||||
n.getType() = pragma[only_bind_into](bound) and
|
||||
|
||||
31
shared/util/codeql/util/ReportStats.qll
Normal file
31
shared/util/codeql/util/ReportStats.qll
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Provides the `ReportStats` module for reporting database quality statistics.
|
||||
*/
|
||||
module;
|
||||
|
||||
signature module StatsSig {
|
||||
int getNumberOfOk();
|
||||
|
||||
int getNumberOfNotOk();
|
||||
|
||||
string getOkText();
|
||||
|
||||
string getNotOkText();
|
||||
}
|
||||
|
||||
module ReportStats<StatsSig Stats> {
|
||||
predicate numberOfOk(string key, int value) {
|
||||
value = Stats::getNumberOfOk() and
|
||||
key = "Number of " + Stats::getOkText()
|
||||
}
|
||||
|
||||
predicate numberOfNotOk(string key, int value) {
|
||||
value = Stats::getNumberOfNotOk() and
|
||||
key = "Number of " + Stats::getNotOkText()
|
||||
}
|
||||
|
||||
predicate percentageOfOk(string key, float value) {
|
||||
value = Stats::getNumberOfOk() * 100.0 / (Stats::getNumberOfOk() + Stats::getNumberOfNotOk()) and
|
||||
key = "Percentage of " + Stats::getOkText()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user