Skip to content

Commit 77bf564

Browse files
author
Dave Bartolomeo
committed
C++: Finish Instruction.qll QLDoc
1 parent 6de3d5b commit 77bf564

File tree

5 files changed

+275
-20
lines changed

5 files changed

+275
-20
lines changed

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

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class Instruction extends Construction::TStageInstruction {
215215
result = Raw::getInstructionUnconvertedResultExpression(this)
216216
}
217217

218+
/**
219+
* Gets the language-specific type of the result produced by this instruction.
220+
*
221+
* Most consumers of the IR should use `getResultIRType()` instead. `getResultIRType()` uses a
222+
* less complex, language-neutral type system in which all semantically equivalent types share the
223+
* same `IRType` instance. For example, in C++, four different `Instruction`s might have three
224+
* different values for `getResultLanguageType()`: `unsigned int`, `char32_t`, and `wchar_t`,
225+
* whereas all four instructions would have the same value for `getResultIRType()`, `uint4`.
226+
*/
218227
final Language::LanguageType getResultLanguageType() {
219228
result = Construction::getInstructionResultType(this)
220229
}
@@ -1178,8 +1187,14 @@ class PointerDiffInstruction extends PointerArithmeticInstruction {
11781187
class UnaryInstruction extends Instruction {
11791188
UnaryInstruction() { getOpcode() instanceof UnaryOpcode }
11801189

1190+
/**
1191+
* Gets the sole operand of this instruction.
1192+
*/
11811193
final UnaryOperand getUnaryOperand() { result = getAnOperand() }
11821194

1195+
/**
1196+
* Gets the instruction whose result provides the sole operand of this instruction.
1197+
*/
11831198
final Instruction getUnary() { result = getUnaryOperand().getDef() }
11841199
}
11851200

@@ -1621,7 +1636,15 @@ class SizedBufferReadSideEffectInstruction extends ReadSideEffectInstruction {
16211636
getOpcode() instanceof Opcode::SizedBufferReadSideEffect
16221637
}
16231638

1624-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1639+
/**
1640+
* Gets the operand that holds the number of bytes read from the buffer.
1641+
*/
1642+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1643+
1644+
/**
1645+
* Gets the instruction whose result provides the number of bytes read from the buffer.
1646+
*/
1647+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
16251648
}
16261649

16271650
/**
@@ -1631,7 +1654,15 @@ class SizedBufferReadSideEffectInstruction extends ReadSideEffectInstruction {
16311654
class WriteSideEffectInstruction extends SideEffectInstruction, IndexedInstruction {
16321655
WriteSideEffectInstruction() { getOpcode() instanceof WriteSideEffectOpcode }
16331656

1634-
Instruction getArgumentDef() { result = getAnOperand().(AddressOperand).getDef() }
1657+
/**
1658+
* Get the operand that holds the address of the memory to be written.
1659+
*/
1660+
final AddressOperand getDestinationAddressOperand() { result = getAnOperand() }
1661+
1662+
/**
1663+
* Gets the instruction whose result provides the address of the memory to be written.
1664+
*/
1665+
Instruction getDestinationAddress() { result = getDestinationAddressOperand().getDef() }
16351666
}
16361667

16371668
/**
@@ -1662,7 +1693,15 @@ class SizedBufferMustWriteSideEffectInstruction extends WriteSideEffectInstructi
16621693
getOpcode() instanceof Opcode::SizedBufferMustWriteSideEffect
16631694
}
16641695

1665-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1696+
/**
1697+
* Gets the operand that holds the number of bytes written to the buffer.
1698+
*/
1699+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1700+
1701+
/**
1702+
* Gets the instruction whose result provides the number of bytes written to the buffer.
1703+
*/
1704+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
16661705
}
16671706

16681707
/**
@@ -1696,7 +1735,15 @@ class SizedBufferMayWriteSideEffectInstruction extends WriteSideEffectInstructio
16961735
getOpcode() instanceof Opcode::SizedBufferMayWriteSideEffect
16971736
}
16981737

1699-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1738+
/**
1739+
* Gets the operand that holds the number of bytes written to the buffer.
1740+
*/
1741+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1742+
1743+
/**
1744+
* Gets the instruction whose result provides the number of bytes written to the buffer.
1745+
*/
1746+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
17001747
}
17011748

17021749
/**
@@ -1941,6 +1988,10 @@ class BuiltInOperationInstruction extends Instruction {
19411988
operation = Raw::getInstructionBuiltInOperation(this)
19421989
}
19431990

1991+
/**
1992+
* Gets the language-specific `BuildInOperation` object that specifies the operation that is
1993+
* performed by this instruction.
1994+
*/
19441995
final Language::BuiltInOperation getBuiltInOperation() { result = operation }
19451996
}
19461997

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

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class Instruction extends Construction::TStageInstruction {
215215
result = Raw::getInstructionUnconvertedResultExpression(this)
216216
}
217217

