forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CodeQL query to detect redundant assignments
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Showing
6 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: "Custom CodeQL Analysis" | ||
|
||
queries: | ||
- uses: ./.github/codeql/custom-queries/cpp/redundantAssignment.ql | ||
- uses: ./.github/codeql/openzfs-code-scanning.qls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: "Custom CodeQL Analysis" | ||
|
||
paths-ignore: | ||
- tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: openzfs-cpp-queries | ||
version: 0.0.0 | ||
libraryPathDependencies: codeql-cpp | ||
suites: openzfs-cpp-suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import cpp | ||
|
||
from Assignment firstAssign, Assignment secondAssign | ||
where | ||
// The first assignment is from 'a' to 'b' | ||
firstAssign.getLValue().(VariableAccess).getTarget() = secondAssign.getRValue().(VariableAccess).getTarget() and | ||
firstAssign.getRValue().(VariableAccess).getTarget() = secondAssign.getLValue().(VariableAccess).getTarget() and | ||
// Ensure 'a' and 'b' are not modified in between these assignments | ||
not exists(Assignment anyAssign | | ||
anyAssign.getEnclosingFunction() = firstAssign.getEnclosingFunction() and | ||
anyAssign.getLocation().isBetween(firstAssign.getLocation(), secondAssign.getLocation()) and | ||
( | ||
anyAssign.getLValue().(VariableAccess).getTarget() = firstAssign.getLValue().(VariableAccess).getTarget() or | ||
anyAssign.getLValue().(VariableAccess).getTarget() = firstAssign.getRValue().(VariableAccess).getTarget() | ||
) | ||
) | ||
select secondAssign, "This assignment is redundant." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Reusing existing QL Pack | ||
- import: codeql-suites/cpp-code-scanning.qls | ||
from: codeql-cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters