Skip to content

Commit 3d222a7

Browse files
committed
Merge main into redsun82/swift-use-generated-classes
2 parents 48584a6 + 35c8ca1 commit 3d222a7

File tree

97 files changed

+7827
-1445
lines changed

Some content is hidden

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

97 files changed

+7827
-1445
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class Expr extends StmtParent, @expr {
4949
/** Gets the enclosing variable of this expression, if any. */
5050
Variable getEnclosingVariable() { result = exprEnclosingElement(this) }
5151

52+
/** Gets the enclosing variable or function of this expression. */
53+
Declaration getEnclosingDeclaration() { result = exprEnclosingElement(this) }
54+
5255
/** Gets a child of this expression. */
5356
Expr getAChild() { exists(int n | result = this.getChild(n)) }
5457

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Node extends TIRDataFlowNode {
100100
Declaration getEnclosingCallable() { none() } // overridden in subclasses
101101

102102
/** Gets the function to which this node belongs, if any. */
103-
Function getFunction() { none() } // overridden in subclasses
103+
Declaration getFunction() { none() } // overridden in subclasses
104104

105105
/** Gets the type of this node. */
106106
IRType getType() { none() } // overridden in subclasses
@@ -196,7 +196,7 @@ class InstructionNode extends Node, TInstructionNode {
196196

197197
override Declaration getEnclosingCallable() { result = this.getFunction() }
198198

199-
override Function getFunction() { result = instr.getEnclosingFunction() }
199+
override Declaration getFunction() { result = instr.getEnclosingFunction() }
200200

201201
override IRType getType() { result = instr.getResultIRType() }
202202

@@ -222,7 +222,7 @@ class OperandNode extends Node, TOperandNode {
222222

223223
override Declaration getEnclosingCallable() { result = this.getFunction() }
224224

225-
override Function getFunction() { result = op.getUse().getEnclosingFunction() }
225+
override Declaration getFunction() { result = op.getUse().getEnclosingFunction() }
226226

227227
override IRType getType() { result = op.getIRType() }
228228

@@ -274,7 +274,7 @@ class StoreNodeInstr extends StoreNode, TStoreNodeInstr {
274274
/** Gets the underlying instruction. */
275275
Instruction getInstruction() { result = instr }
276276

277-
override Function getFunction() { result = this.getInstruction().getEnclosingFunction() }
277+
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
278278

279279
override IRType getType() { result = this.getInstruction().getResultIRType() }
280280

@@ -328,7 +328,7 @@ class StoreNodeOperand extends StoreNode, TStoreNodeOperand {
328328
/** Gets the underlying operand. */
329329
Operand getOperand() { result = operand }
330330

331-
override Function getFunction() { result = operand.getDef().getEnclosingFunction() }
331+
override Declaration getFunction() { result = operand.getDef().getEnclosingFunction() }
332332

333333
override IRType getType() { result = operand.getIRType() }
334334

@@ -384,7 +384,7 @@ class ReadNode extends Node, TReadNode {
384384

385385
override Declaration getEnclosingCallable() { result = this.getFunction() }
386386

387-
override Function getFunction() { result = this.getInstruction().getEnclosingFunction() }
387+
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
388388

389389
override IRType getType() { result = this.getInstruction().getResultIRType() }
390390

@@ -436,7 +436,7 @@ class SsaPhiNode extends Node, TSsaPhiNode {
436436

437437
override Declaration getEnclosingCallable() { result = this.getFunction() }
438438

439-
override Function getFunction() { result = phi.getBasicBlock().getEnclosingFunction() }
439+
override Declaration getFunction() { result = phi.getBasicBlock().getEnclosingFunction() }
440440

441441
override IRType getType() { result instanceof IRVoidType }
442442

@@ -673,7 +673,7 @@ class VariableNode extends Node, TVariableNode {
673673
/** Gets the variable corresponding to this node. */
674674
Variable getVariable() { result = v }
675675

676-
override Function getFunction() { none() }
676+
override Declaration getFunction() { none() }
677677

678678
override Declaration getEnclosingCallable() {
679679
// When flow crosses from one _enclosing callable_ to another, the

cpp/ql/lib/semmle/code/cpp/ir/implementation/IRConfiguration.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class IRConfiguration extends TIRConfiguration {
1616
/**
1717
* Holds if IR should be created for function `func`. By default, holds for all functions.
1818
*/
19-
predicate shouldCreateIRForFunction(Language::Function func) { any() }
19+
predicate shouldCreateIRForFunction(Language::Declaration func) { any() }
2020

2121
/**
2222
* Holds if the strings used as part of an IR dump should be generated for function `func`.
@@ -25,7 +25,7 @@ class IRConfiguration extends TIRConfiguration {
2525
* of debug strings for IR that will not be dumped. We still generate the actual IR for these
2626
* functions, however, to preserve the results of any interprocedural analysis.
2727
*/
28-
predicate shouldEvaluateDebugStringsForFunction(Language::Function func) { any() }
28+
predicate shouldEvaluateDebugStringsForFunction(Language::Declaration func) { any() }
2929
}
3030

3131
private newtype TIREscapeAnalysisConfiguration = MkIREscapeAnalysisConfiguration()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class IRBlockBase extends TIRBlock {
9797
/**
9898
* Gets the `Function` that contains this block.
9999
*/
100-
final Language::Function getEnclosingFunction() {
100+
final Language::Declaration getEnclosingFunction() {
101101
result = getFirstInstruction(this).getEnclosingFunction()
102102
}
103103
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,23 @@ module InstructionConsistency {
524524
"' has a `this` argument operand that is not an address, in function '$@'." and
525525
irFunc = getInstructionIRFunction(instr, irFuncText)
526526
}
527+
528+
query predicate nonUniqueIRVariable(
529+
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
530+
) {
531+
exists(VariableInstruction vi, IRVariable v1, IRVariable v2 |
532+
instr = vi and vi.getIRVariable() = v1 and vi.getIRVariable() = v2 and v1 != v2
533+
) and
534+
message =
535+
"Variable instruction '" + instr.toString() +
536+
"' has multiple associated variables, in function '$@'." and
537+
irFunc = getInstructionIRFunction(instr, irFuncText)
538+
or
539+
instr.getOpcode() instanceof Opcode::VariableAddress and
540+
not instr instanceof VariableInstruction and
541+
message =
542+
"Variable address instruction '" + instr.toString() +
543+
"' has no associated variable, in function '$@'." and
544+
irFunc = getInstructionIRFunction(instr, irFuncText)
545+
}
527546
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private import Imports::IRType
1818
* by the AST-to-IR translation (`IRTempVariable`).
1919
*/
2020
class IRVariable extends TIRVariable {
21-
Language::Function func;
21+
Language::Declaration func;
2222

2323
IRVariable() {
2424
this = TIRUserVariable(_, _, func) or
@@ -79,7 +79,7 @@ class IRVariable extends TIRVariable {
7979
/**
8080
* Gets the function that references this variable.
8181
*/
82-
final Language::Function getEnclosingFunction() { result = func }
82+
final Language::Declaration getEnclosingFunction() { result = func }
8383
}
8484

8585
/**
@@ -246,7 +246,7 @@ class IREllipsisVariable extends IRTempVariable, IRParameter {
246246

247247
final override string toString() { result = "#ellipsis" }
248248

249-
final override int getIndex() { result = func.getNumberOfParameters() }
249+
final override int getIndex() { result = func.(Language::Function).getNumberOfParameters() }
250250
}
251251

252252
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Instruction extends Construction::TStageInstruction {
194194
/**
195195
* Gets the function that contains this instruction.
196196
*/
197-
final Language::Function getEnclosingFunction() {
197+
final Language::Declaration getEnclosingFunction() {
198198
result = this.getEnclosingIRFunction().getFunction()
199199
}
200200

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ class PrintIRConfiguration extends TPrintIRConfiguration {
2626
* Holds if the IR for `func` should be printed. By default, holds for all
2727
* functions.
2828
*/
29-
predicate shouldPrintFunction(Language::Function func) { any() }
29+
predicate shouldPrintFunction(Language::Declaration decl) { any() }
3030
}
3131

3232
/**
3333
* Override of `IRConfiguration` to only evaluate debug strings for the functions that are to be dumped.
3434
*/
3535
private class FilteredIRConfiguration extends IRConfiguration {
36-
override predicate shouldEvaluateDebugStringsForFunction(Language::Function func) {
36+
override predicate shouldEvaluateDebugStringsForFunction(Language::Declaration func) {
3737
shouldPrintFunction(func)
3838
}
3939
}
4040

41-
private predicate shouldPrintFunction(Language::Function func) {
42-
exists(PrintIRConfiguration config | config.shouldPrintFunction(func))
41+
private predicate shouldPrintFunction(Language::Declaration decl) {
42+
exists(PrintIRConfiguration config | config.shouldPrintFunction(decl))
4343
}
4444

4545
private string getAdditionalInstructionProperty(Instruction instr, string key) {

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
private import IRFunctionBaseInternal
66

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

1011
/**
1112
* The IR for a function. This base class contains only the predicates that are the same between all
1213
* phases of the IR. Each instantiation of `IRFunction` extends this class.
1314
*/
1415
class IRFunctionBase extends TIRFunction {
15-
Language::Function func;
16+
Language::Declaration decl;
1617

17-
IRFunctionBase() { this = MkIRFunction(func) }
18+
IRFunctionBase() {
19+
this = TFunctionIRFunction(decl)
20+
or
21+
this = TVarInitIRFunction(decl)
22+
}
1823

1924
/** Gets a textual representation of this element. */
20-
final string toString() { result = "IR: " + func.toString() }
25+
final string toString() { result = "IR: " + decl.toString() }
2126

2227
/** Gets the function whose IR is represented. */
23-
final Language::Function getFunction() { result = func }
28+
final Language::Declaration getFunction() { result = decl }
2429

2530
/** Gets the location of the function. */
26-
final Language::Location getLocation() { result = func.getLocation() }
31+
final Language::Location getLocation() { result = decl.getLocation() }
2732
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ private import TIRVariableInternal
22
private import Imports::TempVariableTag
33

44
newtype TIRVariable =
5-
TIRUserVariable(Language::Variable var, Language::LanguageType type, Language::Function func) {
5+
TIRUserVariable(Language::Variable var, Language::LanguageType type, Language::Declaration func) {
66
Construction::hasUserVariable(func, var, type)
77
} or
88
TIRTempVariable(
9-
Language::Function func, Language::AST ast, TempVariableTag tag, Language::LanguageType type
9+
Language::Declaration func, Language::AST ast, TempVariableTag tag, Language::LanguageType type
1010
) {
1111
Construction::hasTempVariable(func, ast, tag, type)
1212
} or
1313
TIRDynamicInitializationFlag(
14-
Language::Function func, Language::Variable var, Language::LanguageType type
14+
Language::Declaration func, Language::Variable var, Language::LanguageType type
1515
) {
1616
Construction::hasDynamicInitializationFlag(func, var, type)
1717
} or
1818
TIRStringLiteral(
19-
Language::Function func, Language::AST ast, Language::LanguageType type,
19+
Language::Declaration func, Language::AST ast, Language::LanguageType type,
2020
Language::StringLiteral literal
2121
) {
2222
Construction::hasStringLiteral(func, ast, type, literal)

0 commit comments

Comments
 (0)