Skip to content

Commit 61ff9d0

Browse files
committed
Merge remote-tracking branch 'origin/main' into redsun82-rust-analyzer-update
2 parents 150e30c + 7f60101 commit 61ff9d0

11 files changed

Lines changed: 106 additions & 33 deletions

File tree

csharp/ql/src/Language Abuse/SimplifyBoolExpr.ql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ predicate negatedOperators(string op, string negated) {
7575
negatedOperators(negated, op)
7676
}
7777

78+
/** Holds if replacing `expr` with `operatorName` could call an enclosing operator. */
79+
private predicate couldCallEnclosingOperator(LogicalNotExpr expr, string operatorName) {
80+
exists(BinaryOperation binary, Operator enclosingOperator |
81+
binary = expr.getOperand() and
82+
enclosingOperator = expr.getEnclosingCallable().getEnclosingCallable*() and
83+
enclosingOperator.getName() = operatorName and
84+
binary
85+
.getLeftOperand()
86+
.getType()
87+
.isImplicitlyConvertibleTo(enclosingOperator.getParameter(0).getType()) and
88+
binary
89+
.getRightOperand()
90+
.getType()
91+
.isImplicitlyConvertibleTo(enclosingOperator.getParameter(1).getType())
92+
)
93+
}
94+
7895
predicate simplifyBinaryExpr(string op, string withFalseOperand, string withTrueOperand) {
7996
op = "==" and withTrueOperand = "A" and withFalseOperand = "!A"
8097
or
@@ -90,7 +107,8 @@ predicate pushNegation(LogicalNotExpr expr, string oldPattern, string newPattern
90107
or
91108
exists(string oldOperator, string newOperator |
92109
oldOperator = expr.getOperand().(BinaryOperation).getOperator() and
93-
negatedOperators(oldOperator, newOperator)
110+
negatedOperators(oldOperator, newOperator) and
111+
not couldCallEnclosingOperator(expr, newOperator)
94112
|
95113
oldPattern = "!(A " + oldOperator + " B)" and
96114
newPattern = "A " + newOperator + " B"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `cs/simplifiable-boolean-expression` query no longer suggests replacing a negated comparison when the replacement could recursively call an enclosing user-defined operator in `build-mode: none` databases.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
3+
// The missing matching operators deliberately model an incompletely compiled database.
4+
class IncompleteOperatorTest
5+
{
6+
// GOOD: Rewriting this as `left != right` could recursively call this operator.
7+
public static bool operator !=(IncompleteOperatorTest left, IncompleteOperatorTest right)
8+
{
9+
// BAD: Rewriting this built-in comparison cannot call the enclosing operator.
10+
bool valuesDiffer = !(left.Value == right.Value); // $ Alert
11+
12+
// BAD: Explicitly converting both operands prevents a call to the enclosing operator.
13+
bool referencesDiffer = !((object)left == (object)right); // $ Alert
14+
15+
return valuesDiffer && referencesDiffer && !(left == right);
16+
}
17+
18+
// GOOD: Rewriting this as `left >= right` could recursively call this operator.
19+
public static bool operator >=(IncompleteOperatorTest left, IncompleteOperatorTest right) => !(left < right);
20+
21+
int Value { get; }
22+
}
23+
24+
class IncompleteReverseOperatorTest
25+
{
26+
// GOOD: Rewriting this as `left == right` could recursively call this operator.
27+
public static bool operator ==(IncompleteReverseOperatorTest left, IncompleteReverseOperatorTest right) => !(left != right);
28+
29+
// GOOD: Rewriting this as `left < right` could recursively call this operator.
30+
public static bool operator <(IncompleteReverseOperatorTest left, IncompleteReverseOperatorTest right) => !(left >= right);
31+
}
32+
33+
class IncompleteGreaterOperatorTest
34+
{
35+
// GOOD: Rewriting this as `left <= right` could recursively call this operator.
36+
public static bool operator <=(IncompleteGreaterOperatorTest left, IncompleteGreaterOperatorTest right) => !(left > right);
37+
38+
// GOOD: Rewriting this as `left > right` could recursively call this operator.
39+
public static bool operator >(IncompleteGreaterOperatorTest left, IncompleteGreaterOperatorTest right) => !(left <= right);
40+
}
41+
42+
class IncompleteDifferentOperatorTest
43+
{
44+
// BAD: The suggested operator differs from the enclosing operator.
45+
public static bool operator >(IncompleteDifferentOperatorTest left, IncompleteDifferentOperatorTest right) => !(left == right); // $ Alert
46+
}
47+
48+
class IncompleteNestedOperatorTest
49+
{
50+
public static bool operator !=(IncompleteNestedOperatorTest left, IncompleteNestedOperatorTest right)
51+
{
52+
// GOOD: The replacement could call the enclosing operator from this lambda.
53+
Func<bool> lambda = () => !(left == right);
54+
55+
// GOOD: The replacement could call the enclosing operator from this local function.
56+
bool Local() => !(left == right);
57+
58+
return lambda() || Local();
59+
}
60+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| SimplifyBoolExpr.cs:10:29:10:56 | !... | The expression '!(A == B)' can be simplified to 'A != B'. |
2+
| SimplifyBoolExpr.cs:13:33:13:64 | !... | The expression '!(A == B)' can be simplified to 'A != B'. |
3+
| SimplifyBoolExpr.cs:45:115:45:130 | !... | The expression '!(A == B)' can be simplified to 'A != B'. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Language Abuse/SimplifyBoolExpr.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --standalone

go/actions/test/action.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: Test Go extractor
2-
description: Run build, QL tests, and optionally basic code sanity checks (formatting and generated code) for the Go extractor
2+
description: Run build, QL tests, and optionally qhelp generation for the Go extractor
33
inputs:
44
go-test-version:
55
description: Which Go version to use for running the tests
66
required: false
77
default: "~1.26.6"
88
run-code-checks:
9-
description: Whether to run formatting, code and qhelp generation checks
9+
description: Whether to run qhelp generation checks
1010
required: false
1111
default: false
1212
runs:
@@ -26,28 +26,11 @@ runs:
2626
shell: bash
2727
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
2828

29-
- name: Check checked-in generated code
30-
if: inputs.run-code-checks == 'true'
31-
shell: bash
32-
run: |
33-
bazel run go:gen
34-
git add .
35-
git diff --exit-code HEAD || (
36-
echo "please run bazel run //go:gen"
37-
exit 1
38-
)
39-
4029
- name: Build
4130
shell: bash
4231
run: |
43-
bazel run go:go-installer
44-
45-
- name: Check that all Go code is autoformatted
46-
if: inputs.run-code-checks == 'true' && !cancelled()
47-
shell: bash
48-
run: |
49-
cd go
50-
make check-formatting
32+
cd go/extractor
33+
go build ./...
5134
5235
- name: Compile qhelp files to markdown
5336
if: inputs.run-code-checks == 'true' && !cancelled()

rust/codeql-extractor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ options:
2525
title: Controls compression for the TRAP files written by the extractor.
2626
description: >
2727
This option is only intended for use in debugging the extractor. Accepted
28-
values are 'gzip' (to write gzip-compressed TRAP) 'zstd' (to write
29-
Zstandard-compressed TRAP) and 'none' (the default, to write uncompressed
28+
values are 'gzip' (to write gzip-compressed TRAP) 'zstd' (the default,
29+
to write Zstandard-compressed TRAP) and 'none' (to write uncompressed
3030
TRAP).
3131
type: string
3232
pattern: "^(none|gzip|zstd)$"

rust/extractor/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ use std::path::{Path, PathBuf};
2828
#[serde(rename_all = "lowercase")]
2929
#[clap(rename_all = "lowercase")]
3030
pub enum Compression {
31-
#[default] // TODO make gzip default
3231
None,
3332
Gzip,
33+
#[default]
3434
Zstd,
3535
}
3636

unified/BUILD.bazel

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup")
2+
load("//misc/bazel:os.bzl", "codeql_platform_select")
23
load("//misc/bazel:pkg.bzl", "codeql_pack", "codeql_pkg_files")
3-
load("//misc/bazel:utils.bzl", "select_os")
44

55
package(default_visibility = ["//visibility:public"])
66

@@ -41,12 +41,14 @@ codeql_pkg_files(
4141

4242
codeql_pkg_files(
4343
name = "extractor-arch",
44-
exes = select_os(
45-
posix = ["//unified/extractor"],
46-
windows = ["//unified/extractor-unsupported-os:extractor"],
47-
) + select_os(
48-
linux = ["//unified/swift-syntax-rs:swift_runtime_libs"],
49-
otherwise = [],
44+
exes = codeql_platform_select(
45+
linux64 = [
46+
"//unified/extractor",
47+
"//unified/swift-syntax-rs:swift_runtime_libs",
48+
],
49+
linux_arm64 = ["//unified/extractor-unsupported-os:extractor"],
50+
osx64 = ["//unified/extractor"],
51+
win64 = ["//unified/extractor-unsupported-os:extractor"],
5052
),
5153
prefix = "tools/{CODEQL_PLATFORM}",
5254
)

0 commit comments

Comments
 (0)