Merge pull request #1600 from AndreiDiaconu1/ircsharp

C#: Initial port of IR for C#
This commit is contained in:
Calum Grant
2019-08-29 09:26:34 +01:00
committed by GitHub
94 changed files with 12801 additions and 19 deletions

View File

@@ -43,6 +43,7 @@ private newtype TOpcode =
TVariableAddress() or
TFieldAddress() or
TFunctionAddress() or
TElementsAddress() or
TConstant() or
TStringConstant() or
TConditionalBranch() or
@@ -72,7 +73,8 @@ private newtype TOpcode =
TBufferMayWriteSideEffect() or
TChi() or
TInlineAsm() or
TUnreached()
TUnreached() or
TNewObj()
class Opcode extends TOpcode {
string toString() {
@@ -190,6 +192,7 @@ module Opcode {
class DynamicCastToVoid extends UnaryOpcode, TDynamicCastToVoid { override final string toString() { result = "DynamicCastToVoid" } }
class VariableAddress extends Opcode, TVariableAddress { override final string toString() { result = "VariableAddress" } }
class FieldAddress extends UnaryOpcode, TFieldAddress { override final string toString() { result = "FieldAddress" } }
class ElementsAddress extends UnaryOpcode, TElementsAddress { override final string toString() { result = "ElementsAddress" } }
class FunctionAddress extends Opcode, TFunctionAddress { override final string toString() { result = "FunctionAddress" } }
class Constant extends Opcode, TConstant { override final string toString() { result = "Constant" } }
class StringConstant extends Opcode, TStringConstant { override final string toString() { result = "StringConstant" } }
@@ -221,4 +224,5 @@ module Opcode {
class Chi extends Opcode, TChi { override final string toString() { result = "Chi" } }
class InlineAsm extends Opcode, TInlineAsm { override final string toString() { result = "InlineAsm" } }
class Unreached extends Opcode, TUnreached { override final string toString() { result = "Unreached" } }
class NewObj extends Opcode, TNewObj { override final string toString() { result = "NewObj" } }
}

View File

@@ -1,4 +1,5 @@
private import semmle.code.cpp.ir.internal.TempVariableTag
private import internal.TempVariableTagInternal
private import Imports::TempVariableTag
class TempVariableTag extends TTempVariableTag {
string toString() {

View File

@@ -512,7 +512,7 @@ class Instruction extends Construction::TInstruction {
else if getResultType() instanceof Language::UnknownType then
result = Construction::getInstructionResultSize(this)
else (
result = getResultType().getSize()
result = Language::getTypeSize(getResultType())
)
}

View File

@@ -186,7 +186,7 @@ class Operand extends TOperand {
* a known constant size, this predicate does not hold.
*/
int getSize() {
result = getType().getSize()
result = Language::getTypeSize(getType())
}
}
@@ -450,7 +450,7 @@ class SideEffectOperand extends TypedOperand {
if getType() instanceof Language::UnknownType then
result = Construction::getInstructionOperandSize(useInstr, tag)
else
result = getType().getSize()
result = Language::getTypeSize(getType())
}
override MemoryAccessKind getMemoryAccess() {

View File

@@ -0,0 +1,6 @@
import semmle.code.cpp.ir.internal.IRCppLanguage as Language
private import semmle.code.cpp.ir.internal.TempVariableTag as TempVariableTag_
module Imports {
module TempVariableTag = TempVariableTag_;
}

View File

@@ -512,7 +512,7 @@ class Instruction extends Construction::TInstruction {
else if getResultType() instanceof Language::UnknownType then
result = Construction::getInstructionResultSize(this)
else (
result = getResultType().getSize()
result = Language::getTypeSize(getResultType())
)
}

View File

@@ -186,7 +186,7 @@ class Operand extends TOperand {
* a known constant size, this predicate does not hold.
*/
int getSize() {
result = getType().getSize()
result = Language::getTypeSize(getType())
}
}
@@ -450,7 +450,7 @@ class SideEffectOperand extends TypedOperand {
if getType() instanceof Language::UnknownType then
result = Construction::getInstructionOperandSize(useInstr, tag)
else
result = getType().getSize()
result = Language::getTypeSize(getType())
}
override MemoryAccessKind getMemoryAccess() {

View File

@@ -512,7 +512,7 @@ class Instruction extends Construction::TInstruction {
else if getResultType() instanceof Language::UnknownType then
result = Construction::getInstructionResultSize(this)
else (
result = getResultType().getSize()
result = Language::getTypeSize(getResultType())
)
}

View File

@@ -186,7 +186,7 @@ class Operand extends TOperand {
* a known constant size, this predicate does not hold.
*/
int getSize() {
result = getType().getSize()
result = Language::getTypeSize(getType())
}
}
@@ -450,7 +450,7 @@ class SideEffectOperand extends TypedOperand {
if getType() instanceof Language::UnknownType then
result = Construction::getInstructionOperandSize(useInstr, tag)
else
result = getType().getSize()
result = Language::getTypeSize(getType())
}
override MemoryAccessKind getMemoryAccess() {

View File

@@ -52,6 +52,10 @@ predicate hasAsmOperandIndex(int operandIndex) {
)
}
int getTypeSize(Type type) {
result = type.getSize()
}
int getPointerSize() {
exists(Cpp::NullPointerType nullptr |
result = nullptr.getSize()