Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/tooling-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,10 @@ jobs:

- name: Run PyTest
run: |
pytest scripts/release/update_release_assets_test.py
pytest scripts/release/update_release_assets_test.py \
scripts/release/create_supported_rules_list_test.py \
scripts/verify_rule_package_consistency_test.py

- name: Run matrix tooling regression tests
shell: pwsh
run: ./scripts/matrix_testing/Get-TestFile.Tests.ps1
16 changes: 16 additions & 0 deletions c/misra/src/codeql-suites/misra-c-2023.qls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- description: MISRA C 2023 - Third Edition, Second Revision
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
- problem
- path-problem
tags contain:
- external/misra/c/2012/third-edition-first-revision
- external/misra/c/2012/amendment2
- external/misra/c/2012/amendment3
- external/misra/c/2012/amendment4
- exclude:
tags contain:
- external/misra/audit
- external/misra/strict
- external/misra/default-disabled
4 changes: 3 additions & 1 deletion c/misra/src/codeql-suites/misra-c-advisory.qls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- description: MISRA C 2023 (Advisory)
- description: MISRA C 2025 (Advisory)
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
Expand All @@ -9,4 +9,6 @@
- exclude:
tags contain:
- external/misra/audit
- external/misra/strict
- external/misra/default-disabled
- external/misra/legacy
7 changes: 5 additions & 2 deletions c/misra/src/codeql-suites/misra-c-audit.qls
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
- description: MISRA C 2023 (Audit)
- description: MISRA C 2025 (Audit)
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
- problem
- path-problem
tags contain:
- external/misra/c/audit
- external/misra/audit
- exclude:
tags contain:
- external/misra/legacy
3 changes: 2 additions & 1 deletion c/misra/src/codeql-suites/misra-c-default.qls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- description: MISRA C 2023 (Default)
- description: MISRA C 2025 (Default)
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
Expand All @@ -9,3 +9,4 @@
- external/misra/audit
- external/misra/strict
- external/misra/default-disabled
- external/misra/legacy
4 changes: 3 additions & 1 deletion c/misra/src/codeql-suites/misra-c-mandatory.qls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- description: MISRA C 2023 (Advisory)
- description: MISRA C 2025 (Mandatory)
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
Expand All @@ -9,4 +9,6 @@
- exclude:
tags contain:
- external/misra/audit
- external/misra/strict
- external/misra/default-disabled
- external/misra/legacy
4 changes: 3 additions & 1 deletion c/misra/src/codeql-suites/misra-c-required.qls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- description: MISRA C 2023 (Required)
- description: MISRA C 2025 (Required)
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
Expand All @@ -9,4 +9,6 @@
- exclude:
tags contain:
- external/misra/audit
- external/misra/strict
- external/misra/default-disabled
- external/misra/legacy
5 changes: 4 additions & 1 deletion c/misra/src/codeql-suites/misra-c-strict.qls
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
- description: MISRA C 2023 (Strict)
- description: MISRA C 2025 (Strict)
- qlpack: codeql/misra-c-coding-standards
- include:
kind:
- problem
- path-problem
tags contain:
- external/misra/strict
- exclude:
tags contain:
- external/misra/legacy
2 changes: 1 addition & 1 deletion c/misra/src/codeql-suites/misra-default.qls
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- description: "DEPRECATED - MISRA C 2012 - use misra-c-default.qls instead"
- description: "DEPRECATED - MISRA C 2025 - use misra-c-default.qls instead"
- import: codeql-suites/misra-c-default.qls
22 changes: 22 additions & 0 deletions c/misra/src/codingstandards/c/misra/ReservedMacroNames.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** Provides the reserved-macro detector shared by MISRA C guideline identities. */

import cpp
import codingstandards.cpp.Naming

/** Gets a reserved name defined or undefined by `directive`. */
string getReservedMacroName(PreprocessorDirective directive) {
(
directive.(Macro).hasName(result)
or
directive.(PreprocessorUndef).getName() = result
) and
(
Naming::Cpp14::hasStandardLibraryMacroName(result)
or
Naming::Cpp14::hasStandardLibraryObjectName(result)
or
result.regexpMatch("_.*")
or
result = "defined"
)
}
25 changes: 25 additions & 0 deletions c/misra/src/codingstandards/c/misra/SinglePointOfExit.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** Provides the exit detector shared by Advisory and Disapplied query wrappers. */

