mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
C++/C#: Autoformat all the things
This commit is contained in:
@@ -7,27 +7,13 @@ private import internal.IRTypeInternal
|
||||
private newtype TIRType =
|
||||
TIRVoidType() or
|
||||
TIRUnknownType() or
|
||||
TIRErrorType() {
|
||||
Language::hasErrorType()
|
||||
} or
|
||||
TIRBooleanType(int byteSize) {
|
||||
Language::hasBooleanType(byteSize)
|
||||
} or
|
||||
TIRSignedIntegerType(int byteSize) {
|
||||
Language::hasSignedIntegerType(byteSize)
|
||||
} or
|
||||
TIRUnsignedIntegerType(int byteSize) {
|
||||
Language::hasUnsignedIntegerType(byteSize)
|
||||
} or
|
||||
TIRFloatingPointType(int byteSize) {
|
||||
Language::hasFloatingPointType(byteSize)
|
||||
} or
|
||||
TIRAddressType(int byteSize) {
|
||||
Language::hasAddressType(byteSize)
|
||||
} or
|
||||
TIRFunctionAddressType(int byteSize) {
|
||||
Language::hasFunctionAddressType(byteSize)
|
||||
} or
|
||||
TIRErrorType() { Language::hasErrorType() } or
|
||||
TIRBooleanType(int byteSize) { Language::hasBooleanType(byteSize) } or
|
||||
TIRSignedIntegerType(int byteSize) { Language::hasSignedIntegerType(byteSize) } or
|
||||
TIRUnsignedIntegerType(int byteSize) { Language::hasUnsignedIntegerType(byteSize) } or
|
||||
TIRFloatingPointType(int byteSize) { Language::hasFloatingPointType(byteSize) } or
|
||||
TIRAddressType(int byteSize) { Language::hasAddressType(byteSize) } or
|
||||
TIRFunctionAddressType(int byteSize) { Language::hasFunctionAddressType(byteSize) } or
|
||||
TIROpaqueType(Language::OpaqueTypeTag tag, int byteSize) {
|
||||
Language::hasOpaqueType(tag, byteSize)
|
||||
}
|
||||
@@ -49,9 +35,7 @@ class IRType extends TIRType {
|
||||
* Gets a string that uniquely identifies this `IRType`. This string is often the same as the
|
||||
* result of `IRType.toString()`, but for some types it may be more verbose to ensure uniqueness.
|
||||
*/
|
||||
string getIdentityString() {
|
||||
result = toString()
|
||||
}
|
||||
string getIdentityString() { result = toString() }
|
||||
|
||||
/**
|
||||
* Gets the size of the type, in bytes, if known.
|
||||
@@ -215,9 +199,7 @@ class IRFunctionAddressType extends IRSizedType, TIRFunctionAddressType {
|
||||
class IROpaqueType extends IRSizedType, TIROpaqueType {
|
||||
Language::OpaqueTypeTag tag;
|
||||
|
||||
IROpaqueType() {
|
||||
this = TIROpaqueType(tag, byteSize)
|
||||
}
|
||||
IROpaqueType() { this = TIROpaqueType(tag, byteSize) }
|
||||
|
||||
final override string toString() {
|
||||
result = "opaque" + byteSize.toString() + "{" + tag.toString() + "}"
|
||||
@@ -246,7 +228,8 @@ module IRTypeSanity {
|
||||
|
||||
query predicate multipleCanonicalLanguageTypes(IRType type, string message) {
|
||||
strictcount(type.getCanonicalLanguageType()) > 1 and
|
||||
message = "Type has multiple canonical `LanguageType`s: " + concat(type.getCanonicalLanguageType().toString(), ", ")
|
||||
message = "Type has multiple canonical `LanguageType`s: " +
|
||||
concat(type.getCanonicalLanguageType().toString(), ", ")
|
||||
}
|
||||
|
||||
query predicate missingIRType(Language::LanguageType type, string message) {
|
||||
@@ -256,7 +239,8 @@ module IRTypeSanity {
|
||||
|
||||
query predicate multipleIRTypes(Language::LanguageType type, string message) {
|
||||
strictcount(type.getIRType()) > 1 and
|
||||
message = "`LanguageType` " + type.getAQlClass() + " has multiple `IRType`s: " + concat(type.getIRType().toString(), ", ")
|
||||
message = "`LanguageType` " + type.getAQlClass() + " has multiple `IRType`s: " +
|
||||
concat(type.getIRType().toString(), ", ")
|
||||
}
|
||||
|
||||
import Language::LanguageTypeSanity
|
||||
|
||||
@@ -354,4 +354,3 @@ MemoryLocation getOperandMemoryLocation(MemoryOperand operand) {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -305,9 +305,7 @@ private module Cached {
|
||||
|
||||
cached
|
||||
predicate needsUnknownOpaqueType(int byteSize) {
|
||||
exists(TranslatedElement element |
|
||||
element.needsUnknownOpaqueType(byteSize)
|
||||
)
|
||||
exists(TranslatedElement element | element.needsUnknownOpaqueType(byteSize))
|
||||
}
|
||||
|
||||
cached
|
||||
|
||||
@@ -455,7 +455,8 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
|
||||
tag instanceof OnlyInstructionTag and
|
||||
operandType = arg.getType().getUnspecifiedType() and
|
||||
not operandType instanceof DerivedType and
|
||||
operandTag instanceof SideEffectOperandTag |
|
||||
operandTag instanceof SideEffectOperandTag
|
||||
|
|
||||
// If the type we select is an incomplete type (e.g. a forward-declared `struct`), there will
|
||||
// not be a `CppType` that represents that type. In that case, fall back to `UnknownCppType`.
|
||||
result = getTypeForPRValueOrUnknown(operandType)
|
||||
|
||||
@@ -65,8 +65,8 @@ private predicate ignoreExprAndDescendants(Expr expr) {
|
||||
)
|
||||
or
|
||||
// Do not translate input/output variables in GNU asm statements
|
||||
// getRealParent(expr) instanceof AsmStmt
|
||||
// or
|
||||
// getRealParent(expr) instanceof AsmStmt
|
||||
// or
|
||||
ignoreExprAndDescendants(getRealParent(expr)) // recursive case
|
||||
or
|
||||
// We do not yet translate destructors properly, so for now we ignore any
|
||||
@@ -617,7 +617,7 @@ abstract class TranslatedElement extends TTranslatedElement {
|
||||
int getInstructionResultSize(InstructionTag tag) { none() }
|
||||
|
||||
predicate needsUnknownOpaqueType(int byteSize) { none() }
|
||||
|
||||
|
||||
/**
|
||||
* If the instruction specified by `tag` is a `StringConstantInstruction`,
|
||||
* gets the `StringLiteral` for that instruction.
|
||||
|
||||
@@ -54,10 +54,9 @@ abstract class TranslatedExpr extends TranslatedElement {
|
||||
abstract predicate producesExprResult();
|
||||
|
||||
final CppType getResultType() {
|
||||
if isResultGLValue() then
|
||||
result = getTypeForGLValue(expr.getType())
|
||||
else
|
||||
result = getTypeForPRValue(expr.getType())
|
||||
if isResultGLValue()
|
||||
then result = getTypeForGLValue(expr.getType())
|
||||
else result = getTypeForPRValue(expr.getType())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +337,7 @@ abstract class TranslatedCrementOperation extends TranslatedNonConstantExpr {
|
||||
final override string getInstructionConstantValue(InstructionTag tag) {
|
||||
tag = CrementConstantTag() and
|
||||
exists(Type resultType |
|
||||
resultType = expr.getUnspecifiedType() and
|
||||
resultType = expr.getUnspecifiedType() and
|
||||
(
|
||||
resultType instanceof IntegralOrEnumType and result = "1"
|
||||
or
|
||||
@@ -353,18 +352,15 @@ abstract class TranslatedCrementOperation extends TranslatedNonConstantExpr {
|
||||
exists(Type resultType |
|
||||
resultType = expr.getUnspecifiedType() and
|
||||
(
|
||||
(
|
||||
resultType instanceof ArithmeticType and
|
||||
result = getTypeForPRValue(expr.getType())
|
||||
) or
|
||||
or
|
||||
resultType instanceof PointerType and result = getIntType()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
final override predicate hasInstruction(
|
||||
Opcode opcode, InstructionTag tag, CppType resultType
|
||||
) {
|
||||
final override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = CrementLoadTag() and
|
||||
opcode instanceof Opcode::Load and
|
||||
resultType = getTypeForPRValue(expr.getType())
|
||||
@@ -615,9 +611,7 @@ class TranslatedTransparentConversion extends TranslatedTransparentExpr {
|
||||
)
|
||||
}
|
||||
|
||||
override TranslatedExpr getOperand() {
|
||||
result = getTranslatedExpr(expr.getExpr())
|
||||
}
|
||||
override TranslatedExpr getOperand() { result = getTranslatedExpr(expr.getExpr()) }
|
||||
}
|
||||
|
||||
class TranslatedThisExpr extends TranslatedNonConstantExpr {
|
||||
@@ -1242,7 +1236,7 @@ class TranslatedAssignExpr extends TranslatedAssignment {
|
||||
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
|
||||
tag = AssignmentStoreTag() and
|
||||
opcode instanceof Opcode::Store and
|
||||
resultType = getTypeForPRValue(expr.getType()) // Always a prvalue
|
||||
resultType = getTypeForPRValue(expr.getType()) // Always a prvalue
|
||||
}
|
||||
|
||||
override Instruction getInstructionOperand(InstructionTag tag, OperandTag operandTag) {
|
||||
@@ -1326,8 +1320,9 @@ class TranslatedAssignOperation extends TranslatedAssignment {
|
||||
}
|
||||
|
||||
private predicate leftOperandNeedsConversion() {
|
||||
getConvertedLeftOperandType().getUnspecifiedType() !=
|
||||
getLeftOperand().getExpr().getUnspecifiedType()
|
||||
getConvertedLeftOperandType().getUnspecifiedType() != getLeftOperand()
|
||||
.getExpr()
|
||||
.getUnspecifiedType()
|
||||
}
|
||||
|
||||
private Opcode getOpcode() {
|
||||
@@ -1367,7 +1362,7 @@ class TranslatedAssignOperation extends TranslatedAssignment {
|
||||
or
|
||||
tag = AssignmentStoreTag() and
|
||||
opcode instanceof Opcode::Store and
|
||||
resultType = getTypeForPRValue(expr.getType()) // Always a prvalue
|
||||
resultType = getTypeForPRValue(expr.getType()) // Always a prvalue
|
||||
or
|
||||
leftOperandNeedsConversion() and
|
||||
opcode instanceof Opcode::Convert and
|
||||
@@ -1577,9 +1572,7 @@ class TranslatedAllocatorCall extends TTranslatedAllocatorCall, TranslatedDirect
|
||||
tag = CallTargetTag() and result = expr.getAllocator()
|
||||
}
|
||||
|
||||
final override Type getCallResultType() {
|
||||
result = expr.getAllocator().getType()
|
||||
}
|
||||
final override Type getCallResultType() { result = expr.getAllocator().getType() }
|
||||
|
||||
final override TranslatedExpr getQualifier() { none() }
|
||||
|
||||
|
||||
@@ -234,9 +234,7 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
|
||||
/**
|
||||
* Holds if the function has a non-`void` return type.
|
||||
*/
|
||||
final predicate hasReturnValue() {
|
||||
not func.getUnspecifiedType() instanceof VoidType
|
||||
}
|
||||
final predicate hasReturnValue() { not func.getUnspecifiedType() instanceof VoidType }
|
||||
|
||||
/**
|
||||
* Gets the single `UnmodeledDefinition` instruction for this function.
|
||||
|
||||
@@ -717,10 +717,9 @@ class TranslatedElementValueInitialization extends TranslatedElementInitializati
|
||||
}
|
||||
|
||||
private CppType getDefaultValueType() {
|
||||
if elementCount = 1 then
|
||||
result = getTypeForPRValue(getElementType())
|
||||
else
|
||||
result = getUnknownOpaqueType(elementCount * getElementType().getSize())
|
||||
if elementCount = 1
|
||||
then result = getTypeForPRValue(getElementType())
|
||||
else result = getUnknownOpaqueType(elementCount * getElementType().getSize())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,9 +165,7 @@ class TranslatedReturnValueStmt extends TranslatedReturnStmt, InitializationCont
|
||||
result = getInstruction(InitializerVariableAddressTag())
|
||||
}
|
||||
|
||||
override Type getTargetType() {
|
||||
result = getEnclosingFunction().getReturnType()
|
||||
}
|
||||
override Type getTargetType() { result = getEnclosingFunction().getReturnType() }
|
||||
|
||||
TranslatedInitialization getInitialization() {
|
||||
result = getTranslatedInitialization(stmt.getExpr().getFullyConverted())
|
||||
|
||||
@@ -3,9 +3,7 @@ private import semmle.code.cpp.Print
|
||||
private import semmle.code.cpp.ir.implementation.IRType
|
||||
private import semmle.code.cpp.ir.implementation.raw.internal.IRConstruction as IRConstruction
|
||||
|
||||
private int getPointerSize() {
|
||||
result = max(any(NullPointerType t).getSize())
|
||||
}
|
||||
private int getPointerSize() { result = max(any(NullPointerType t).getSize()) }
|
||||
|
||||
/**
|
||||
* Works around an extractor bug where a function reference gets a size of one byte.
|
||||
@@ -45,19 +43,16 @@ private int getTypeSize(Type type) {
|
||||
/**
|
||||
* Holds if an `IRErrorType` should exist.
|
||||
*/
|
||||
predicate hasErrorType() {
|
||||
exists(ErroneousType t)
|
||||
}
|
||||
predicate hasErrorType() { exists(ErroneousType t) }
|
||||
|
||||
/**
|
||||
* Holds if an `IRBooleanType` with the specified `byteSize` should exist.
|
||||
*/
|
||||
predicate hasBooleanType(int byteSize) {
|
||||
byteSize = getTypeSize(any(BoolType type))
|
||||
}
|
||||
predicate hasBooleanType(int byteSize) { byteSize = getTypeSize(any(BoolType type)) }
|
||||
|
||||
private predicate isSigned(IntegralOrEnumType type) {
|
||||
type.(IntegralType).isSigned() or
|
||||
type.(IntegralType).isSigned()
|
||||
or
|
||||
exists(Enum enumType |
|
||||
// If the enum has an explicit underlying type, we'll determine signedness from that. If not,
|
||||
// we'll assume unsigned. The actual rules for the implicit underlying type of an enum vary
|
||||
@@ -93,14 +88,15 @@ predicate hasUnsignedIntegerType(int byteSize) {
|
||||
/**
|
||||
* Holds if an `IRFloatingPointType` with the specified `byteSize` should exist.
|
||||
*/
|
||||
predicate hasFloatingPointType(int byteSize) {
|
||||
byteSize = any(FloatingPointType type).getSize()
|
||||
}
|
||||
predicate hasFloatingPointType(int byteSize) { byteSize = any(FloatingPointType type).getSize() }
|
||||
|
||||
private predicate isPointerIshType(Type type) {
|
||||
type instanceof PointerType or
|
||||
type instanceof ReferenceType or
|
||||
type instanceof NullPointerType or
|
||||
type instanceof PointerType
|
||||
or
|
||||
type instanceof ReferenceType
|
||||
or
|
||||
type instanceof NullPointerType
|
||||
or
|
||||
// Treat `T[]` as a pointer. The only place we should see these is as the type of a parameter. If
|
||||
// the corresponding decayed `T*` type is available, we'll use that, but if it's not available,
|
||||
// we're stuck with `T[]`. Just treat it as a pointer.
|
||||
@@ -125,14 +121,13 @@ predicate hasFunctionAddressType(int byteSize) {
|
||||
}
|
||||
|
||||
private predicate isOpaqueType(Type type) {
|
||||
exists(type.getSize()) and // Only include complete types
|
||||
(
|
||||
exists(type.getSize()) and // Only include complete types
|
||||
(
|
||||
type instanceof ArrayType or
|
||||
type instanceof Class or
|
||||
type instanceof GNUVectorType
|
||||
)
|
||||
) or
|
||||
type instanceof ArrayType or
|
||||
type instanceof Class or
|
||||
type instanceof GNUVectorType
|
||||
)
|
||||
or
|
||||
type instanceof PointerToMemberType // PTMs are missing size info
|
||||
}
|
||||
|
||||
@@ -149,37 +144,42 @@ predicate hasOpaqueType(Type tag, int byteSize) {
|
||||
* Gets the `IRType` that represents a prvalue of the specified `Type`.
|
||||
*/
|
||||
private IRType getIRTypeForPRValue(Type type) {
|
||||
exists(Type unspecifiedType |
|
||||
unspecifiedType = type.getUnspecifiedType() |
|
||||
(
|
||||
isOpaqueType(unspecifiedType) and
|
||||
exists(IROpaqueType opaqueType |
|
||||
opaqueType = result |
|
||||
opaqueType.getByteSize() = getTypeSize(type) and
|
||||
opaqueType.getTag() = unspecifiedType
|
||||
)
|
||||
) or
|
||||
unspecifiedType instanceof BoolType and result.(IRBooleanType).getByteSize() = type.getSize() or
|
||||
isSignedIntegerType(unspecifiedType) and result.(IRSignedIntegerType).getByteSize() = type.getSize() or
|
||||
isUnsignedIntegerType(unspecifiedType) and result.(IRUnsignedIntegerType).getByteSize() = type.getSize() or
|
||||
unspecifiedType instanceof FloatingPointType and result.(IRFloatingPointType).getByteSize() = type.getSize() or
|
||||
isPointerIshType(unspecifiedType) and result.(IRAddressType).getByteSize() = getTypeSize(type) or
|
||||
unspecifiedType instanceof FunctionPointerIshType and result.(IRFunctionAddressType).getByteSize() = getTypeSize(type) or
|
||||
unspecifiedType instanceof VoidType and result instanceof IRVoidType or
|
||||
unspecifiedType instanceof ErroneousType and result instanceof IRErrorType or
|
||||
exists(Type unspecifiedType | unspecifiedType = type.getUnspecifiedType() |
|
||||
isOpaqueType(unspecifiedType) and
|
||||
exists(IROpaqueType opaqueType | opaqueType = result |
|
||||
opaqueType.getByteSize() = getTypeSize(type) and
|
||||
opaqueType.getTag() = unspecifiedType
|
||||
)
|
||||
or
|
||||
unspecifiedType instanceof BoolType and result.(IRBooleanType).getByteSize() = type.getSize()
|
||||
or
|
||||
isSignedIntegerType(unspecifiedType) and
|
||||
result.(IRSignedIntegerType).getByteSize() = type.getSize()
|
||||
or
|
||||
isUnsignedIntegerType(unspecifiedType) and
|
||||
result.(IRUnsignedIntegerType).getByteSize() = type.getSize()
|
||||
or
|
||||
unspecifiedType instanceof FloatingPointType and
|
||||
result.(IRFloatingPointType).getByteSize() = type.getSize()
|
||||
or
|
||||
isPointerIshType(unspecifiedType) and result.(IRAddressType).getByteSize() = getTypeSize(type)
|
||||
or
|
||||
unspecifiedType instanceof FunctionPointerIshType and
|
||||
result.(IRFunctionAddressType).getByteSize() = getTypeSize(type)
|
||||
or
|
||||
unspecifiedType instanceof VoidType and result instanceof IRVoidType
|
||||
or
|
||||
unspecifiedType instanceof ErroneousType and result instanceof IRErrorType
|
||||
or
|
||||
unspecifiedType instanceof UnknownType and result instanceof IRUnknownType
|
||||
)
|
||||
}
|
||||
|
||||
private newtype TCppType =
|
||||
TPRValueType(Type type) {
|
||||
exists(getIRTypeForPRValue(type))
|
||||
} or
|
||||
TPRValueType(Type type) { exists(getIRTypeForPRValue(type)) } or
|
||||
TFunctionGLValueType() or
|
||||
TGLValueAddressType(Type type) or
|
||||
TUnknownOpaqueType(int byteSize) {
|
||||
IRConstruction::needsUnknownOpaqueType(byteSize)
|
||||
} or
|
||||
TUnknownOpaqueType(int byteSize) { IRConstruction::needsUnknownOpaqueType(byteSize) } or
|
||||
TUnknownType()
|
||||
|
||||
/**
|
||||
@@ -231,7 +231,9 @@ private class CppWrappedType extends CppType {
|
||||
}
|
||||
|
||||
abstract string toString();
|
||||
|
||||
abstract override IRType getIRType();
|
||||
|
||||
abstract override predicate hasType(Type type, boolean isGLValue);
|
||||
}
|
||||
|
||||
@@ -239,13 +241,13 @@ private class CppWrappedType extends CppType {
|
||||
* A `CppType` that represents a prvalue of an existing `Type`.
|
||||
*/
|
||||
private class CppPRValueType extends CppWrappedType, TPRValueType {
|
||||
override final string toString() { result = ctype.toString() }
|
||||
final override string toString() { result = ctype.toString() }
|
||||
|
||||
override final string getDumpString() { result = ctype.getUnspecifiedType().toString() }
|
||||
final override string getDumpString() { result = ctype.getUnspecifiedType().toString() }
|
||||
|
||||
override final IRType getIRType() { result = getIRTypeForPRValue(ctype) }
|
||||
final override IRType getIRType() { result = getIRTypeForPRValue(ctype) }
|
||||
|
||||
override final predicate hasType(Type type, boolean isGLValue) {
|
||||
final override predicate hasType(Type type, boolean isGLValue) {
|
||||
type = ctype and
|
||||
isGLValue = false
|
||||
}
|
||||
@@ -259,15 +261,11 @@ private class CppPRValueType extends CppWrappedType, TPRValueType {
|
||||
private class CppUnknownOpaqueType extends CppType, TUnknownOpaqueType {
|
||||
int byteSize;
|
||||
|
||||
CppUnknownOpaqueType() {
|
||||
this = TUnknownOpaqueType(byteSize)
|
||||
}
|
||||
CppUnknownOpaqueType() { this = TUnknownOpaqueType(byteSize) }
|
||||
|
||||
override final string toString() {
|
||||
result = "unknown[" + byteSize.toString() + "]"
|
||||
}
|
||||
final override string toString() { result = "unknown[" + byteSize.toString() + "]" }
|
||||
|
||||
override final IROpaqueType getIRType() {
|
||||
final override IROpaqueType getIRType() {
|
||||
result.getByteSize() = byteSize and result.getTag() instanceof UnknownType
|
||||
}
|
||||
|
||||
@@ -280,19 +278,15 @@ private class CppUnknownOpaqueType extends CppType, TUnknownOpaqueType {
|
||||
* A `CppType` that represents a glvalue of an existing `Type`.
|
||||
*/
|
||||
private class CppGLValueAddressType extends CppWrappedType, TGLValueAddressType {
|
||||
override final string toString() {
|
||||
result = "glval<" + ctype.toString() + ">"
|
||||
}
|
||||
final override string toString() { result = "glval<" + ctype.toString() + ">" }
|
||||
|
||||
override final string getDumpString() {
|
||||
final override string getDumpString() {
|
||||
result = "glval<" + ctype.getUnspecifiedType().toString() + ">"
|
||||
}
|
||||
|
||||
override final IRAddressType getIRType() {
|
||||
result.getByteSize() = getPointerSize()
|
||||
}
|
||||
final override IRAddressType getIRType() { result.getByteSize() = getPointerSize() }
|
||||
|
||||
override final predicate hasType(Type type, boolean isGLValue) {
|
||||
final override predicate hasType(Type type, boolean isGLValue) {
|
||||
type = ctype and
|
||||
isGLValue = true
|
||||
}
|
||||
@@ -302,15 +296,11 @@ private class CppGLValueAddressType extends CppWrappedType, TGLValueAddressType
|
||||
* A `CppType` that represents a function lvalue.
|
||||
*/
|
||||
private class CppFunctionGLValueType extends CppType, TFunctionGLValueType {
|
||||
override final string toString() {
|
||||
result = "glval<unknown>"
|
||||
}
|
||||
final override string toString() { result = "glval<unknown>" }
|
||||
|
||||
override final IRFunctionAddressType getIRType() {
|
||||
result.getByteSize() = getPointerSize()
|
||||
}
|
||||
final override IRFunctionAddressType getIRType() { result.getByteSize() = getPointerSize() }
|
||||
|
||||
override final predicate hasType(Type type, boolean isGLValue) {
|
||||
final override predicate hasType(Type type, boolean isGLValue) {
|
||||
type instanceof UnknownType and isGLValue = true
|
||||
}
|
||||
}
|
||||
@@ -319,15 +309,11 @@ private class CppFunctionGLValueType extends CppType, TFunctionGLValueType {
|
||||
* A `CppType` that represents an unknown type.
|
||||
*/
|
||||
private class CppUnknownType extends CppType, TUnknownType {
|
||||
override final string toString() {
|
||||
result = any(UnknownType type).toString()
|
||||
}
|
||||
final override string toString() { result = any(UnknownType type).toString() }
|
||||
|
||||
override final IRUnknownType getIRType() {
|
||||
any()
|
||||
}
|
||||
final override IRUnknownType getIRType() { any() }
|
||||
|
||||
override final predicate hasType(Type type, boolean isGLValue) {
|
||||
final override predicate hasType(Type type, boolean isGLValue) {
|
||||
type instanceof UnknownType and isGLValue = false
|
||||
}
|
||||
}
|
||||
@@ -335,18 +321,12 @@ private class CppUnknownType extends CppType, TUnknownType {
|
||||
/**
|
||||
* Gets the single instance of `CppUnknownType`.
|
||||
*/
|
||||
CppUnknownType getUnknownType() {
|
||||
any()
|
||||
}
|
||||
CppUnknownType getUnknownType() { any() }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that represents a prvalue of type `void`.
|
||||
*/
|
||||
CppPRValueType getVoidType() {
|
||||
exists(VoidType voidType |
|
||||
result.hasType(voidType, false)
|
||||
)
|
||||
}
|
||||
CppPRValueType getVoidType() { exists(VoidType voidType | result.hasType(voidType, false)) }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that represents a prvalue of type `type`.
|
||||
@@ -362,16 +342,15 @@ CppType getTypeForPRValue(Type type) {
|
||||
* Otherwise, gets `CppUnknownType`.
|
||||
*/
|
||||
CppType getTypeForPRValueOrUnknown(Type type) {
|
||||
result = getTypeForPRValue(type) or
|
||||
result = getTypeForPRValue(type)
|
||||
or
|
||||
not exists(getTypeForPRValue(type)) and result = getUnknownType()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that represents a glvalue of type `type`.
|
||||
*/
|
||||
CppType getTypeForGLValue(Type type) {
|
||||
result.hasType(type, true)
|
||||
}
|
||||
CppType getTypeForGLValue(Type type) { result.hasType(type, true) }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that represents a prvalue of type `int`.
|
||||
@@ -386,34 +365,24 @@ CppPRValueType getIntType() {
|
||||
/**
|
||||
* Gets the `CppType` that represents a prvalue of type `bool`.
|
||||
*/
|
||||
CppPRValueType getBoolType() {
|
||||
exists(BoolType type |
|
||||
result.hasType(type, false)
|
||||
)
|
||||
}
|
||||
CppPRValueType getBoolType() { exists(BoolType type | result.hasType(type, false)) }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that represents a glvalue of function type.
|
||||
*/
|
||||
CppFunctionGLValueType getFunctionGLValueType() {
|
||||
any()
|
||||
}
|
||||
CppFunctionGLValueType getFunctionGLValueType() { any() }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that represents a opaque of unknown type with size `byteSize`.
|
||||
*/
|
||||
CppUnknownOpaqueType getUnknownOpaqueType(int byteSize) {
|
||||
result.getByteSize() = byteSize
|
||||
}
|
||||
CppUnknownOpaqueType getUnknownOpaqueType(int byteSize) { result.getByteSize() = byteSize }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that is the canonical type for an `IRBooleanType` with the specified
|
||||
* `byteSize`.
|
||||
*/
|
||||
CppWrappedType getCanonicalBooleanType(int byteSize) {
|
||||
exists(BoolType type |
|
||||
result = TPRValueType(type) and byteSize = type.getSize()
|
||||
)
|
||||
exists(BoolType type | result = TPRValueType(type) and byteSize = type.getSize())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,9 +395,10 @@ private int getSignPriority(IntegralType type) {
|
||||
// `char` is unsigned.
|
||||
if type.isExplicitlyUnsigned()
|
||||
then result = 2
|
||||
else if type.isExplicitlySigned()
|
||||
then result = 0
|
||||
else result = 1
|
||||
else
|
||||
if type.isExplicitlySigned()
|
||||
then result = 0
|
||||
else result = 1
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,12 +406,11 @@ private int getSignPriority(IntegralType type) {
|
||||
*/
|
||||
private int getKindPriority(IntegralType type) {
|
||||
/*
|
||||
`CharType` sorts lower so that we prefer the plain integer types when they have the same size as
|
||||
a `CharType`.
|
||||
*/
|
||||
if type instanceof CharType
|
||||
then result = 0
|
||||
else result = 1
|
||||
* `CharType` sorts lower so that we prefer the plain integer types when they have the same size as
|
||||
* a `CharType`.
|
||||
*/
|
||||
|
||||
if type instanceof CharType then result = 0 else result = 1
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -449,8 +418,11 @@ private int getKindPriority(IntegralType type) {
|
||||
* `byteSize`.
|
||||
*/
|
||||
CppPRValueType getCanonicalSignedIntegerType(int byteSize) {
|
||||
result = TPRValueType(max(IntegralType type | type.isSigned() and type.getSize() = byteSize |
|
||||
type order by getKindPriority(type), getSignPriority(type), type.toString() desc))
|
||||
result = TPRValueType(max(IntegralType type |
|
||||
type.isSigned() and type.getSize() = byteSize
|
||||
|
|
||||
type order by getKindPriority(type), getSignPriority(type), type.toString() desc
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,8 +430,11 @@ CppPRValueType getCanonicalSignedIntegerType(int byteSize) {
|
||||
* `byteSize`.
|
||||
*/
|
||||
CppPRValueType getCanonicalUnsignedIntegerType(int byteSize) {
|
||||
result = TPRValueType(max(IntegralType type | type.isUnsigned() and type.getSize() = byteSize |
|
||||
type order by getKindPriority(type), getSignPriority(type), type.toString() desc))
|
||||
result = TPRValueType(max(IntegralType type |
|
||||
type.isUnsigned() and type.getSize() = byteSize
|
||||
|
|
||||
type order by getKindPriority(type), getSignPriority(type), type.toString() desc
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,8 +442,11 @@ CppPRValueType getCanonicalUnsignedIntegerType(int byteSize) {
|
||||
* `byteSize`.
|
||||
*/
|
||||
CppPRValueType getCanonicalFloatingPointType(int byteSize) {
|
||||
result = TPRValueType(max(FloatingPointType type | type.getSize() = byteSize |
|
||||
type order by type.toString() desc))
|
||||
result = TPRValueType(max(FloatingPointType type |
|
||||
type.getSize() = byteSize
|
||||
|
|
||||
type order by type.toString() desc
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,23 +472,17 @@ CppFunctionGLValueType getCanonicalFunctionAddressType(int byteSize) {
|
||||
/**
|
||||
* Gets the `CppType` that is the canonical type for `IRErrorType`.
|
||||
*/
|
||||
CppPRValueType getCanonicalErrorType() {
|
||||
result = TPRValueType(any(ErroneousType type))
|
||||
}
|
||||
CppPRValueType getCanonicalErrorType() { result = TPRValueType(any(ErroneousType type)) }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that is the canonical type for `IRUnknownType`.
|
||||
*/
|
||||
CppUnknownType getCanonicalUnknownType() {
|
||||
any()
|
||||
}
|
||||
CppUnknownType getCanonicalUnknownType() { any() }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that is the canonical type for `IRVoidType`.
|
||||
*/
|
||||
CppPRValueType getCanonicalVoidType() {
|
||||
result = TPRValueType(any(VoidType type))
|
||||
}
|
||||
CppPRValueType getCanonicalVoidType() { result = TPRValueType(any(VoidType type)) }
|
||||
|
||||
/**
|
||||
* Gets the `CppType` that is the canonical type for an `IROpaqueType` with the specified `tag` and
|
||||
@@ -538,7 +510,7 @@ module LanguageTypeSanity {
|
||||
not exists(getTypeForPRValue(type)) and
|
||||
exists(type.getSize()) and
|
||||
// `ProxyClass`es have a size, but only appear in uninstantiated templates
|
||||
not type instanceof ProxyClass and
|
||||
not type instanceof ProxyClass and
|
||||
message = "Type does not have an associated `CppType`."
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user