218+
/**
219+
* Gets the language-specific type of the result produced by this instruction.
220+
*
221+
* Most consumers of the IR should use `getResultIRType()` instead. `getResultIRType()` uses a
222+
* less complex, language-neutral type system in which all semantically equivalent types share the
223+
* same `IRType` instance. For example, in C++, four different `Instruction`s might have three
224+
* different values for `getResultLanguageType()`: `unsigned int`, `char32_t`, and `wchar_t`,
225+
* whereas all four instructions would have the same value for `getResultIRType()`, `uint4`.
226+
*/
218227
final Language::LanguageType getResultLanguageType() {
219228
result = Construction::getInstructionResultType(this)
220229
}
@@ -1178,8 +1187,14 @@ class PointerDiffInstruction extends PointerArithmeticInstruction {
11781187
class UnaryInstruction extends Instruction {
11791188
UnaryInstruction() { getOpcode() instanceof UnaryOpcode }
11801189

1190+
/**
1191+
* Gets the sole operand of this instruction.
1192+
*/
11811193
final UnaryOperand getUnaryOperand() { result = getAnOperand() }
11821194

1195+
/**
1196+
* Gets the instruction whose result provides the sole operand of this instruction.
1197+
*/
11831198
final Instruction getUnary() { result = getUnaryOperand().getDef() }
11841199
}
11851200

@@ -1621,7 +1636,15 @@ class SizedBufferReadSideEffectInstruction extends ReadSideEffectInstruction {
16211636
getOpcode() instanceof Opcode::SizedBufferReadSideEffect
16221637
}
16231638

1624-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1639+
/**
1640+
* Gets the operand that holds the number of bytes read from the buffer.
1641+
*/
1642+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1643+
1644+
/**
1645+
* Gets the instruction whose result provides the number of bytes read from the buffer.
1646+
*/
1647+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
16251648
}
16261649

16271650
/**
@@ -1631,7 +1654,15 @@ class SizedBufferReadSideEffectInstruction extends ReadSideEffectInstruction {
16311654
class WriteSideEffectInstruction extends SideEffectInstruction, IndexedInstruction {
16321655
WriteSideEffectInstruction() { getOpcode() instanceof WriteSideEffectOpcode }
16331656

1634-
Instruction getArgumentDef() { result = getAnOperand().(AddressOperand).getDef() }
1657+
/**
1658+
* Get the operand that holds the address of the memory to be written.
1659+
*/
1660+
final AddressOperand getDestinationAddressOperand() { result = getAnOperand() }
1661+
1662+
/**
1663+
* Gets the instruction whose result provides the address of the memory to be written.
1664+
*/
1665+
Instruction getDestinationAddress() { result = getDestinationAddressOperand().getDef() }
16351666
}
16361667

16371668
/**
@@ -1662,7 +1693,15 @@ class SizedBufferMustWriteSideEffectInstruction extends WriteSideEffectInstructi
16621693
getOpcode() instanceof Opcode::SizedBufferMustWriteSideEffect
16631694
}
16641695

1665-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1696+
/**
1697+
* Gets the operand that holds the number of bytes written to the buffer.
1698+
*/
1699+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1700+
1701+
/**
1702+
* Gets the instruction whose result provides the number of bytes written to the buffer.
1703+
*/
1704+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
16661705
}
16671706

16681707
/**
@@ -1696,7 +1735,15 @@ class SizedBufferMayWriteSideEffectInstruction extends WriteSideEffectInstructio
16961735
getOpcode() instanceof Opcode::SizedBufferMayWriteSideEffect
16971736
}
16981737

1699-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1738+
/**
1739+
* Gets the operand that holds the number of bytes written to the buffer.
1740+
*/
1741+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1742+
1743+
/**
1744+
* Gets the instruction whose result provides the number of bytes written to the buffer.
1745+
*/
1746+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
17001747
}
17011748

17021749
/**
@@ -1941,6 +1988,10 @@ class BuiltInOperationInstruction extends Instruction {
19411988
operation = Raw::getInstructionBuiltInOperation(this)
19421989
}
19431990

1991+
/**
1992+
* Gets the language-specific `BuildInOperation` object that specifies the operation that is
1993+
* performed by this instruction.
1994+
*/
19441995
final Language::BuiltInOperation getBuiltInOperation() { result = operation }
19451996
}
19461997

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

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ class Instruction extends Construction::TStageInstruction {
215215
result = Raw::getInstructionUnconvertedResultExpression(this)
216216
}
217217