import cpp

/** A return statement explicitly written in source code. */
private class UserReturn extends ReturnStmt {
UserReturn() { not this.isCompilerGenerated() }
}

/** Holds if `function` has an offending `statement`, with `message` explaining why. */
predicate problems(Function function, string message, ReturnStmt statement) {
function.hasDefinition() and
count(function.getBlock()) = 1 and
not function.isCompilerGenerated() and
statement instanceof UserReturn and
statement.getEnclosingFunction() = function and
(
count(UserReturn other | other.getEnclosingFunction() = function) > 1 and
message = "Function has more than one $@."
or
count(UserReturn other | other.getEnclosingFunction() = function) = 1 and
not function.getBlock().getLastStmt() instanceof UserReturn and
message = "The $@ is not the last statement of the function."
)
}
2 changes: 1 addition & 1 deletion c/misra/src/qlpack.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: codeql/misra-c-coding-standards
version: 2.63.0-dev
description: MISRA C 2012
description: MISRA C 2025
suites: codeql-suites
license: MIT
default-suite-file: codeql-suites/misra-c-default.qls
Expand Down
25 changes: 25 additions & 0 deletions c/misra/src/rules/DIR-1-2/LanguageExtensionsShouldBeMinimized.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @id c/misra/language-extensions-should-be-minimized
* @name DIR-1-2: Language extensions should be minimized
* @description Language extensions are not portable to other compilers and their use should be
* minimized.
* @kind problem
* @precision high
* @problem.severity recommendation
* @tags external/misra/id/dir-1-2
* maintainability
* readability
* external/misra/c/2025
* external/misra/obligation/advisory
*/

import cpp
import codingstandards.c.misra
import codingstandards.cpp.AlertReporting
import codingstandards.c.Extensions

from CCompilerExtension extension
where
not isExcluded(MacroUnwrapper<CCompilerExtension>::unwrapElement(extension),
Language3Package::languageExtensionsShouldBeMinimizedQuery())
select MacroUnwrapper<CCompilerExtension>::unwrapElement(extension), extension.getMessage()
2 changes: 1 addition & 1 deletion c/misra/src/rules/DIR-5-3/BannedDynamicThreadCreation.ql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @problem.severity error
* @tags external/misra/id/dir-5-3
* external/misra/c/2012/amendment4
* external/misra/c/audit
* external/misra/audit
* correctness
* maintainability
* concurrency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* maintainability
* readability
* external/misra/c/2012/third-edition-first-revision
* external/misra/legacy
* external/misra/obligation/advisory
*/

Expand Down
27 changes: 4 additions & 23 deletions c/misra/src/rules/RULE-15-5/FunctionReturnCondition.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,16 @@
* readability
* correctness
* external/misra/c/2012/third-edition-first-revision
* external/misra/legacy
* external/misra/obligation/advisory
*/

import cpp
import codingstandards.c.misra
import codingstandards.c.misra.SinglePointOfExit

class UserWrittenReturnStmt extends ReturnStmt {
UserWrittenReturnStmt() { not this.isCompilerGenerated() }
}

