mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: Allow annotating IR dumps with Alias Analysis info
This commit adds a `PrintAliasAnalysis.qll` module, which can be imported alongside `PrintIR.qll` to annotate those dumps with alias analysis results.
This commit is contained in:
@@ -249,6 +249,10 @@
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll",
|
||||
"csharp/ql/src/experimental/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll"
|
||||
],
|
||||
"SSA PrintAliasAnalysis": [
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/PrintAliasAnalysis.qll",
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/PrintAliasAnalysis.qll"
|
||||
],
|
||||
"C++ SSA AliasAnalysisImports": [
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysisImports.qll",
|
||||
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysisImports.qll"
|
||||
|
||||
@@ -400,3 +400,46 @@ predicate addressOperandAllocationAndOffset(
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicates used only for printing annotated IR dumps. These should not be used in production
|
||||
* queries.
|
||||
*/
|
||||
module Print {
|
||||
string getOperandProperty(Operand operand, string key) {
|
||||
key = "alloc" and
|
||||
result =
|
||||
strictconcat(Configuration::Allocation allocation, IntValue bitOffset |
|
||||
addressOperandAllocationAndOffset(operand, allocation, bitOffset)
|
||||
|
|
||||
allocation.toString() + Ints::getBitOffsetString(bitOffset), ", "
|
||||
)
|
||||
or
|
||||
key = "prop" and
|
||||
result =
|
||||
strictconcat(Instruction destInstr, IntValue bitOffset, string value |
|
||||
operandIsPropagatedIncludingByCall(operand, bitOffset, destInstr) and
|
||||
if destInstr = operand.getUse()
|
||||
then value = "@" + Ints::getBitOffsetString(bitOffset) + "->result"
|
||||
else value = "@" + Ints::getBitOffsetString(bitOffset) + "->" + destInstr.getResultId()
|
||||
|
|
||||
value, ", "
|
||||
)
|
||||
}
|
||||
|
||||
string getInstructionProperty(Instruction instr, string key) {
|
||||
key = "prop" and
|
||||
result =
|
||||
strictconcat(IntValue bitOffset, Operand sourceOperand, string value |
|
||||
operandIsPropagatedIncludingByCall(sourceOperand, bitOffset, instr) and
|
||||
if instr = sourceOperand.getUse()
|
||||
then value = sourceOperand.getDumpId() + Ints::getBitOffsetString(bitOffset) + "->@"
|
||||
else
|
||||
value =
|
||||
sourceOperand.getUse().getResultId() + "." + sourceOperand.getDumpId() +
|
||||
Ints::getBitOffsetString(bitOffset) + "->@"
|
||||
|
|
||||
value, ", "
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Include this module to annotate IR dumps with information computed by `AliasAnalysis.qll`.
|
||||
*/
|
||||
|
||||
private import AliasAnalysisInternal
|
||||
private import InputIR
|
||||
private import AliasAnalysisImports
|
||||
private import AliasAnalysis
|
||||
private import semmle.code.cpp.ir.internal.IntegerConstant
|
||||
|
||||
private class AliasPropertyProvider extends IRPropertyProvider {
|
||||
override string getOperandProperty(Operand operand, string key) {
|
||||
result = Print::getOperandProperty(operand, key)
|
||||
}
|
||||
|
||||
override string getInstructionProperty(Instruction instr, string key) {
|
||||
result = Print::getInstructionProperty(instr, key)
|
||||
}
|
||||
}
|
||||
@@ -400,3 +400,46 @@ predicate addressOperandAllocationAndOffset(
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicates used only for printing annotated IR dumps. These should not be used in production
|
||||
* queries.
|
||||
*/
|
||||
module Print {
|
||||
string getOperandProperty(Operand operand, string key) {
|
||||
key = "alloc" and
|
||||
result =
|
||||
strictconcat(Configuration::Allocation allocation, IntValue bitOffset |
|
||||
addressOperandAllocationAndOffset(operand, allocation, bitOffset)
|
||||
|
|
||||
allocation.toString() + Ints::getBitOffsetString(bitOffset), ", "
|
||||
)
|
||||
or
|
||||
key = "prop" and
|
||||
result =
|
||||
strictconcat(Instruction destInstr, IntValue bitOffset, string value |
|
||||
operandIsPropagatedIncludingByCall(operand, bitOffset, destInstr) and
|
||||
if destInstr = operand.getUse()
|
||||
then value = "@" + Ints::getBitOffsetString(bitOffset) + "->result"
|
||||
else value = "@" + Ints::getBitOffsetString(bitOffset) + "->" + destInstr.getResultId()
|
||||
|
|
||||
value, ", "
|
||||
)
|
||||
}
|
||||
|
||||
string getInstructionProperty(Instruction instr, string key) {
|
||||
key = "prop" and
|
||||
result =
|
||||
strictconcat(IntValue bitOffset, Operand sourceOperand, string value |
|
||||
operandIsPropagatedIncludingByCall(sourceOperand, bitOffset, instr) and
|
||||
if instr = sourceOperand.getUse()
|
||||
then value = sourceOperand.getDumpId() + Ints::getBitOffsetString(bitOffset) + "->@"
|
||||
else
|
||||
value =
|
||||
sourceOperand.getUse().getResultId() + "." + sourceOperand.getDumpId() +
|
||||
Ints::getBitOffsetString(bitOffset) + "->@"
|
||||
|
|
||||
value, ", "
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Include this module to annotate IR dumps with information computed by `AliasAnalysis.qll`.
|
||||
*/
|
||||
|
||||
private import AliasAnalysisInternal
|
||||
private import InputIR
|
||||
private import AliasAnalysisImports
|
||||
private import AliasAnalysis
|
||||
private import semmle.code.cpp.ir.internal.IntegerConstant
|
||||
|
||||
private class AliasPropertyProvider extends IRPropertyProvider {
|
||||
override string getOperandProperty(Operand operand, string key) {
|
||||
result = Print::getOperandProperty(operand, key)
|
||||
}
|
||||
|
||||
override string getInstructionProperty(Instruction instr, string key) {
|
||||
result = Print::getInstructionProperty(instr, key)
|
||||
}
|
||||
}
|
||||
@@ -400,3 +400,46 @@ predicate addressOperandAllocationAndOffset(
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Predicates used only for printing annotated IR dumps. These should not be used in production
|
||||
* queries.
|
||||
*/
|
||||
module Print {
|
||||
string getOperandProperty(Operand operand, string key) {
|
||||
key = "alloc" and
|
||||
result =
|
||||
strictconcat(Configuration::Allocation allocation, IntValue bitOffset |
|
||||
addressOperandAllocationAndOffset(operand, allocation, bitOffset)
|
||||
|
|
||||
allocation.toString() + Ints::getBitOffsetString(bitOffset), ", "
|
||||
)
|
||||
or
|
||||
key = "prop" and
|
||||
result =
|
||||
strictconcat(Instruction destInstr, IntValue bitOffset, string value |
|
||||
operandIsPropagatedIncludingByCall(operand, bitOffset, destInstr) and
|
||||
if destInstr = operand.getUse()
|
||||
then value = "@" + Ints::getBitOffsetString(bitOffset) + "->result"
|
||||
else value = "@" + Ints::getBitOffsetString(bitOffset) + "->" + destInstr.getResultId()
|
||||
|
|
||||
value, ", "
|
||||
)
|
||||
}
|
||||
|
||||
string getInstructionProperty(Instruction instr, string key) {
|
||||
key = "prop" and
|
||||
result =
|
||||
strictconcat(IntValue bitOffset, Operand sourceOperand, string value |
|
||||
operandIsPropagatedIncludingByCall(sourceOperand, bitOffset, instr) and
|
||||
if instr = sourceOperand.getUse()
|
||||
then value = sourceOperand.getDumpId() + Ints::getBitOffsetString(bitOffset) + "->@"
|
||||
else
|
||||
value =
|
||||
sourceOperand.getUse().getResultId() + "." + sourceOperand.getDumpId() +
|
||||
Ints::getBitOffsetString(bitOffset) + "->@"
|
||||
|
|
||||
value, ", "
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user