Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 984405b

Browse files
committed
C++ IR: Change many uses of getAnyDef to getDef
This changes all the getters on `Instruction` to use `getDef` instead of `getAnyDef`, with the result that these getters now only have a result if the definition is exact. This is a backwards-INCOMPATIBLE change.
1 parent e082451 commit 984405b

5 files changed

Lines changed: 63 additions & 64 deletions

File tree

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ class Instruction extends Construction::TInstruction {
480480
}
481481

482482
/**
483-
* Gets all direct uses of the result of this instruction.
483+
* Gets all direct uses of the result of this instruction. The result can be
484+
* an `Operand` for which `isDefinitionInexact` holds.
484485
*/
485486
final Operand getAUse() {
486487
result.getAnyDef() = this
@@ -698,7 +699,7 @@ class FieldAddressInstruction extends FieldInstruction {
698699
}
699700

700701
final Instruction getObjectAddress() {
701-
result = getObjectAddressOperand().getAnyDef()
702+
result = getObjectAddressOperand().getDef()
702703
}
703704
}
704705

@@ -747,7 +748,7 @@ class ReturnValueInstruction extends ReturnInstruction {
747748
}
748749

749750
final Instruction getReturnValue() {
750-
result = getReturnValueOperand().getAnyDef()
751+
result = getReturnValueOperand().getDef()
751752
}
752753
}
753754

@@ -761,7 +762,7 @@ class CopyInstruction extends Instruction {
761762
}
762763

763764
final Instruction getSourceValue() {
764-
result = getSourceValueOperand().getAnyDef()
765+
result = getSourceValueOperand().getDef()
765766
}
766767
}
767768

@@ -785,7 +786,7 @@ class LoadInstruction extends CopyInstruction {
785786
}
786787

787788
final Instruction getSourceAddress() {
788-
result = getSourceAddressOperand().getAnyDef()
789+
result = getSourceAddressOperand().getDef()
789790
}
790791

