mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
More PR fixes
This commit is contained in:
@@ -11,6 +11,9 @@ private import TranslatedStmt
|
||||
private import IRConstruction
|
||||
private import semmle.code.csharp.ir.Util
|
||||
private import semmle.code.csharp.ir.internal.IRCSharpLanguage as Language
|
||||
private import desugar.Foreach
|
||||
private import desugar.Delegate
|
||||
private import desugar.Lock
|
||||
|
||||
/**
|
||||
* Gets the built-in `int` type.
|
||||
@@ -23,14 +26,14 @@ ArrayType getArrayOfDim(int dim, Type type) {
|
||||
}
|
||||
|
||||
private predicate canCreateCompilerGeneratedElement(Element generatedBy, int nth) {
|
||||
(
|
||||
generatedBy instanceof ForeachStmt or
|
||||
generatedBy instanceof LockStmt or
|
||||
generatedBy instanceof DelegateCreation or
|
||||
generatedBy instanceof DelegateCall
|
||||
) and
|
||||
// For now we allow a max of 15 compiler generated elements
|
||||
nth in [0 .. 14]
|
||||
generatedBy instanceof ForeachStmt and nth in [0 .. ForeachElements::noGeneratedElements()]
|
||||
or
|
||||
generatedBy instanceof LockStmt and nth in [0 .. LockElements::noGeneratedElements()]
|
||||
or
|
||||
generatedBy instanceof DelegateCreation and
|
||||
nth in [0 .. DelegateElements::noGeneratedElements(generatedBy)]
|
||||
or
|
||||
generatedBy instanceof DelegateCall and nth in [0 .. DelegateElements::noGeneratedElements(generatedBy)]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,7 +165,7 @@ class TranslatedFunction extends TranslatedElement, TTranslatedFunction {
|
||||
isLValue = false and
|
||||
(
|
||||
// Only generate the `Unwind` instruction if there is any exception
|
||||
// handling present in the function.
|
||||
// handling present in the function (compiler generated or not).
|
||||
exists(TryStmt try | try.getEnclosingCallable() = callable) or
|
||||
exists(ThrowStmt throw | throw.getEnclosingCallable() = callable)
|
||||
)
|
||||
|
||||
@@ -113,7 +113,7 @@ abstract class LocalVariableDeclarationBase extends TranslatedElement {
|
||||
abstract TranslatedElement getInitialization();
|
||||
|
||||
/**
|
||||
* Predicate that holds if a declaration is not explicitly initialized,
|
||||
* Holds if a declaration is not explicitly initialized,
|
||||
* but will be implicitly initialized by an element.
|
||||
*/
|
||||
abstract predicate isInitializedByElement();
|
||||
|
||||
@@ -31,6 +31,12 @@ module DelegateElements {
|
||||
}
|
||||
|
||||
TranslatedDelegateInvokeCall getInvoke(DelegateCall generatedBy) { result.getAST() = generatedBy }
|
||||
|
||||
int noGeneratedElements(Element generatedBy) {
|
||||
generatedBy instanceof DelegateCreation and result = 1
|
||||
or
|
||||
generatedBy instanceof DelegateCall and result = 1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,6 +58,8 @@ module ForeachElements {
|
||||
TranslatedForeachTry getTry(ForeachStmt generatedBy) { result.getAST() = generatedBy }
|
||||
|
||||
TranslatedForeachEnumerator getEnumDecl(ForeachStmt generatedBy) { result.getAST() = generatedBy }
|
||||
|
||||
int noGeneratedElements() { result = 12 }
|
||||
}
|
||||
|
||||
private class TranslatedForeachTry extends TranslatedCompilerGeneratedTry,
|
||||
@@ -206,17 +208,14 @@ private class TranslatedForeachGetEnumerator extends TranslatedCompilerGenerated
|
||||
|
||||
override Callable getInstructionFunction(InstructionTag tag) {
|
||||
tag = CallTargetTag() and
|
||||
exists(Callable internal |
|
||||
internal.getName() = "GetEnumerator" and
|
||||
// TODO: For now ignore the possibility that the
|
||||
// foreach variable can have a generic type.
|
||||
// The type of the callable will need to be fabricated,
|
||||
// since we might not find the correct callable in the DB.
|
||||
// Probably will have change the way the immediate
|
||||
// operand of `FunctionAddress` is calculated.
|
||||
internal.getReturnType().getName() = "IEnumerator" and
|
||||
result = internal
|
||||
)
|
||||
result.getName() = "GetEnumerator" and
|
||||
// TODO: For now ignore the possibility that the
|
||||
// foreach variable can have a generic type.
|
||||
// The type of the callable will need to be fabricated,
|
||||
// since we might not find the correct callable in the DB.
|
||||
// Probably will have change the way the immediate
|
||||
// operand of `FunctionAddress` is calculated.
|
||||
result.getReturnType().getName() = "IEnumerator"
|
||||
}
|
||||
|
||||
override TranslatedExpr getArgument(int id) { none() }
|
||||
|
||||
@@ -48,6 +48,8 @@ module LockElements {
|
||||
TranslatedLockWasTakenDecl getLockWasTakenDecl(LockStmt generatedBy) {
|
||||
result.getAST() = generatedBy
|
||||
}
|
||||
|
||||
int noGeneratedElements() { result = 13 }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* which represents the element that generated the compiler generated element.
|
||||
*/
|
||||
|
||||
import csharp
|
||||
private import semmle.code.csharp.ir.implementation.raw.internal.TranslatedElement
|
||||
private import semmle.code.csharp.ir.internal.IRCSharpLanguage as Language
|
||||
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
private import csharp
|
||||
|
||||
/**
|
||||
* Given a type, get the type that would result by applying "pointer decay".
|
||||
* A function type becomes a pointer to that function type, and an array type
|
||||
* becomes a pointer to the element type of the array. If the specified type
|
||||
* is not subject to pointer decay, this predicate does not hold.
|
||||
*/
|
||||
// TODO: Only pointer to array decay in C#?
|
||||
private Type getDecayedType(Type type) {
|
||||
result.(PointerType).getReferentType() = type.(ArrayType).getElementType()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual type of the specified variable, as opposed to the declared type.
|
||||
* This returns the type of the variable after any pointer decay is applied, and
|
||||
@@ -21,9 +10,7 @@ Type getVariableType(Variable v) {
|
||||
declaredType = v.getType() and
|
||||
if v instanceof Parameter
|
||||
then
|
||||
result = getDecayedType(declaredType)
|
||||
or
|
||||
not exists(getDecayedType(declaredType)) and result = declaredType
|
||||
result = declaredType
|
||||
else
|
||||
if declaredType instanceof ArrayType
|
||||
then
|
||||
|
||||
@@ -4,10 +4,10 @@ class LockTest
|
||||
{
|
||||
static void A()
|
||||
{
|
||||
object _object = new object();
|
||||
lock (_object)
|
||||
object @object = new object();
|
||||
lock (@object)
|
||||
{
|
||||
Console.WriteLine(_object.ToString());
|
||||
Console.WriteLine(@object.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,14 +609,14 @@ lock.cs:
|
||||
# 5| v0_0(Void) = EnterFunction :
|
||||
# 5| mu0_1(null) = AliasedDefinition :
|
||||
# 5| mu0_2(null) = UnmodeledDefinition :
|
||||
# 7| r0_3(glval<Object>) = VariableAddress[_object] :
|
||||
# 7| r0_3(glval<Object>) = VariableAddress[object] :
|
||||
# 7| r0_4(Object) = NewObj :
|
||||
# 7| r0_5(glval<null>) = FunctionAddress[Object] :
|
||||
# 7| v0_6(Void) = Call : func:r0_5, this:r0_4
|
||||
# 7| mu0_7(null) = ^CallSideEffect : ~mu0_2
|
||||
# 7| mu0_8(Object) = Store : &:r0_3, r0_4
|
||||
# 8| r0_9(glval<Object>) = VariableAddress[#temp8:9] :
|
||||
# 8| r0_10(glval<Object>) = VariableAddress[_object] :
|
||||
# 8| r0_10(glval<Object>) = VariableAddress[object] :
|
||||
# 8| r0_11(Object) = Load : &:r0_10, ~mu0_2
|
||||
# 8| mu0_12(Object) = Store : &:r0_9, r0_11
|
||||
# 8| r0_13(glval<Boolean>) = VariableAddress[#temp8:9] :
|
||||
@@ -629,7 +629,7 @@ lock.cs:
|
||||
# 8| v0_20(Void) = Call : func:r0_16, 0:r0_18, 1:r0_19
|
||||
# 8| mu0_21(null) = ^CallSideEffect : ~mu0_2
|
||||
# 10| r0_22(glval<null>) = FunctionAddress[WriteLine] :
|
||||
# 10| r0_23(glval<Object>) = VariableAddress[_object] :
|
||||
# 10| r0_23(glval<Object>) = VariableAddress[object] :
|
||||
# 10| r0_24(Object) = Load : &:r0_23, ~mu0_2
|
||||
# 10| r0_25(glval<null>) = FunctionAddress[ToString] :
|
||||
# 10| r0_26(String) = Call : func:r0_25, this:r0_24
|
||||
|
||||
Reference in New Issue
Block a user