Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/identical-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRVariable.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRVariable.qll"
],
"C++ IR FunctionIR": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/FunctionIR.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/FunctionIR.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/FunctionIR.qll"
"C++ IR IRFunction": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRFunction.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRFunction.qll",
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRFunction.qll"
],
"C++ IR Operand": [
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Operand.qll",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FunctionIR
import IRFunction
import Instruction
import IRBlock
import IRVariable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class IRBlockBase extends TIRBlock {
result = getInstructionCount(this)
}

final FunctionIR getEnclosingFunctionIR() {
result = getFirstInstruction(this).getEnclosingFunctionIR()
final IRFunction getEnclosingIRFunction() {
result = getFirstInstruction(this).getEnclosingIRFunction()
}

final Function getEnclosingFunction() {
Expand Down Expand Up @@ -116,7 +116,7 @@ class IRBlock extends IRBlockBase {
* Holds if this block is reachable from the entry point of its function
*/
final predicate isReachableFromFunctionEntry() {
this = getEnclosingFunctionIR().getEntryBlock() or
this = getEnclosingIRFunction().getEntryBlock() or
getAPredecessor().isReachableFromFunctionEntry()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ private import internal.IRInternal
import Instruction
import cpp

private newtype TFunctionIR =
MkFunctionIR(Function func) {
private newtype TIRFunction =
MkIRFunction(Function func) {
Construction::functionHasIR(func)
}

/**
* Represents the IR for a function.
*/
class FunctionIR extends TFunctionIR {
class IRFunction extends TIRFunction {
Function func;

FunctionIR() {
this = MkFunctionIR(func)
IRFunction() {
this = MkIRFunction(func)
}

final string toString() {
Expand All @@ -40,33 +40,33 @@ class FunctionIR extends TFunctionIR {
*/
pragma[noinline]
final EnterFunctionInstruction getEnterFunctionInstruction() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

/**
* Gets the exit point for this function.
*/
pragma[noinline]
final ExitFunctionInstruction getExitFunctionInstruction() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

pragma[noinline]
final UnmodeledDefinitionInstruction getUnmodeledDefinitionInstruction() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

pragma[noinline]
final UnmodeledUseInstruction getUnmodeledUseInstruction() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

/**
* Gets the single return instruction for this function.
*/
pragma[noinline]
final ReturnInstruction getReturnInstruction() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

/**
Expand All @@ -75,7 +75,7 @@ class FunctionIR extends TFunctionIR {
*/
pragma[noinline]
final IRReturnVariable getReturnVariable() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

/**
Expand All @@ -90,13 +90,13 @@ class FunctionIR extends TFunctionIR {
* Gets all instructions in this function.
*/
final Instruction getAnInstruction() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}

/**
* Gets all blocks in this function.
*/
final IRBlock getABlock() {
result.getEnclosingFunctionIR() = this
result.getEnclosingIRFunction() = this
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
private import internal.IRInternal
import FunctionIR
import IRFunction
import cpp
import semmle.code.cpp.ir.implementation.TempVariableTag
private import semmle.code.cpp.ir.internal.IRUtilities
Expand Down Expand Up @@ -48,7 +48,7 @@ abstract class IRVariable extends TIRVariable {
/**
* Gets the IR for the function that references this variable.
*/
final FunctionIR getEnclosingFunctionIR() {
final IRFunction getEnclosingIRFunction() {
result.getFunction() = func
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
private import internal.IRInternal
import FunctionIR
import IRFunction
import IRBlock
import IRVariable
import Operand
Expand All @@ -15,7 +15,7 @@ module InstructionSanity {
/**
* Holds if the instruction `instr` should be expected to have an operand
* with operand tag `tag`. Only holds for singleton operand tags. Tags with
* parameters, such as `PhiOperand` and `PositionalArgumentOperand` are handled
* parameters, such as `PhiInputOperand` and `PositionalArgumentOperand` are handled
* separately in `unexpectedOperand`.
*/
private predicate expectsOperand(Instruction instr, OperandTag tag) {
Expand Down Expand Up @@ -87,7 +87,7 @@ module InstructionSanity {
*/
query predicate missingPhiOperand(PhiInstruction instr, IRBlock pred) {
pred = instr.getBlock().getAPredecessor() and
not exists(PhiOperand operand |
not exists(PhiInputOperand operand |
operand = instr.getAnOperand() and
operand.getPredecessorBlock() = pred
)
Expand Down Expand Up @@ -153,7 +153,7 @@ module InstructionSanity {
query predicate operandAcrossFunctions(Operand operand, Instruction instr, Instruction defInstr) {
operand.getUseInstruction() = instr and
operand.getDefinitionInstruction() = defInstr and
instr.getEnclosingFunctionIR() != defInstr.getEnclosingFunctionIR()
instr.getEnclosingIRFunction() != defInstr.getEnclosingIRFunction()
}

/**
Expand All @@ -174,10 +174,10 @@ module InstructionSanity {
*
* This check ensures we don't have too _few_ back edges.
*/
query predicate containsLoopOfForwardEdges(FunctionIR f) {
query predicate containsLoopOfForwardEdges(IRFunction f) {
exists(IRBlock block |
forwardEdge+(block, block) and
block.getEnclosingFunctionIR() = f
block.getEnclosingIRFunction() = f
)
}

Expand All @@ -190,7 +190,7 @@ module InstructionSanity {
* This check ensures we don't have too _many_ back edges.
*/
query predicate lostReachability(IRBlock block) {
exists(FunctionIR f, IRBlock entry |
exists(IRFunction f, IRBlock entry |
entry = f.getEntryBlock() and
entry.getASuccessor+() = block and
not forwardEdge+(entry, block) and
Expand Down Expand Up @@ -373,14 +373,14 @@ class Instruction extends Construction::TInstruction {
* Gets the function that contains this instruction.
*/
final Function getEnclosingFunction() {
result = getEnclosingFunctionIR().getFunction()
result = getEnclosingIRFunction().getFunction()
}

/**
* Gets the FunctionIR object that contains the IR for this instruction.
* Gets the IRFunction object that contains the IR for this instruction.
*/
final FunctionIR getEnclosingFunctionIR() {
result = Construction::getInstructionEnclosingFunctionIR(this)
final IRFunction getEnclosingIRFunction() {
result = Construction::getInstructionEnclosingIRFunction(this)
}

/**
Expand Down Expand Up @@ -1622,15 +1622,22 @@ class PhiInstruction extends Instruction {
result instanceof PhiMemoryAccess
}

/**
* Gets all of the instruction's `PhiInputOperand`s, representing the values that flow from each predecessor block.
*/
final PhiInputOperand getAnInputOperand() {
result = this.getAnOperand()
}

/**
* Gets an instruction that defines the input to one of the operands of this
* instruction. It's possible for more than one operand to have the same
* defining instruction, so this predicate will have the same number of
* results as `getAnOperand()` or fewer.
* results as `getAnInputOperand()` or fewer.
*/
pragma[noinline]
final Instruction getAnOperandDefinitionInstruction() {
result = this.getAnOperand().(PhiOperand).getDefinitionInstruction()
final Instruction getAnInput() {
result = this.getAnInputOperand().getDefinitionInstruction()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Operand extends TOperand {
result = getUseInstruction().getLocation()
}

final FunctionIR getEnclosingFunctionIR() {
result = getUseInstruction().getEnclosingFunctionIR()
final IRFunction getEnclosingIRFunction() {
result = getUseInstruction().getEnclosingIRFunction()
}

/**
Expand Down Expand Up @@ -379,12 +379,12 @@ class SideEffectOperand extends TypedOperand {
/**
* An operand of a `PhiInstruction`.
*/
class PhiOperand extends MemoryOperand, TPhiOperand {
class PhiInputOperand extends MemoryOperand, TPhiOperand {
PhiInstruction useInstr;
Instruction defInstr;
IRBlock predecessorBlock;

PhiOperand() {
PhiInputOperand() {
this = TPhiOperand(useInstr, defInstr, predecessorBlock)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private string getAdditionalBlockProperty(IRBlock block, string key) {
}

private newtype TPrintableIRNode =
TPrintableFunctionIR(FunctionIR funcIR) {
shouldPrintFunction(funcIR.getFunction())
TPrintableIRFunction(IRFunction irFunc) {
shouldPrintFunction(irFunc.getFunction())
} or
TPrintableIRBlock(IRBlock block) {
shouldPrintFunction(block.getEnclosingFunction())
Expand Down Expand Up @@ -113,30 +113,30 @@ abstract class PrintableIRNode extends TPrintableIRNode {
}

/**
* An IR graph node representing a `FunctionIR` object.
* An IR graph node representing a `IRFunction` object.
*/
class PrintableFunctionIR extends PrintableIRNode, TPrintableFunctionIR {
FunctionIR funcIR;
class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
IRFunction irFunc;

PrintableFunctionIR() {
this = TPrintableFunctionIR(funcIR)
PrintableIRFunction() {
this = TPrintableIRFunction(irFunc)
}

override string toString() {
result = funcIR.toString()
result = irFunc.toString()
}

override Location getLocation() {
result = funcIR.getLocation()
result = irFunc.getLocation()
}

override string getLabel() {
result = getIdentityString(funcIR.getFunction())
result = getIdentityString(irFunc.getFunction())
}

override int getOrder() {
this = rank[result + 1](PrintableFunctionIR orderedFunc, Location location |
location = orderedFunc.getFunctionIR().getLocation() |
this = rank[result + 1](PrintableIRFunction orderedFunc, Location location |
location = orderedFunc.getIRFunction().getLocation() |
orderedFunc order by location.getFile().getAbsolutePath(), location.getStartLine(),
location.getStartColumn(), orderedFunc.getLabel()
)
Expand All @@ -146,8 +146,8 @@ class PrintableFunctionIR extends PrintableIRNode, TPrintableFunctionIR {
none()
}

final FunctionIR getFunctionIR() {
result = funcIR
final IRFunction getIRFunction() {
result = irFunc
}
}

Expand Down Expand Up @@ -185,8 +185,8 @@ class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
any()
}

override final PrintableFunctionIR getParent() {
result.getFunctionIR() = block.getEnclosingFunctionIR()
override final PrintableIRFunction getParent() {
result.getIRFunction() = block.getEnclosingIRFunction()
}

override string getProperty(string key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ int getConstantValue(Instruction instr) {
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
exists(PhiInstruction phi |
phi = instr and
result = max(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnOperandDefinitionInstruction() | getConstantValueToPhi(def))
result = max(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def)) and
result = min(Instruction def | def = phi.getAnInput() | getConstantValueToPhi(def))
)
}

pragma[noinline]
int getConstantValueToPhi(Instruction def) {
exists(PhiInstruction phi |
result = getConstantValue(def) and
def = phi.getAnOperandDefinitionInstruction()
def = phi.getAnInput()
)
}

Expand Down
Loading