Skip to content

Commit c81ea9d

Browse files
authored
Merge branch 'main' into swift/rename-functions
2 parents 5838c5d + e9f1e99 commit c81ea9d

File tree

142 files changed

+10221
-2811
lines changed

Some content is hidden

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

142 files changed

+10221
-2811
lines changed

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,17 @@ module Impl<FullStateConfigSig Config> {
30313031
this instanceof PathNodeSinkGroup
30323032
}
30333033

3034+
private string ppType() {
3035+
this instanceof PathNodeSink and result = ""
3036+
or
3037+
this.(PathNodeMid).getAp() instanceof AccessPathNil and result = ""
3038+
or
3039+
exists(DataFlowType t | t = this.(PathNodeMid).getAp().getHead().getContainerType() |
3040+
// The `concat` becomes "" if `ppReprType` has no result.
3041+
result = concat(" : " + ppReprType(t))
3042+
)
3043+
}
3044+
30343045
private string ppAp() {
30353046
this instanceof PathNodeSink and result = ""
30363047
or
@@ -3046,14 +3057,14 @@ module Impl<FullStateConfigSig Config> {
30463057
}
30473058

30483059
/** Gets a textual representation of this element. */
3049-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
3060+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
30503061

30513062
/**
30523063
* Gets a textual representation of this element, including a textual
30533064
* representation of the call context.
30543065
*/
30553066
string toStringWithContext() {
3056-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
3067+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
30573068
}
30583069

30593070
/**
@@ -3998,14 +4009,14 @@ module Impl<FullStateConfigSig Config> {
39984009
*/
39994010
class PartialPathNode extends TPartialPathNode {
40004011
/** Gets a textual representation of this element. */
4001-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
4012+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
40024013

40034014
/**
40044015
* Gets a textual representation of this element, including a textual
40054016
* representation of the call context.
40064017
*/
40074018
string toStringWithContext() {
4008-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
4019+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
40094020
}
40104021

40114022
/**
@@ -4046,6 +4057,19 @@ module Impl<FullStateConfigSig Config> {
40464057
*/
40474058
int getSinkDistance() { result = distSink(this.getNodeEx().getEnclosingCallable()) }
40484059

4060+
private string ppType() {
4061+
this instanceof PartialPathNodeRev and result = ""
4062+
or
4063+
this.(PartialPathNodeFwd).getAp() instanceof PartialAccessPathNil and result = ""
4064+
or
4065+
exists(DataFlowType t |
4066+
t = this.(PartialPathNodeFwd).getAp().(PartialAccessPathCons).getType()
4067+
|
4068+
// The `concat` becomes "" if `ppReprType` has no result.
4069+
result = concat(" : " + ppReprType(t))
4070+
)
4071+
}
4072+
40494073
private string ppAp() {
40504074
exists(string s |
40514075
s = this.(PartialPathNodeFwd).getAp().toString() or

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,17 @@ module Impl<FullStateConfigSig Config> {
30313031
this instanceof PathNodeSinkGroup
30323032
}
30333033

3034+
private string ppType() {
3035+
this instanceof PathNodeSink and result = ""
3036+
or
3037+
this.(PathNodeMid).getAp() instanceof AccessPathNil and result = ""
3038+
or
3039+
exists(DataFlowType t | t = this.(PathNodeMid).getAp().getHead().getContainerType() |
3040+
// The `concat` becomes "" if `ppReprType` has no result.
3041+
result = concat(" : " + ppReprType(t))
3042+
)
3043+
}
3044+
30343045
private string ppAp() {
30353046
this instanceof PathNodeSink and result = ""
30363047
or
@@ -3046,14 +3057,14 @@ module Impl<FullStateConfigSig Config> {
30463057
}
30473058

30483059
/** Gets a textual representation of this element. */
3049-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
3060+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
30503061

30513062
/**
30523063
* Gets a textual representation of this element, including a textual
30533064
* representation of the call context.
30543065
*/
30553066
string toStringWithContext() {
3056-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
3067+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
30573068
}
30583069

30593070
/**
@@ -3998,14 +4009,14 @@ module Impl<FullStateConfigSig Config> {
39984009
*/
39994010
class PartialPathNode extends TPartialPathNode {
40004011
/** Gets a textual representation of this element. */
4001-
string toString() { result = this.getNodeEx().toString() + this.ppAp() }
4012+
string toString() { result = this.getNodeEx().toString() + this.ppType() + this.ppAp() }
40024013

40034014
/**
40044015
* Gets a textual representation of this element, including a textual
40054016
* representation of the call context.
40064017
*/
40074018
string toStringWithContext() {
4008-
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
4019+
result = this.getNodeEx().toString() + this.ppType() + this.ppAp() + this.ppCtx()
40094020
}
40104021

40114022
/**
@@ -4046,6 +4057,19 @@ module Impl<FullStateConfigSig Config> {
40464057
*/
40474058
int getSinkDistance() { result = distSink(this.getNodeEx().getEnclosingCallable()) }
40484059

4060+
private string ppType() {
4061+
this instanceof PartialPathNodeRev and result = ""
4062+
or
4063+
this.(PartialPathNodeFwd).getAp() instanceof PartialAccessPathNil and result = ""
4064+
or
4065+
exists(DataFlowType t |
4066+
t = this.(PartialPathNodeFwd).getAp().(PartialAccessPathCons).getType()
4067+
|
4068+
// The `concat` becomes "" if `ppReprType` has no result.
4069+
result = concat(" : " + ppReprType(t))
4070+
)
4071+
}
4072+
40494073
private string ppAp() {
40504074
exists(string s |
40514075
s = this.(PartialPathNodeFwd).getAp().toString() or

cpp/ql/lib/semmle/code/cpp/ir/implementation/internal/IRFunctionBase.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private import IRFunctionBaseInternal
66

77
private newtype TIRFunction =
88
TFunctionIRFunction(Language::Function func) { IRConstruction::Raw::functionHasIR(func) } or
9-
TVarInitIRFunction(Language::GlobalVariable var) { IRConstruction::Raw::varHasIRFunc(var) }
9+
TVarInitIRFunction(Language::Variable var) { IRConstruction::Raw::varHasIRFunc(var) }
1010

1111
/**
1212
* The IR for a function. This base class contains only the predicates that are the same between all

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ module Raw {
3737
predicate functionHasIR(Function func) { exists(getTranslatedFunction(func)) }
3838

3939
cached
40-
predicate varHasIRFunc(GlobalOrNamespaceVariable var) {
40+
predicate varHasIRFunc(Variable var) {
41+
(
42+
var instanceof GlobalOrNamespaceVariable
43+
or
44+
not var.isFromUninstantiatedTemplate(_) and
45+
var instanceof StaticInitializedStaticLocalVariable
46+
) and
4147
var.hasInitializer() and
4248
(
4349
not var.getType().isDeeplyConst()
@@ -75,9 +81,10 @@ module Raw {
7581
}
7682

7783
cached
78-
predicate hasDynamicInitializationFlag(Function func, StaticLocalVariable var, CppType type) {
84+
predicate hasDynamicInitializationFlag(
85+
Function func, RuntimeInitializedStaticLocalVariable var, CppType type
86+
) {
7987
var.getFunction() = func and
80-
var.hasDynamicInitialization() and
8188
type = getBoolType()
8289
}
8390

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ abstract class TranslatedSideEffects extends TranslatedElement {
180180
/** DEPRECATED: Alias for getAst */
181181
deprecated override Locatable getAST() { result = getAst() }
182182

183-
final override Declaration getFunction() { result = getExpr().getEnclosingDeclaration() }
183+
final override Declaration getFunction() { result = getEnclosingDeclaration(getExpr()) }
184184

185185
final override TranslatedElement getChild(int i) {
186186
result =

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ abstract class TranslatedCondition extends TranslatedElement {
2828

2929
final Expr getExpr() { result = expr }
3030

31-
final override Function getFunction() { result = expr.getEnclosingFunction() }
31+
final override Declaration getFunction() {
32+
result = getEnclosingFunction(expr) or
33+
result = getEnclosingVariable(expr).(GlobalOrNamespaceVariable) or
34+
result = getEnclosingVariable(expr).(StaticInitializedStaticLocalVariable)
35+
}
3236

3337
final Type getResultType() { result = expr.getUnspecifiedType() }
3438
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ abstract class TranslatedDeclarationEntry extends TranslatedElement, TTranslated
2828

2929
TranslatedDeclarationEntry() { this = TTranslatedDeclarationEntry(entry) }
3030

31-
final override Function getFunction() {
32-
exists(DeclStmt stmt |
33-
stmt = entry.getStmt() and
31+
final override Declaration getFunction() {
32+
exists(DeclStmt stmt | stmt = entry.getStmt() |
33+
result = entry.getDeclaration().(StaticInitializedStaticLocalVariable)
34+
or
35+
result = entry.getDeclaration().(GlobalOrNamespaceVariable)
36+
or
37+
not entry.getDeclaration() instanceof StaticInitializedStaticLocalVariable and
38+
not entry.getDeclaration() instanceof GlobalOrNamespaceVariable and
3439
result = stmt.getEnclosingFunction()
3540
)
3641
}
@@ -237,7 +242,7 @@ class TranslatedStaticLocalVariableInitialization extends TranslatedElement,
237242

238243
final override LocalVariable getVariable() { result = var }
239244

240-
final override Function getFunction() { result = var.getFunction() }
245+
final override Declaration getFunction() { result = var.getFunction() }
241246
}
242247

243248
TranslatedConditionDecl getTranslatedConditionDecl(ConditionDeclExpr expr) {
@@ -264,7 +269,7 @@ class TranslatedConditionDecl extends TranslatedLocalVariableDeclaration, TTrans
264269
/** DEPRECATED: Alias for getAst */
265270
deprecated override Locatable getAST() { result = getAst() }
266271

267-
override Function getFunction() { result = conditionDeclExpr.getEnclosingFunction() }
272+
override Declaration getFunction() { result = getEnclosingFunction(conditionDeclExpr) }
268273

269274
override LocalVariable getVariable() { result = conditionDeclExpr.getVariable() }
270275
}

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ private predicate ignoreExprAndDescendants(Expr expr) {
6262
// constant value.
6363
isIRConstant(getRealParent(expr))
6464
or
65-
// Only translate the initializer of a static local if it uses run-time data.
66-
// Otherwise the initializer does not run in function scope.
67-
exists(Initializer init, StaticStorageDurationVariable var |
68-
init = var.getInitializer() and
69-
not var.hasDynamicInitialization() and
70-
expr = init.getExpr().getFullyConverted() and
71-
not var instanceof GlobalOrNamespaceVariable
72-
)
73-
or
7465
// Ignore descendants of `__assume` expressions, since we translated these to `NoOp`.
7566
getRealParent(expr) instanceof AssumeExpr
7667
or
@@ -118,8 +109,8 @@ private predicate ignoreExprOnly(Expr expr) {
118109
// should not be translated.
119110
exists(NewOrNewArrayExpr new | expr = new.getAllocatorCall().getArgument(0))
120111
or
121-
not translateFunction(expr.getEnclosingFunction()) and
122-
not Raw::varHasIRFunc(expr.getEnclosingVariable())
112+
not translateFunction(getEnclosingFunction(expr)) and
113+
not Raw::varHasIRFunc(getEnclosingVariable(expr))
123114
or
124115
// We do not yet translate destructors properly, so for now we ignore the
125116
// destructor call. We do, however, translate the expression being
@@ -438,6 +429,17 @@ predicate hasTranslatedSyntheticTemporaryObject(Expr expr) {
438429
not expr.hasLValueToRValueConversion()
439430
}
440431

432+
class StaticInitializedStaticLocalVariable extends StaticLocalVariable {
433+
StaticInitializedStaticLocalVariable() {
434+
this.hasInitializer() and
435+
not this.hasDynamicInitialization()
436+
}
437+
}
438+
439+
class RuntimeInitializedStaticLocalVariable extends StaticLocalVariable {
440+
RuntimeInitializedStaticLocalVariable() { this.hasDynamicInitialization() }
441+
}
442+
441443
/**
442444
* Holds if the specified `DeclarationEntry` needs an IR translation. An IR translation is only
443445
* necessary for automatic local variables, or for static local variables with dynamic
@@ -453,7 +455,7 @@ private predicate translateDeclarationEntry(IRDeclarationEntry entry) {
453455
not var.isStatic()
454456
or
455457
// Ignore static variables unless they have a dynamic initializer.
456-
var.(StaticLocalVariable).hasDynamicInitialization()
458+
var instanceof RuntimeInitializedStaticLocalVariable
457459
)
458460
)
459461
}
@@ -755,7 +757,7 @@ newtype TTranslatedElement =
755757
} or
756758
// The side effect that initializes newly-allocated memory.
757759
TTranslatedAllocationSideEffect(AllocationExpr expr) { not ignoreSideEffects(expr) } or
758-
TTranslatedGlobalOrNamespaceVarInit(GlobalOrNamespaceVariable var) { Raw::varHasIRFunc(var) }
760+
TTranslatedStaticStorageDurationVarInit(Variable var) { Raw::varHasIRFunc(var) }
759761

760762
/**
761763
* Gets the index of the first explicitly initialized element in `initList`
@@ -1043,6 +1045,6 @@ abstract class TranslatedRootElement extends TranslatedElement {
10431045
TranslatedRootElement() {
10441046
this instanceof TTranslatedFunction
10451047
or
1046-
this instanceof TTranslatedGlobalOrNamespaceVarInit
1048+
this instanceof TTranslatedStaticStorageDurationVarInit
10471049
}
10481050
}

0 commit comments

Comments
 (0)