218+
/**
219+
* Gets the language-specific type of the result produced by this instruction.
220+
*
221+
* Most consumers of the IR should use `getResultIRType()` instead. `getResultIRType()` uses a
222+
* less complex, language-neutral type system in which all semantically equivalent types share the
223+
* same `IRType` instance. For example, in C++, four different `Instruction`s might have three
224+
* different values for `getResultLanguageType()`: `unsigned int`, `char32_t`, and `wchar_t`,
225+
* whereas all four instructions would have the same value for `getResultIRType()`, `uint4`.
226+
*/
218227
final Language::LanguageType getResultLanguageType() {
219228
result = Construction::getInstructionResultType(this)
220229
}
@@ -1178,8 +1187,14 @@ class PointerDiffInstruction extends PointerArithmeticInstruction {
11781187
class UnaryInstruction extends Instruction {
11791188
UnaryInstruction() { getOpcode() instanceof UnaryOpcode }
11801189

1190+
/**
1191+
* Gets the sole operand of this instruction.
1192+
*/
11811193
final UnaryOperand getUnaryOperand() { result = getAnOperand() }
11821194

1195+
/**
1196+
* Gets the instruction whose result provides the sole operand of this instruction.
1197+
*/
11831198
final Instruction getUnary() { result = getUnaryOperand().getDef() }
11841199
}
11851200

@@ -1621,7 +1636,15 @@ class SizedBufferReadSideEffectInstruction extends ReadSideEffectInstruction {
16211636
getOpcode() instanceof Opcode::SizedBufferReadSideEffect
16221637
}
16231638

1624-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1639+
/**
1640+
* Gets the operand that holds the number of bytes read from the buffer.
1641+
*/
1642+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1643+
1644+
/**
1645+
* Gets the instruction whose result provides the number of bytes read from the buffer.
1646+
*/
1647+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
16251648
}
16261649

16271650
/**
@@ -1631,7 +1654,15 @@ class SizedBufferReadSideEffectInstruction extends ReadSideEffectInstruction {
16311654
class WriteSideEffectInstruction extends SideEffectInstruction, IndexedInstruction {
16321655
WriteSideEffectInstruction() { getOpcode() instanceof WriteSideEffectOpcode }
16331656

1634-
Instruction getArgumentDef() { result = getAnOperand().(AddressOperand).getDef() }
1657+
/**
1658+
* Get the operand that holds the address of the memory to be written.
1659+
*/
1660+
final AddressOperand getDestinationAddressOperand() { result = getAnOperand() }
1661+
1662+
/**
1663+
* Gets the instruction whose result provides the address of the memory to be written.
1664+
*/
1665+
Instruction getDestinationAddress() { result = getDestinationAddressOperand().getDef() }
16351666
}
16361667

16371668
/**
@@ -1662,7 +1693,15 @@ class SizedBufferMustWriteSideEffectInstruction extends WriteSideEffectInstructi
16621693
getOpcode() instanceof Opcode::SizedBufferMustWriteSideEffect
16631694
}
16641695

1665-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1696+
/**
1697+
* Gets the operand that holds the number of bytes written to the buffer.
1698+
*/
1699+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1700+
1701+
/**
1702+
* Gets the instruction whose result provides the number of bytes written to the buffer.
1703+
*/
1704+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
16661705
}
16671706

16681707
/**
@@ -1696,7 +1735,15 @@ class SizedBufferMayWriteSideEffectInstruction extends WriteSideEffectInstructio
16961735
getOpcode() instanceof Opcode::SizedBufferMayWriteSideEffect
16971736
}
16981737

1699-
Instruction getSizeDef() { result = getAnOperand().(BufferSizeOperand).getDef() }
1738+
/**
1739+
* Gets the operand that holds the number of bytes written to the buffer.
1740+
*/
1741+
final BufferSizeOperand getBufferSizeOperand() { result = getAnOperand() }
1742+
1743+
/**
1744+
* Gets the instruction whose result provides the number of bytes written to the buffer.
1745+
*/
1746+
final Instruction getBufferSize() { result = getBufferSizeOperand().getDef() }
17001747
}
17011748

17021749
/**
@@ -1941,6 +1988,10 @@ class BuiltInOperationInstruction extends Instruction {
19411988
operation = Raw::getInstructionBuiltInOperation(this)
19421989
}
19431990

1991+
/**
1992+
* Gets the language-specific `BuildInOperation` object that specifies the operation that is
1993+
* performed by this instruction.
1994+
*/
19441995
final Language::BuiltInOperation getBuiltInOperation() { result = operation }
19451996
}
19461997

0 commit comments

Comments
 (0)