from Function func, string message, UserWrittenReturnStmt returnStmt
from Function func, string message, ReturnStmt returnStmt
where
not isExcluded(func, Statements5Package::functionReturnConditionQuery()) and
func.hasDefinition() and
// Ignore functions which have multiple bodies
count(func.getBlock()) = 1 and
// Ignore functions which are compiler generated
not func.isCompilerGenerated() and
// Report all the return statements in the function
returnStmt.getEnclosingFunction() = func and
(
// There is more than one return statement
count(UserWrittenReturnStmt return | return.getEnclosingFunction() = func) > 1 and
message = "Function has more than one $@."
or
// There is exactly one return statement
count(UserWrittenReturnStmt return | return.getEnclosingFunction() = func) = 1 and
// But it is not the last statement in the function
not func.getBlock().getLastStmt() instanceof UserWrittenReturnStmt and
message = "The $@ is not the last statement of the function."
)
problems(func, message, returnStmt)
select func, message, returnStmt, "return statement"
22 changes: 22 additions & 0 deletions c/misra/src/rules/RULE-15-5/SinglePointOfExit.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @id c/misra/single-point-of-exit
* @name RULE-15-5: A function should have a single point of exit at the end
* @description A single exit can be enforced when this Disapplied guideline is recategorized.
* @kind problem
* @precision very-high
* @problem.severity recommendation
* @tags external/misra/id/rule-15-5
* maintainability
* external/misra/c/2025
* external/misra/obligation/disapplied
*/

import cpp
import codingstandards.c.misra
import codingstandards.c.misra.SinglePointOfExit

from Function function, string message, ReturnStmt statement
where
not isExcluded(function, Statements5Package::singlePointOfExitQuery()) and
problems(function, message, statement)
select function, message, statement, "return statement"
1 change: 1 addition & 0 deletions c/misra/src/rules/RULE-17-3/FunctionDeclaredImplicitly.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* correctness
* readability
* external/misra/c/2012/third-edition-first-revision
* external/misra/c/2025
* external/misra/obligation/mandatory
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @tags external/misra/id/rule-17-5
* correctness
* external/misra/c/2012/third-edition-first-revision
* external/misra/c/2025
* external/misra/obligation/required
*/

Expand Down
1 change: 1 addition & 0 deletions c/misra/src/rules/RULE-17-6/UseOfArrayStatic.ql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @tags external/misra/id/rule-17-6
* correctness
* external/misra/c/2012/third-edition-first-revision
* external/misra/legacy
* external/misra/obligation/mandatory
*/

Expand Down
2 changes: 1 addition & 1 deletion c/misra/src/rules/RULE-2-8/UnusedObjectDefinitionStrict.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* maintainability
* performance
* external/misra/c/2012/amendment4
* external/misra/c/strict
* external/misra/strict
* external/misra/obligation/advisory
*/

Expand Down
22 changes: 22 additions & 0 deletions c/misra/src/rules/RULE-20-15/ReservedMacroName.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @id c/misra/reserved-macro-name
* @name RULE-20-15: Reserved identifiers shall not be defined or undefined
* @description Defining or undefining reserved names can cause undefined behavior.
* @kind problem
* @precision high
* @problem.severity warning
* @tags external/misra/id/rule-20-15
* correctness
* external/misra/c/2025
* external/misra/obligation/required
*/

import cpp
import codingstandards.c.misra
import codingstandards.c.misra.ReservedMacroNames

from PreprocessorDirective directive, string name
where
not isExcluded(directive, Preprocessor4Package::reservedMacroNameQuery()) and
name = getReservedMacroName(directive)
select directive, "Reserved identifier '" + name + "' has been undefined or redefined."
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,16 @@
* readability
* maintainability
* external/misra/c/2012/third-edition-first-revision
* external/misra/legacy
* external/misra/obligation/required
*/

import cpp
import codingstandards.c.misra
import codingstandards.cpp.Naming
import codingstandards.c.misra.ReservedMacroNames

from PreprocessorDirective p, string name
where
not isExcluded(p, Preprocessor4Package::defineAndUndefUsedOnReservedIdentifierOrMacroNameQuery()) and
(
p.(Macro).hasName(name)
or
p.(PreprocessorUndef).getName() = name
) and
(
Naming::Cpp14::hasStandardLibraryMacroName(name)
or
Naming::Cpp14::hasStandardLibraryObjectName(name)
or
name.regexpMatch("_.*")
or
name = "defined"
)
name = getReservedMacroName(p)
select p, "Reserved identifier '" + name + "' has been undefined or redefined."
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* maintainability
* readability
* external/misra/c/2012/third-edition-first-revision
* external/misra/legacy
* external/misra/obligation/required
*/

Expand Down
Loading
Loading