791792
override final LoadOperand getSourceValueOperand() {
@@ -807,7 +808,7 @@ class StoreInstruction extends CopyInstruction {
807808
}
808809

809810
final Instruction getDestinationAddress() {
810-
result = getDestinationAddressOperand().getAnyDef()
811+
result = getDestinationAddressOperand().getDef()
811812
}
812813

813814
override final StoreValueOperand getSourceValueOperand() {
@@ -825,7 +826,7 @@ class ConditionalBranchInstruction extends Instruction {
825826
}
826827

827828
final Instruction getCondition() {
828-
result = getConditionOperand().getAnyDef()
829+
result = getConditionOperand().getDef()
829830
}
830831

831832
final Instruction getTrueSuccessor() {
@@ -891,11 +892,11 @@ class BinaryInstruction extends Instruction {
891892
}
892893

893894
final Instruction getLeft() {
894-
result = getLeftOperand().getAnyDef()
895+
result = getLeftOperand().getDef()
895896
}
896897

897898
final Instruction getRight() {
898-
result = getRightOperand().getAnyDef()
899+
result = getRightOperand().getDef()
899900
}
900901

901902
/**
@@ -1045,7 +1046,7 @@ class UnaryInstruction extends Instruction {
10451046
}
10461047

10471048
final Instruction getUnary() {
1048-
result = getUnaryOperand().getAnyDef()
1049+
result = getUnaryOperand().getDef()
10491050
}
10501051
}
10511052

@@ -1275,7 +1276,7 @@ class SwitchInstruction extends Instruction {
12751276
}
12761277

12771278
final Instruction getExpression() {
1278-
result = getExpressionOperand().getAnyDef()
1279+
result = getExpressionOperand().getDef()
12791280
}
12801281

12811282
final Instruction getACaseSuccessor() {
@@ -1310,7 +1311,7 @@ class CallInstruction extends Instruction {
13101311
* function pointer.
13111312
*/
13121313
final Instruction getCallTarget() {
1313-
result = getCallTargetOperand().getAnyDef()
1314+
result = getCallTargetOperand().getDef()
13141315
}
13151316

13161317
/**
@@ -1331,7 +1332,7 @@ class CallInstruction extends Instruction {
13311332
* Gets all of the arguments of the call, including the `this` pointer, if any.
13321333
*/
13331334
final Instruction getAnArgument() {
1334-
result = getAnArgumentOperand().getAnyDef()
1335+
result = getAnArgumentOperand().getDef()
13351336
}
13361337

13371338
/**
@@ -1345,7 +1346,7 @@ class CallInstruction extends Instruction {
13451346
* Gets the `this` pointer argument of the call, if any.
13461347
*/
13471348
final Instruction getThisArgument() {
1348-
result = getThisArgumentOperand().getAnyDef()
1349+
result = getThisArgumentOperand().getDef()
13491350
}
13501351

13511352
/**
@@ -1360,7 +1361,7 @@ class CallInstruction extends Instruction {
13601361
* Gets the argument at the specified index.
13611362
*/
13621363
final Instruction getPositionalArgument(int index) {
1363-
result = getPositionalArgumentOperand(index).getAnyDef()
1364+
result = getPositionalArgumentOperand(index).getDef()
13641365
}
13651366
}
13661367

@@ -1516,7 +1517,7 @@ class ThrowValueInstruction extends ThrowInstruction {
15161517
* Gets the address of the exception thrown by this instruction.
15171518
*/
15181519
final Instruction getExceptionAddress() {
1519-
result = getExceptionAddressOperand().getAnyDef()
1520+
result = getExceptionAddressOperand().getDef()
15201521
}
15211522

15221523
/**
@@ -1530,7 +1531,7 @@ class ThrowValueInstruction extends ThrowInstruction {
15301531
* Gets the exception thrown by this instruction.
15311532
*/
15321533
final Instruction getException() {
1533-
result = getExceptionOperand().getAnyDef()
1534+
result = getExceptionOperand().getDef()
15341535
}
15351536
}
15361537

@@ -1660,7 +1661,7 @@ class PhiInstruction extends Instruction {
16601661
*/
16611662
pragma[noinline]
16621663
final Instruction getAnInput() {
1663-
result = this.getAnInputOperand().getAnyDef()
1664+
result = this.getAnInputOperand().getDef()
16641665
}
16651666
}
16661667

@@ -1728,7 +1729,7 @@ class ChiInstruction extends Instruction {
17281729
* memory write.
17291730
*/
17301731
final Instruction getTotal() {
1731-
result = getTotalOperand().getAnyDef()
1732+
result = getTotalOperand().getDef()
17321733
}
17331734

17341735
/**
@@ -1742,7 +1743,7 @@ class ChiInstruction extends Instruction {
17421743
* Gets the operand that represents the new value written by the memory write.
17431744
*/
17441745
final Instruction getPartial() {
1745-
result = getPartialOperand().getAnyDef()
1746+
result = getPartialOperand().getDef()
17461747
}
17471748
}
17481749

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ class Instruction extends Construction::TInstruction {
480480
}
481481

482482
/**
483-
* Gets all direct uses of the result of this instruction.
483+
* Gets all direct uses of the result of this instruction. The result can be
484+
* an `Operand` for which `isDefinitionInexact` holds.
484485
*/
485486
final Operand getAUse() {
486487
result.getAnyDef() = this
@@ -698,7 +699,7 @@ class FieldAddressInstruction extends FieldInstruction {
698699
}
699700

700701
final Instruction getObjectAddress() {
701-
result = getObjectAddressOperand().getAnyDef()
702+
result = getObjectAddressOperand().getDef()
702703
}
703704
}
704705

@@ -747,7 +748,7 @@ class ReturnValueInstruction extends ReturnInstruction {
747748
}
748749

749750
final Instruction getReturnValue() {
750-
result = getReturnValueOperand().getAnyDef()
751+
result = getReturnValueOperand().getDef()
751752
}
752753
}
753754

@@ -761,7 +762,7 @@ class CopyInstruction extends Instruction {
761762
}
762763

763764
final Instruction getSourceValue() {
764-
result = getSourceValueOperand().getAnyDef()
765+
result = getSourceValueOperand().getDef()
765766
}
766767
}
767768

@@ -785,7 +786,7 @@ class LoadInstruction extends CopyInstruction {
785786
}
786787

787788
final Instruction getSourceAddress() {
788-
result = getSourceAddressOperand().getAnyDef()
789+
result = getSourceAddressOperand().getDef()
789790
}
790791

