Skip to content

Commit acbf389

Browse files
committed
C++: Allow getInstructionFunction to yield a declaration
1 parent a311b0f commit acbf389

File tree

9 files changed

+23
-18
lines changed

9 files changed

+23
-18
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,11 @@ class DefinitionByReferenceNode extends IndirectArgumentOutNode {
16031603

16041604
/** Gets the parameter through which this value is assigned. */
16051605
Parameter getParameter() {
1606-
result = this.getCallInstruction().getStaticCallTarget().getParameter(this.getArgumentIndex())
1606+
result =
1607+
this.getCallInstruction()
1608+
.getStaticCallTarget()
1609+
.(Function)
1610+
.getParameter(this.getArgumentIndex())
16071611
}
16081612
}
16091613

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
@@ -230,7 +230,8 @@ private class PointerWrapperTypeIndirection extends Indirection instanceof Point
230230
override predicate isAdditionalDereference(Instruction deref, Operand address) {
231231
exists(CallInstruction call |
232232
operandForFullyConvertedCall(getAUse(deref), call) and
233-
this = call.getStaticCallTarget().getClassAndName(["operator*", "operator->", "get"]) and
233+
this =
234+
call.getStaticCallTarget().(Function).getClassAndName(["operator*", "operator->", "get"]) and
234235
address = call.getThisArgumentOperand()
235236
)
236237
}
@@ -249,7 +250,7 @@ private module IteratorIndirections {
249250

250251
override predicate isAdditionalWrite(Node0Impl value, Operand address, boolean certain) {
251252
exists(CallInstruction call | call.getArgumentOperand(0) = value.asOperand() |
252-
this = call.getStaticCallTarget().getClassAndName("operator=") and
253+
this = call.getStaticCallTarget().(Function).getClassAndName("operator=") and
253254
address = call.getThisArgumentOperand() and
254255
certain = false
255256
)

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
@@ -114,7 +114,7 @@ module Raw {
114114
}
115115

116116
cached
117-
Function getInstructionFunction(Instruction instruction) {
117+
Declaration getInstructionFunction(Instruction instruction) {
118118
result =
119119
getInstructionTranslatedElement(instruction)
120120
.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)