Skip to content

Commit f1b5470

Browse files
committed
C++: Allow getInstructionFunction to yield a declaration
1 parent 4497441 commit f1b5470

File tree

10 files changed

+24
-18
lines changed

10 files changed

+24
-18
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,11 @@ module Public {
831831

832832
/** Gets the parameter through which this value is assigned. */
833833
Parameter getParameter() {
834-
result = this.getCallInstruction().getStaticCallTarget().getParameter(this.getArgumentIndex())
834+
result =
835+
this.getCallInstruction()
836+
.getStaticCallTarget()
837+
.(Function)
838+
.getParameter(this.getArgumentIndex())
835839
}
836840
}
837841

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ private import DataFlowDispatch as DataFlowDispatch
1919
private import DataFlowNodes
2020
import DataFlowNodes::Public
2121

22+
2223
cached
2324
private module Cached {
2425
/**

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ private class PointerWrapperTypeIndirection extends Indirection instanceof Point
175175
override predicate isAdditionalDereference(Instruction deref, Operand address) {
176176
exists(CallInstruction call |
177177
operandForFullyConvertedCall(getAUse(deref), call) and
178-
this = call.getStaticCallTarget().getClassAndName(["operator*", "operator->", "get"]) and
178+
this =
179+
call.getStaticCallTarget().(Function).getClassAndName(["operator*", "operator->", "get"]) and
179180
address = call.getThisArgumentOperand()
180181
)
181182
}
@@ -194,7 +195,7 @@ private module IteratorIndirections {
194195

195196
override predicate isAdditionalWrite(Node0Impl value, Operand address, boolean certain) {
196197
exists(CallInstruction call | call.getArgumentOperand(0) = value.asOperand() |
197-
this = call.getStaticCallTarget().getClassAndName("operator=") and
198+
this = call.getStaticCallTarget().(Function).getClassAndName("operator=") and
198199
address = call.getThisArgumentOperand() and
199200
certain = false
200201
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class FieldInstruction extends Instruction {
495495
* `FunctionAddress` instruction.
496496
*/
497497
class FunctionInstruction extends Instruction {
498-
Language::Function funcSymbol;
498+
Language::Declaration funcSymbol;
499499

500500
FunctionInstruction() { funcSymbol = Raw::getInstructionFunction(this) }
501501

@@ -504,7 +504,7 @@ class FunctionInstruction extends Instruction {
504504
/**
505505
* Gets the function that this instruction references.
506506
*/
507-
final Language::Function getFunctionSymbol() { result = funcSymbol }
507+
final Language::Declaration getFunctionSymbol() { result = funcSymbol }
508508
}
509509

510510
/**
@@ -1678,7 +1678,7 @@ class CallInstruction extends Instruction {
16781678
/**
16791679
* Gets the `Function` that the call targets, if this is statically known.
16801680
*/
1681-
final Language::Function getStaticCallTarget() {
1681+
final Language::Declaration getStaticCallTarget() {
16821682
result = this.getCallTarget().(FunctionAddressInstruction).getFunctionSymbol()
16831683
}
16841684

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class FieldInstruction extends Instruction {
495495
* `FunctionAddress` instruction.
496496
*/
497497
class FunctionInstruction extends Instruction {
498-
Language::Function funcSymbol;
498+
Language::Declaration funcSymbol;
499499

500500
FunctionInstruction() { funcSymbol = Raw::getInstructionFunction(this) }
501501

@@ -504,7 +504,7 @@ class FunctionInstruction extends Instruction {
504504
/**
505505
* Gets the function that this instruction references.
506506
*/
507-
final Language::Function getFunctionSymbol() { result = funcSymbol }
507+
final Language::Declaration getFunctionSymbol() { result = funcSymbol }
508508
}
509509

510510
/**
@@ -1678,7 +1678,7 @@ class CallInstruction extends Instruction {
16781678
/**
16791679
* Gets the `Function` that the call targets, if this is statically known.
16801680
*/
1681-
final Language::Function getStaticCallTarget() {
1681+
final Language::Declaration getStaticCallTarget() {
16821682
result = this.getCallTarget().(FunctionAddressInstruction).getFunctionSymbol()
16831683
}
16841684

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module Raw {
115115
}
116116

117117
cached
118-
Function getInstructionFunction(Instruction instruction) {
118+
Declaration getInstructionFunction(Instruction instruction) {
119119
result =
120120
getInstructionTranslatedElement(instruction)
121121
.getInstructionFunction(getInstructionTag(instruction))

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
@@ -348,7 +348,7 @@ class TranslatedExprCall extends TranslatedCallExpr {
348348
class TranslatedFunctionCall extends TranslatedCallExpr, TranslatedDirectCall {
349349
override FunctionCall expr;
350350

351-
override Function getInstructionFunction(InstructionTag tag) {
351+
override Declaration getInstructionFunction(InstructionTag tag) {
352352
tag = CallTargetTag() and result = expr.getTarget()
353353
}
354354

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ abstract class TranslatedElement extends TTranslatedElement {
11821182
* If the instruction specified by `tag` is a `FunctionInstruction`, gets the
11831183
* `Function` for that instruction.
11841184
*/
1185-
Function getInstructionFunction(InstructionTag tag) { none() }
1185+
Declaration getInstructionFunction(InstructionTag tag) { none() }
11861186

11871187
/**
11881188
* If the instruction specified by `tag` is a `VariableInstruction`, gets the

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ class TranslatedFunctionAccess extends TranslatedNonConstantExpr {
12641264
resultType = this.getResultType()
12651265
}
12661266

1267-
override Function getInstructionFunction(InstructionTag tag) {
1267+
override Declaration getInstructionFunction(InstructionTag tag) {
12681268
tag = OnlyInstructionTag() and
12691269
result = expr.getTarget()
12701270
}
@@ -2547,7 +2547,7 @@ class TranslatedAllocatorCall extends TTranslatedAllocatorCall, TranslatedDirect
25472547
any()
25482548
}
25492549

2550-
override Function getInstructionFunction(InstructionTag tag) {
2550+
override Declaration getInstructionFunction(InstructionTag tag) {
25512551
tag = CallTargetTag() and result = expr.getAllocator()
25522552
}
25532553

@@ -2630,7 +2630,7 @@ class TranslatedDeleteOrDeleteArrayExpr extends TranslatedNonConstantExpr, Trans
26302630
result = this.getFirstArgumentOrCallInstruction(kind)
26312631
}
26322632

2633-
override Function getInstructionFunction(InstructionTag tag) {
2633+
override Declaration getInstructionFunction(InstructionTag tag) {
26342634
tag = CallTargetTag() and result = expr.getDeallocator()
26352635
}
26362636

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class FieldInstruction extends Instruction {
495495
* `FunctionAddress` instruction.
496496
*/
497497
class FunctionInstruction extends Instruction {
498-
Language::Function funcSymbol;
498+
Language::Declaration funcSymbol;
499499

500500
FunctionInstruction() { funcSymbol = Raw::getInstructionFunction(this) }
501501

@@ -504,7 +504,7 @@ class FunctionInstruction extends Instruction {
504504
/**
505505
* Gets the function that this instruction references.
506506
*/
507-
final Language::Function getFunctionSymbol() { result = funcSymbol }
507+
final Language::Declaration getFunctionSymbol() { result = funcSymbol }
508508
}
509509

510510
/**
@@ -1678,7 +1678,7 @@ class CallInstruction extends Instruction {
16781678
/**
16791679
* Gets the `Function` that the call targets, if this is statically known.
16801680
*/
1681-
final Language::Function getStaticCallTarget() {
1681+
final Language::Declaration getStaticCallTarget() {
16821682
result = this.getCallTarget().(FunctionAddressInstruction).getFunctionSymbol()
16831683
}
16841684

0 commit comments

Comments
 (0)