Skip to content

Commit

Permalink
Merge branch 'main' into redsun82/rust-cli-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Tranquilli committed Sep 16, 2024
2 parents 23dd572 + 39ce3fb commit cb53911
Show file tree
Hide file tree
Showing 562 changed files with 17,998 additions and 3,027 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ permissions:
contents: read

jobs:
rust-check:
rust-code:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -43,6 +43,13 @@ jobs:
run: |
cargo clippy --fix
git diff --exit-code
rust-codegen:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install CodeQL
uses: ./.github/actions/fetch-codeql
- name: Code generation
shell: bash
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,10 @@ newtype TTranslatedElement =
} or
// A statement
TTranslatedStmt(Stmt stmt) { translateStmt(stmt) } or
// The `__except` block of a `__try __except` statement
TTranslatedMicrosoftTryExceptHandler(MicrosoftTryExceptStmt stmt) or
// The `__finally` block of a `__try __finally` statement
TTranslatedMicrosoftTryFinallyHandler(MicrosoftTryFinallyStmt stmt) or
// A function
TTranslatedFunction(Function func) { translateFunction(func) } or
// A constructor init list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,62 @@ class TranslatedMicrosoftTryExceptHandler extends TranslatedElement,
}
}

TranslatedMicrosoftTryFinallyHandler getTranslatedMicrosoftTryFinallyHandler(
MicrosoftTryFinallyStmt tryFinally
) {
result.getAst() = tryFinally.getFinally()
}

class TranslatedMicrosoftTryFinallyHandler extends TranslatedElement,
TTranslatedMicrosoftTryFinallyHandler
{
MicrosoftTryFinallyStmt tryFinally;

TranslatedMicrosoftTryFinallyHandler() {
this = TTranslatedMicrosoftTryFinallyHandler(tryFinally)
}

final override string toString() { result = tryFinally.toString() }

final override Locatable getAst() { result = tryFinally.getFinally() }

override Instruction getFirstInstruction(EdgeKind kind) {
result = this.getTranslatedFinally().getFirstInstruction(kind)
}

override Instruction getALastInstructionInternal() {
result = this.getTranslatedFinally().getALastInstruction()
}

override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
child = this.getTranslatedFinally() and
result = this.getParent().getChildSuccessor(this, kind)
}

override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) { none() }

override TranslatedElement getChild(int id) {
id = 0 and
result = this.getTranslatedFinally()
}

override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
none()
}

final override Function getFunction() { result = tryFinally.getEnclosingFunction() }

private TranslatedStmt getTranslatedFinally() {
result = getTranslatedStmt(tryFinally.getFinally())
}

override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
// A throw from within a `__finally` block flows to the handler for the parent of
// the `__try`.
result = this.getParent().getParent().getExceptionSuccessorInstruction(kind)
}
}

abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt {
Stmt stmt;

Expand Down Expand Up @@ -611,7 +667,9 @@ class TryOrMicrosoftTryStmt extends Stmt {
}

/** Gets the `finally` statement (usually a BlockStmt), if any. */
Stmt getFinally() { result = this.(MicrosoftTryFinallyStmt).getFinally() }
TranslatedElement getTranslatedFinally() {
result = getTranslatedMicrosoftTryFinallyHandler(this)
}
}

