@@ -7,6 +7,7 @@ import cpp
77import semmle.code.cpp.ir.implementation.EdgeKind
88import semmle.code.cpp.ir.implementation.MemoryAccessKind
99import semmle.code.cpp.ir.implementation.Opcode
10+ private import semmle.code.cpp.Print
1011private import semmle.code.cpp.ir.implementation.Opcode
1112private import semmle.code.cpp.ir.internal.OperandTag
1213
@@ -29,12 +30,11 @@ module InstructionSanity {
2930 tag instanceof RightOperandTag
3031 )
3132 ) or
32- opcode instanceof CopyOpcode and tag instanceof CopySourceOperandTag or
3333 opcode instanceof MemoryAccessOpcode and tag instanceof AddressOperandTag or
3434 opcode instanceof BufferAccessOpcode and tag instanceof BufferSizeOperand or
3535 opcode instanceof OpcodeWithCondition and tag instanceof ConditionOperandTag or
36- opcode instanceof Opcode :: ReturnValue and tag instanceof ReturnValueOperandTag or
37- opcode instanceof Opcode:: ThrowValue and tag instanceof ExceptionOperandTag or
36+ opcode instanceof OpcodeWithLoad and tag instanceof LoadOperandTag or
37+ opcode instanceof Opcode:: Store and tag instanceof StoreValueOperandTag or
3838 opcode instanceof Opcode:: UnmodeledUse and tag instanceof UnmodeledUseOperandTag or
3939 opcode instanceof Opcode:: Call and tag instanceof CallTargetOperandTag or
4040 opcode instanceof Opcode:: Chi and tag instanceof ChiTotalOperandTag or
@@ -93,6 +93,14 @@ module InstructionSanity {
9393 )
9494 }
9595
96+ query predicate missingOperandType ( Operand operand , string message ) {
97+ exists ( Function func |
98+ not exists ( operand .getType ( ) ) and
99+ func = operand .getUseInstruction ( ) .getEnclosingFunction ( ) and
100+ message = "Operand missing type in function '" + getIdentityString ( func ) + "'."
101+ )
102+ }
103+
96104 /**
97105 * Holds if an instruction, other than `ExitFunction`, has no successors.
98106 */
@@ -714,7 +722,7 @@ class ReturnValueInstruction extends ReturnInstruction {
714722 getOpcode ( ) instanceof Opcode:: ReturnValue
715723 }
716724
717- final ReturnValueOperand getReturnValueOperand ( ) {
725+ final LoadOperand getReturnValueOperand ( ) {
718726 result = getAnOperand ( )
719727 }
720728
@@ -728,19 +736,23 @@ class CopyInstruction extends Instruction {
728736 getOpcode ( ) instanceof CopyOpcode
729737 }
730738
731- final CopySourceOperand getSourceValueOperand ( ) {
732- result = getAnOperand ( )
739+ Operand getSourceValueOperand ( ) {
740+ none ( )
733741 }
734-
742+
735743 final Instruction getSourceValue ( ) {
736744 result = getSourceValueOperand ( ) .getDefinitionInstruction ( )
737745 }
738746}
739747
740- class CopyValueInstruction extends CopyInstruction {
748+ class CopyValueInstruction extends CopyInstruction , UnaryInstruction {
741749 CopyValueInstruction ( ) {
742750 getOpcode ( ) instanceof Opcode:: CopyValue
743751 }
752+
753+ override final UnaryOperand getSourceValueOperand ( ) {
754+ result = getAnOperand ( )
755+ }
744756}
745757
746758class LoadInstruction extends CopyInstruction {
@@ -755,6 +767,10 @@ class LoadInstruction extends CopyInstruction {
755767 final Instruction getSourceAddress ( ) {
756768 result = getSourceAddressOperand ( ) .getDefinitionInstruction ( )
757769 }
770+
771+ override final LoadOperand getSourceValueOperand ( ) {
772+ result = getAnOperand ( )
773+ }
758774}
759775
760776class StoreInstruction extends CopyInstruction {
@@ -773,6 +789,10 @@ class StoreInstruction extends CopyInstruction {
773789 final Instruction getDestinationAddress ( ) {
774790 result = getDestinationAddressOperand ( ) .getDefinitionInstruction ( )
775791 }
792+
793+ override final StoreValueOperand getSourceValueOperand ( ) {
794+ result = getAnOperand ( )
795+ }
776796}
777797
778798class ConditionalBranchInstruction extends Instruction {
@@ -1442,7 +1462,7 @@ class ThrowValueInstruction extends ThrowInstruction {
14421462 /**
14431463 * Gets the operand for the exception thrown by this instruction.
14441464 */
1445- final ExceptionOperand getExceptionOperand ( ) {
1465+ final LoadOperand getExceptionOperand ( ) {
14461466 result = getAnOperand ( )
14471467 }
14481468
0 commit comments