Skip to content

C++: Make InitializeParameter and Uninitialized return memory results #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2018
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: 8 additions & 0 deletions cpp/ql/src/semmle/code/cpp/ir/internal/Instruction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ class InitializeParameterInstruction extends VariableInstruction {
final Parameter getParameter() {
result = var.(IRUserVariable).getVariable()
}

override final MemoryAccessKind getResultMemoryAccess() {
result instanceof IndirectMemoryAccess
}
}

class FieldAddressInstruction extends FieldInstruction {
Expand All @@ -561,6 +565,10 @@ class UninitializedInstruction extends Instruction {
UninitializedInstruction() {
opcode instanceof Opcode::Uninitialized
}

override final MemoryAccessKind getResultMemoryAccess() {
result instanceof IndirectMemoryAccess
}
}

class NoOpInstruction extends Instruction {
Expand Down
4 changes: 0 additions & 4 deletions cpp/ql/src/semmle/code/cpp/ir/internal/InstructionTag.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ private predicate elementIsInitialized(int elementIndex) {

newtype TInstructionTag =
OnlyInstructionTag() or // Single instruction (not including implicit Load)
InitializerUninitializedTag() or // Source expression of initializer
ParameterInitializerTag() or
InitializeThisTag() or
InitializerVariableAddressTag() or
InitializerLoadStringTag() or
Expand Down Expand Up @@ -88,8 +86,6 @@ newtype TInstructionTag =
*/
string getInstructionTagId(TInstructionTag tag) {
tag = OnlyInstructionTag() and result = "Only" or // Single instruction (not including implicit Load)
tag = InitializerUninitializedTag() and result = "InitUninit" or // Source expression of initializer
tag = ParameterInitializerTag() and result = "ParamInit" or
tag = InitializerVariableAddressTag() and result = "InitVarAddr" or
tag = InitializerStoreTag() and result = "InitStore" or
tag = AssignOperationLoadTag() and result = "AssignOpLoad" or
Expand Down
4 changes: 2 additions & 2 deletions cpp/ql/src/semmle/code/cpp/ir/internal/Opcode.qll
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ abstract class BuiltInOpcode extends Opcode {}

module Opcode {
class NoOp extends Opcode, TNoOp { override final string toString() { result = "NoOp" } }
class Uninitialized extends Opcode, TUninitialized { override final string toString() { result = "Uninitialized" } }
class InitializeParameter extends Opcode, TInitializeParameter { override final string toString() { result = "InitializeParameter" } }
class Uninitialized extends MemoryAccessOpcode, TUninitialized { override final string toString() { result = "Uninitialized" } }
class InitializeParameter extends MemoryAccessOpcode, TInitializeParameter { override final string toString() { result = "InitializeParameter" } }
class InitializeThis extends Opcode, TInitializeThis { override final string toString() { result = "InitializeThis" } }
class EnterFunction extends Opcode, TEnterFunction { override final string toString() { result = "EnterFunction" } }
class ExitFunction extends Opcode, TExitFunction { override final string toString() { result = "ExitFunction" } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ abstract class TranslatedVariableDeclaration extends

/**
* Represents the IR translation of a local variable with no initializer. The
* generated IR stores the result of an `Uninitialized` instruction into the
* variable.
* generated IR stores into the variable using an `Uninitialized` instruction,
* rather than a `Store`.
*/
class TranslatedUninitializedVariable extends
TranslatedVariableDeclaration {
Expand Down Expand Up @@ -127,12 +127,6 @@ class TranslatedUninitializedVariable extends
) or
(
tag = InitializerStoreTag() and
opcode instanceof Opcode::Store and
resultType = var.getType().getUnspecifiedType() and
isGLValue = false
) or
(
tag = InitializerUninitializedTag() and
opcode instanceof Opcode::Uninitialized and
resultType = var.getType().getUnspecifiedType() and
isGLValue = false
Expand All @@ -145,10 +139,6 @@ class TranslatedUninitializedVariable extends
(
(
tag = InitializerVariableAddressTag() and
result = getInstruction(InitializerUninitializedTag())
) or
(
tag = InitializerUninitializedTag() and
result = getInstruction(InitializerStoreTag())
) or
(
Expand All @@ -169,11 +159,7 @@ class TranslatedUninitializedVariable extends
(
operandTag instanceof LoadStoreAddressOperand and
result = getInstruction(InitializerVariableAddressTag())
) or
(
operandTag instanceof CopySourceOperand and
result = getInstruction(InitializerUninitializedTag())
)
)
)
}

Expand Down
20 changes: 3 additions & 17 deletions cpp/ql/src/semmle/code/cpp/ir/internal/TranslatedFunction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class TranslatedParameter extends TranslatedElement, TTranslatedParameter {
}

override final Instruction getFirstInstruction() {
result = getInstruction(ParameterInitializerTag())
result = getInstruction(InitializerVariableAddressTag())
}

override final TranslatedElement getChild(int id) {
Expand All @@ -334,10 +334,6 @@ class TranslatedParameter extends TranslatedElement, TTranslatedParameter {
EdgeKind kind) {
kind instanceof GotoEdge and
(
(
tag = ParameterInitializerTag() and
result = getInstruction(InitializerVariableAddressTag())
) or
(
tag = InitializerVariableAddressTag() and
result = getInstruction(InitializerStoreTag())
Expand All @@ -355,12 +351,6 @@ class TranslatedParameter extends TranslatedElement, TTranslatedParameter {

override final predicate hasInstruction(Opcode opcode, InstructionTag tag,
Type resultType, boolean isGLValue) {
(
tag = ParameterInitializerTag() and
opcode instanceof Opcode::InitializeParameter and
resultType = param.getType().getUnspecifiedType() and
isGLValue = false
) or
(
tag = InitializerVariableAddressTag() and
opcode instanceof Opcode::VariableAddress and
Expand All @@ -369,15 +359,15 @@ class TranslatedParameter extends TranslatedElement, TTranslatedParameter {
) or
(
tag = InitializerStoreTag() and
opcode instanceof Opcode::Store and
opcode instanceof Opcode::InitializeParameter and
resultType = param.getType().getUnspecifiedType() and
isGLValue = false
)
}

override final IRVariable getInstructionVariable(InstructionTag tag) {
(
tag = ParameterInitializerTag() or
tag = InitializerStoreTag() or
tag = InitializerVariableAddressTag()
) and
result = getIRUserVariable(getFunction(), param)
Expand All @@ -390,10 +380,6 @@ class TranslatedParameter extends TranslatedElement, TTranslatedParameter {
(
operandTag instanceof LoadStoreAddressOperand and
result = getInstruction(InitializerVariableAddressTag())
) or
(
operandTag instanceof CopySourceOperand and
result = getInstruction(ParameterInitializerTag())
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ class InitializeParameterInstruction extends VariableInstruction {
final Parameter getParameter() {
result = var.(IRUserVariable).getVariable()
}

override final MemoryAccessKind getResultMemoryAccess() {
result instanceof IndirectMemoryAccess
}
}

class FieldAddressInstruction extends FieldInstruction {
Expand All @@ -561,6 +565,10 @@ class UninitializedInstruction extends Instruction {
UninitializedInstruction() {
opcode instanceof Opcode::Uninitialized
}

override final MemoryAccessKind getResultMemoryAccess() {
result instanceof IndirectMemoryAccess
}
}

class NoOpInstruction extends Instruction {
Expand Down
8 changes: 8 additions & 0 deletions cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/Instruction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ class InitializeParameterInstruction extends VariableInstruction {
final Parameter getParameter() {
result = var.(IRUserVariable).getVariable()
}

override final MemoryAccessKind getResultMemoryAccess() {
result instanceof IndirectMemoryAccess
}
}

class FieldAddressInstruction extends FieldInstruction {
Expand All @@ -561,6 +565,10 @@ class UninitializedInstruction extends Instruction {
UninitializedInstruction() {
opcode instanceof Opcode::Uninitialized
}

override final MemoryAccessKind getResultMemoryAccess() {
result instanceof IndirectMemoryAccess
}
}

class NoOpInstruction extends Instruction {
Expand Down
Loading