/**
Expand Down Expand Up @@ -681,11 +739,14 @@ class TranslatedTryStmt extends TranslatedStmt {

final override Instruction getExceptionSuccessorInstruction(EdgeKind kind) {
result = this.getHandler(0).getFirstInstruction(kind)
or
not exists(this.getHandler(_)) and
result = this.getFinally().getFirstInstruction(kind)
}

private TranslatedElement getHandler(int index) { result = stmt.getTranslatedHandler(index) }

private TranslatedStmt getFinally() { result = getTranslatedStmt(stmt.getFinally()) }
private TranslatedElement getFinally() { result = stmt.getTranslatedFinally() }

private TranslatedStmt getBody() { result = getTranslatedStmt(stmt.getStmt()) }
}
Expand Down
24 changes: 24 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/aliased_ir.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,16 @@ ir.c:
# 62| v62_3(void) = Call[ExRaiseAccessViolation] : func:r62_1, 0:r62_2
# 62| m62_4(unknown) = ^CallSideEffect : ~m57_4
# 62| m62_5(unknown) = Chi : total:m57_4, partial:m62_4
#-----| Exception -> Block 1

# 66| Block 1
# 66| r66_1(int) = Constant[1] :
# 66| r66_2(glval<int>) = VariableAddress[x] :
# 66| m66_3(int) = Store[x] : &:r66_2, r66_1
# 68| v68_1(void) = NoOp :
# 57| v57_5(void) = ReturnVoid :
# 57| v57_6(void) = AliasedUse : ~m62_5
# 57| v57_7(void) = ExitFunction :

# 70| void throw_in_try_with_throw_in_finally()
# 70| Block 0
Expand All @@ -3253,6 +3263,20 @@ ir.c:
# 73| v73_3(void) = Call[ExRaiseAccessViolation] : func:r73_1, 0:r73_2
# 73| m73_4(unknown) = ^CallSideEffect : ~m70_4
# 73| m73_5(unknown) = Chi : total:m70_4, partial:m73_4
#-----| Exception -> Block 2

# 70| Block 1
# 70| v70_5(void) = Unwind :
# 70| v70_6(void) = AliasedUse : ~m76_5
# 70| v70_7(void) = ExitFunction :

# 76| Block 2
# 76| r76_1(glval<unknown>) = FunctionAddress[ExRaiseAccessViolation] :
# 76| r76_2(int) = Constant[0] :
# 76| v76_3(void) = Call[ExRaiseAccessViolation] : func:r76_1, 0:r76_2
# 76| m76_4(unknown) = ^CallSideEffect : ~m73_5
# 76| m76_5(unknown) = Chi : total:m73_5, partial:m76_4
#-----| Exception -> Block 1

# 80| void raise_access_violation()
# 80| Block 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | Chi: call to ExRaiseAccessViolation | Instruction 'Chi: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
Expand Down
3 changes: 0 additions & 3 deletions cpp/ql/test/library-tests/ir/ir/raw_consistency.expected
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
| ir.c:76:5:76:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
Expand Down
3 changes: 3 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/raw_ir.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,7 @@ ir.c:
# 62| r62_2(int) = Constant[0] :
# 62| v62_3(void) = Call[ExRaiseAccessViolation] : func:r62_1, 0:r62_2
# 62| mu62_4(unknown) = ^CallSideEffect : ~m?
#-----| Exception -> Block 3

# 57| Block 1
# 57| v57_4(void) = AliasedUse : ~m?
Expand All @@ -3048,6 +3049,7 @@ ir.c:
# 73| r73_2(int) = Constant[0] :
# 73| v73_3(void) = Call[ExRaiseAccessViolation] : func:r73_1, 0:r73_2
# 73| mu73_4(unknown) = ^CallSideEffect : ~m?
#-----| Exception -> Block 3

# 70| Block 1
# 70| v70_4(void) = AliasedUse : ~m?
Expand All @@ -3062,6 +3064,7 @@ ir.c:
# 76| r76_2(int) = Constant[0] :
# 76| v76_3(void) = Call[ExRaiseAccessViolation] : func:r76_1, 0:r76_2
# 76| mu76_4(unknown) = ^CallSideEffect : ~m?
#-----| Exception -> Block 2

# 78| Block 4
# 78| v78_1(void) = NoOp :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ir.c:62:5:62:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:57:6:57:30 | void throw_in_try_with_finally() | void throw_in_try_with_finally() |
| ir.c:73:5:73:26 | CallSideEffect: call to ExRaiseAccessViolation | Instruction 'CallSideEffect: call to ExRaiseAccessViolation' has no successors in function '$@'. | ir.c:70:6:70:39 | void throw_in_try_with_throw_in_finally() | void throw_in_try_with_throw_in_finally() |
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ms_try_mix.cpp:38:5:38:5 | Chi: c106 | Instruction 'Chi: c106' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
ambiguousSuccessors
unexplainedLoop
Expand Down
2 changes: 0 additions & 2 deletions cpp/ql/test/library-tests/syntax-zoo/raw_consistency.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ms_try_mix.cpp:38:5:38:5 | IndirectMayWriteSideEffect: c106 | Instruction 'IndirectMayWriteSideEffect: c106' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
| stmt_expr.cpp:29:11:32:11 | CopyValue: (statement expression) | Instruction 'CopyValue: (statement expression)' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
| stmt_in_type.cpp:5:53:5:53 | Constant: 1 | Instruction 'Constant: 1' has no successors in function '$@'. | stmt_in_type.cpp:2:6:2:12 | void cpp_fun() | void cpp_fun() |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ missingOperandType
duplicateChiOperand
sideEffectWithoutPrimary
instructionWithoutSuccessor
| ms_try_mix.cpp:38:5:38:5 | IndirectMayWriteSideEffect: c106 | Instruction 'IndirectMayWriteSideEffect: c106' has no successors in function '$@'. | ms_try_mix.cpp:29:6:29:19 | void ms_finally_mix(int) | void ms_finally_mix(int) |
| ms_try_mix.cpp:53:5:53:11 | ThrowValue: throw ... | Instruction 'ThrowValue: throw ...' has no successors in function '$@'. | ms_try_mix.cpp:49:6:49:28 | void ms_empty_finally_at_end() | void ms_empty_finally_at_end() |
| stmt_expr.cpp:27:5:27:15 | Store: ... = ... | Instruction 'Store: ... = ...' has no successors in function '$@'. | stmt_expr.cpp:21:13:21:13 | void stmtexpr::g(int) | void stmtexpr::g(int) |
ambiguousSuccessors
unexplainedLoop
Expand Down
2 changes: 1 addition & 1 deletion csharp/ql/integration-tests/all-platforms/cshtml/Files.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import csharp

from File f
where f.fromSource() or f.getExtension() = "cshtml"
where f.fromSource()
select f
2 changes: 1 addition & 1 deletion csharp/ql/lib/semmle/code/csharp/File.qll
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class File extends Container, Impl::File {

/** Holds if this file contains source code. */
final predicate fromSource() {
this.getExtension() = ["cs", "cshtml"] and
this.getExtension() = ["cs", "cshtml", "razor"] and
not this.isStub()
}