791792
override final LoadOperand getSourceValueOperand() {
@@ -807,7 +808,7 @@ class StoreInstruction extends CopyInstruction {
807808
}
808809

809810
final Instruction getDestinationAddress() {
810-
result = getDestinationAddressOperand().getAnyDef()
811+
result = getDestinationAddressOperand().getDef()
811812
}
812813

813814
override final StoreValueOperand getSourceValueOperand() {
@@ -825,7 +826,7 @@ class ConditionalBranchInstruction extends Instruction {
825826
}
826827

827828
final Instruction getCondition() {
828-
result = getConditionOperand().getAnyDef()
829+
result = getConditionOperand().getDef()
829830
}
830831

831832
final Instruction getTrueSuccessor() {
@@ -891,11 +892,11 @@ class BinaryInstruction extends Instruction {
891892
}
892893

893894
final Instruction getLeft() {
894-
result = getLeftOperand().getAnyDef()
895+
result = getLeftOperand().getDef()
895896
}
896897

897898
final Instruction getRight() {
898-
result = getRightOperand().getAnyDef()
899+
result = getRightOperand().getDef()
899900
}
900901

901902
/**
@@ -1045,7 +1046,7 @@ class UnaryInstruction extends Instruction {
10451046
}
10461047

10471048
final Instruction getUnary() {
1048-
result = getUnaryOperand().getAnyDef()
1049+
result = getUnaryOperand().getDef()
10491050
}
10501051
}
10511052

@@ -1275,7 +1276,7 @@ class SwitchInstruction extends Instruction {
12751276
}
12761277

12771278
final Instruction getExpression() {
1278-
result = getExpressionOperand().getAnyDef()
1279+
result = getExpressionOperand().getDef()
12791280
}
12801281

12811282
final Instruction getACaseSuccessor() {
@@ -1310,7 +1311,7 @@ class CallInstruction extends Instruction {
13101311
* function pointer.
13111312
*/
13121313
final Instruction getCallTarget() {
1313-
result = getCallTargetOperand().getAnyDef()
1314+
result = getCallTargetOperand().getDef()
13141315
}
13151316

13161317
/**
@@ -1331,7 +1332,7 @@ class CallInstruction extends Instruction {
13311332
* Gets all of the arguments of the call, including the `this` pointer, if any.
13321333
*/
13331334
final Instruction getAnArgument() {
1334-
result = getAnArgumentOperand().getAnyDef()
1335+
result = getAnArgumentOperand().getDef()
13351336
}
13361337

13371338
/**
@@ -1345,7 +1346,7 @@ class CallInstruction extends Instruction {
13451346
* Gets the `this` pointer argument of the call, if any.
13461347
*/
13471348
final Instruction getThisArgument() {
1348-
result = getThisArgumentOperand().getAnyDef()
1349+
result = getThisArgumentOperand().getDef()
13491350
}
13501351

13511352
/**
@@ -1360,7 +1361,7 @@ class CallInstruction extends Instruction {
13601361
* Gets the argument at the specified index.
13611362
*/
13621363
final Instruction getPositionalArgument(int index) {
1363-
result = getPositionalArgumentOperand(index).getAnyDef()
1364+
result = getPositionalArgumentOperand(index).getDef()
13641365
}
13651366
}
13661367

@@ -1516,7 +1517,7 @@ class ThrowValueInstruction extends ThrowInstruction {
15161517
* Gets the address of the exception thrown by this instruction.
15171518
*/
15181519
final Instruction getExceptionAddress() {
1519-
result = getExceptionAddressOperand().getAnyDef()
1520+
result = getExceptionAddressOperand().getDef()
15201521
}
15211522

15221523
/**
@@ -1530,7 +1531,7 @@ class ThrowValueInstruction extends ThrowInstruction {
15301531
* Gets the exception thrown by this instruction.
15311532
*/
15321533
final Instruction getException() {
1533-
result = getExceptionOperand().getAnyDef()
1534+
result = getExceptionOperand().getDef()
15341535
}
15351536
}
15361537

@@ -1660,7 +1661,7 @@ class PhiInstruction extends Instruction {
16601661
*/
16611662
pragma[noinline]
16621663
final Instruction getAnInput() {
1663-
result = this.getAnInputOperand().getAnyDef()
1664+
result = this.getAnInputOperand().getDef()
16641665
}
16651666
}
16661667

@@ -1728,7 +1729,7 @@ class ChiInstruction extends Instruction {
17281729
* memory write.
17291730
*/
17301731
final Instruction getTotal() {
1731-
result = getTotalOperand().getAnyDef()
1732+
result = getTotalOperand().getDef()
17321733
}
17331734

17341735
/**
@@ -1742,7 +1743,7 @@ class ChiInstruction extends Instruction {
17421743
* Gets the operand that represents the new value written by the memory write.
17431744
*/
17441745
final Instruction getPartial() {
1745-
result = getPartialOperand().getAnyDef()
1746+
result = getPartialOperand().getDef()
17461747
}
17471748
}
17481749

0 commit comments

Comments
 (0)