mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C#/C++: Share IR implementation
This commit is contained in:
committed by
AndreiDiaconu1
parent
50ba4d1fda
commit
609ca034c0
@@ -42,6 +42,7 @@ private newtype TOpcode =
|
||||
TDynamicCastToVoid() or
|
||||
TVariableAddress() or
|
||||
TFieldAddress() or
|
||||
TIndexedElementAddress() or
|
||||
TFunctionAddress() or
|
||||
TConstant() or
|
||||
TStringConstant() or
|
||||
@@ -190,6 +191,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 IndexedElementAddress extends BinaryOpcode, TIndexedElementAddress { override final string toString() { result = "IndexedElementAddress" } }
|
||||
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" } }
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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_;
|
||||
}
|
||||
@@ -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())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -52,6 +52,10 @@ predicate hasAsmOperandIndex(int operandIndex) {
|
||||
)
|
||||
}
|
||||
|
||||
int getTypeSize(Type type) {
|
||||
result = type.getSize()
|
||||
}
|
||||
|
||||
int getPointerSize() {
|
||||
exists(Cpp::NullPointerType nullptr |
|
||||
result = nullptr.getSize()
|
||||
|
||||
Reference in New Issue
Block a user