Expand Down
3 changes: 2 additions & 1 deletion go/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,8 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s};namedtype", entitylbl))
case *types.TypeParam:
parentlbl := getTypeParamParentLabel(tw, tp)
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%v},%s;typeparamtype", parentlbl, tp.Obj().Name()))
idx := tp.Index()
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%v},%d,%s;typeparamtype", parentlbl, idx, tp.Obj().Name()))
case *types.Union:
var b strings.Builder
for i := 0; i < tp.Len(); i++ {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* When a function or type has more than one anonymous type parameters, they were mistakenly being treated as the same type parameter. This has now been fixed.
31 changes: 31 additions & 0 deletions go/ql/test/library-tests/semmle/go/Function/TypeParamType.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
numberOfTypeParameters
| genericFunctions2.go:3:6:3:33 | GenericFunctionInAnotherFile | 1 |
| genericFunctions.go:9:6:9:32 | GenericFunctionOneTypeParam | 1 |
| genericFunctions.go:15:6:15:33 | GenericFunctionTwoTypeParams | 2 |
| genericFunctions.go:81:6:81:19 | GenericStruct1 | 1 |
| genericFunctions.go:84:6:84:19 | GenericStruct2 | 2 |
| genericFunctions.go:87:30:87:31 | f1 | 1 |
| genericFunctions.go:92:31:92:32 | g1 | 1 |
| genericFunctions.go:95:35:95:36 | f2 | 2 |
| genericFunctions.go:98:36:98:37 | g2 | 2 |
| genericFunctions.go:111:6:111:12 | Element | 1 |
| genericFunctions.go:115:6:115:9 | List | 1 |
| genericFunctions.go:120:19:120:23 | MyLen | 1 |
| genericFunctions.go:124:6:124:19 | NodeConstraint | 1 |
| genericFunctions.go:128:6:128:19 | EdgeConstraint | 1 |
| genericFunctions.go:132:6:132:10 | Graph | 2 |
| genericFunctions.go:134:6:134:8 | New | 2 |
| genericFunctions.go:138:29:138:40 | ShortestPath | 2 |
| genericFunctions.go:150:6:150:36 | multipleAnonymousTypeParamsFunc | 3 |
| genericFunctions.go:152:6:152:36 | multipleAnonymousTypeParamsType | 3 |
| genericFunctions.go:154:51:154:51 | f | 3 |
#select
| cmp.Compare | 0 | T | Ordered |
| cmp.Less | 0 | T | Ordered |
| cmp.Or | 0 | T | comparable |
Expand Down Expand Up @@ -26,6 +48,15 @@
| codeql-go-tests/function.New | 0 | Node | NodeConstraint |
| codeql-go-tests/function.New | 1 | Edge | EdgeConstraint |
| codeql-go-tests/function.NodeConstraint | 0 | Edge | interface { } |
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 0 | _ | interface { } |
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 1 | _ | interface { string } |
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 2 | _ | interface { } |
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 0 | _ | interface { } |
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 1 | _ | interface { string } |
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 2 | _ | interface { } |
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 0 | _ | interface { } |
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 1 | _ | interface { string } |
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 2 | _ | interface { } |
| github.com/anotherpkg.GenericFunctionInAnotherPackage | 0 | T | interface { } |
| internal/bytealg.HashStr | 0 | T | interface { string \| []uint8 } |
| internal/bytealg.HashStrRev | 0 | T | interface { string \| []uint8 } |
Expand Down
5 changes: 5 additions & 0 deletions go/ql/test/library-tests/semmle/go/Function/TypeParamType.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import go

query predicate numberOfTypeParameters(TypeParamParentEntity parent, int n) {
exists(string file | file != "" | parent.hasLocationInfo(file, _, _, _, _)) and
n = strictcount(TypeParamType tpt | tpt.getParent() = parent)
}

from TypeParamType tpt, TypeParamParentEntity ty
where ty = tpt.getParent()
select ty.getQualifiedName(), tpt.getIndex(), tpt.getParamName(), tpt.getConstraint().pp()
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,9 @@ func callFunctionsInAnotherPackage() {
_ = anotherpkg.GenericFunctionInAnotherPackage[string]("world")
_ = anotherpkg.GenericFunctionInAnotherPackage("world")
}

func multipleAnonymousTypeParamsFunc[_ any, _ string, _ any]() {}

type multipleAnonymousTypeParamsType[_ any, _ string, _ any] struct{}

func (x multipleAnonymousTypeParamsType[_, _, _]) f() {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| genericFunctions.go:138:29:138:40 | ShortestPath | 0 | genericFunctions.go:138:42:138:45 | from |
| genericFunctions.go:138:29:138:40 | ShortestPath | 1 | genericFunctions.go:138:48:138:49 | to |
| genericFunctions.go:138:29:138:40 | ShortestPath | -1 | genericFunctions.go:138:7:138:7 | g |
| genericFunctions.go:154:51:154:51 | f | -1 | genericFunctions.go:154:7:154:7 | x |
| main.go:7:6:7:7 | f1 | 0 | main.go:7:9:7:9 | x |
| main.go:9:12:9:13 | f2 | 0 | main.go:9:15:9:15 | x |
| main.go:9:12:9:13 | f2 | 1 | main.go:9:18:9:18 | y |
Expand Down
Loading

0 comments on commit cb53911

Please sign in to comment.