Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6fda6fa
Add Banned8
jeongsoolee09 Mar 24, 2026
cd095be
Add Banned5
jeongsoolee09 Mar 24, 2026
e4b4e4b
Add Banned6 and improve `@description` metadata of A9-5-1
jeongsoolee09 Mar 24, 2026
25c9df8
Fix an editing mistake on rules.csv
jeongsoolee09 Mar 24, 2026
e682b81
Fix query formatting
jeongsoolee09 Mar 24, 2026
cfaccb3
Re-generate package files with new names and add shared test that was…
jeongsoolee09 Mar 24, 2026
52b590b
Fill in shared query file for BannedSyntax and Banned6
jeongsoolee09 Mar 24, 2026
895ffbb
Populate shared query for Banned5 / Representation and make shared te…
jeongsoolee09 Mar 24, 2026
a54f56d
Minor formatting
jeongsoolee09 Mar 24, 2026
e76a2d2
Fix query formatting
jeongsoolee09 Mar 24, 2026
5f0ad4d
Remove UnionKeywordUsed query and test
mbaluda Apr 2, 2026
a23f7a5
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Banned856
mbaluda Apr 2, 2026
97b5fa5
remove bitFieldsShouldNotBeDeclaredQuery.ql
mbaluda Apr 2, 2026
6b86b72
Remove duplicate tests
mbaluda Apr 2, 2026
33e536d
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Banned856
jeongsoolee09 Apr 6, 2026
67d06e9
Surround code bits with single-quotes
jeongsoolee09 Apr 9, 2026
b73fab8
Un-share `UnionKeywordUsed`
jeongsoolee09 Apr 9, 2026
5740aaa
Add `"readability"` tag to Banned8.json
jeongsoolee09 Apr 9, 2026
bf7a636
Shorten shared query name
jeongsoolee09 Apr 9, 2026
085033d
Update shared test query
jeongsoolee09 Apr 9, 2026
d4233c5
Fix formatting
jeongsoolee09 Apr 9, 2026
750cb2c
Add clickable links to the alert message
jeongsoolee09 Apr 9, 2026
a2d3c0e
Add change note for the breaking change
jeongsoolee09 Apr 9, 2026
febb828
Make the @tags property consistent
jeongsoolee09 Apr 9, 2026
97637a4
Merge branch 'main' into jeongsoolee09/MISRA-C++-2023-Banned856
jeongsoolee09 Apr 9, 2026
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
3 changes: 3 additions & 0 deletions change_notes/2026-04-09-bit-field-declared-query-rename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `A9-6-2` - `BitFieldsShallBeUsedOnlyWhenInterfacingToHardwareOrConformingToCommunicationProtocols.ql`:
- Shorten the name to `BitFieldsShouldNotBeDeclaredAutosarCpp`, where the name shared query it imports is `BitFieldsShouldNotBeDeclared`.
- Tag `"portability"` is added.
9 changes: 5 additions & 4 deletions cpp/autosar/src/rules/A9-5-1/UnionsUsed.ql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @id cpp/autosar/unions-used
* @name A9-5-1: Unions shall not be used
* @description Unions shall not be used. Tagged untions can be used if std::variant is not
* @description Unions shall not be used. Tagged unions can be used if 'std::variant' is not
* available.
* @kind problem
* @precision very-high
Expand Down Expand Up @@ -34,8 +34,9 @@ class TaggedUnion extends UserType {
}
}

from Union u
from Union u, string message
where
not isExcluded(u, BannedSyntaxPackage::unionsUsedQuery()) and
not u.getParentScope() instanceof TaggedUnion
select u, u.getName() + " is not a tagged union."
not u.getParentScope() instanceof TaggedUnion and
message = "'" + u.getName() + "' is not a tagged union."
select u, message

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @id cpp/autosar/bit-fields-should-not-be-declared-autosar-cpp
* @name A9-6-2: Bit-fields shall be used only when interfacing to hardware or conforming to communication protocols
* @description The usage of bit-fields increases code complexity and certain aspects of bit-field
* manipulation can be error prone and implementation defined. Hence a bit-field usage
* is reserved only when interfacing to hardware or conformance to communication
* protocols.
* @kind problem
* @precision very-high
* @problem.severity recommendation
* @tags external/autosar/id/a9-6-2
* maintainability
* portability
* external/autosar/allocated-target/design
* external/autosar/enforcement/partially-automated
* external/autosar/obligation/required
*/

import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.rules.bitfieldsshouldnotbedeclared.BitFieldsShouldNotBeDeclared

module BitFieldsShouldNotBeDeclaredAutosarCppConfig implements BitFieldsShouldNotBeDeclaredConfigSig
{
Query getQuery() { result = RepresentationPackage::bitFieldsShouldNotBeDeclaredAutosarCppQuery() }
}

import BitFieldsShouldNotBeDeclared<BitFieldsShouldNotBeDeclaredAutosarCppConfig>
4 changes: 2 additions & 2 deletions cpp/autosar/test/rules/A9-5-1/UnionsUsed.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| test.cpp:14:9:14:9 | u | u is not a tagged union. |
| test.cpp:21:7:21:7 | u | u is not a tagged union. |
| test.cpp:14:9:14:9 | u | 'u' is not a tagged union. |
| test.cpp:21:7:21:7 | u | 'u' is not a tagged union. |

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cpp/common/test/rules/bitfieldsshouldnotbedeclared/BitFieldsShouldNotBeDeclared.ql
287 changes: 287 additions & 0 deletions cpp/common/src/codingstandards/cpp/CommonTypes.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
import cpp as default

/*
* Implementations of the C/C++ Fixed Width Types from cstdint.
*
* TODO: Deprecate once this is available in the CodeQL standard library.
*/

/**
* A parent class representing C/C++ a typedef'd `UserType` such as `int8_t`.
*/
abstract private class IntegralUnderlyingUserType extends default::UserType {
IntegralUnderlyingUserType() { this.getUnderlyingType() instanceof default::IntegralType }
}

abstract private class TFixedWidthIntegralType extends IntegralUnderlyingUserType { }

/**
* A C/C++ fixed-width numeric type, such as `int8_t`.
*/
class FixedWidthIntegralType extends TFixedWidthIntegralType {
FixedWidthIntegralType() { this instanceof TFixedWidthIntegralType }
}

abstract private class TMinimumWidthIntegralType extends IntegralUnderlyingUserType { }

/**
* A C/C++ minimum-width numeric type, such as `int_least8_t`.
*/
class MinimumWidthIntegralType extends TMinimumWidthIntegralType {
MinimumWidthIntegralType() { this instanceof TMinimumWidthIntegralType }
}

abstract private class TFastestMinimumWidthIntegralType extends IntegralUnderlyingUserType { }

/**
* A C/C++ minimum-width numeric type, representing the fastest integer type with a
* width of at least `N` such as `int_fast8_t`.
*/
class FastestMinimumWidthIntegralType extends TFastestMinimumWidthIntegralType {
FastestMinimumWidthIntegralType() { this instanceof TFastestMinimumWidthIntegralType }
}

/**
* An enum type based on a fixed-width integer type. For instance, `enum e: uint8_t = { a, b };`
*/
class FixedWidthEnumType extends default::UserType {
FixedWidthEnumType() {
this.(default::Enum).getExplicitUnderlyingType() instanceof FixedWidthIntegralType
}
}

/**
* The C/C++ `int8_t` type.
*/
class Int8_t extends TFixedWidthIntegralType {
Int8_t() { this.hasGlobalOrStdName("int8_t") }

override string getAPrimaryQlClass() { result = "Int8_t" }
}

/**
* The C/C++ `int16_t` type.
*/
class Int16_t extends TFixedWidthIntegralType {
Int16_t() { this.hasGlobalOrStdName("int16_t") }

override string getAPrimaryQlClass() { result = "Int16_t" }
}

/**
* The C/C++ `int32_t` type.
*/
class Int32_t extends TFixedWidthIntegralType {
Int32_t() { this.hasGlobalOrStdName("int32_t") }

override string getAPrimaryQlClass() { result = "Int32_t" }
}

/**
* The C/C++ `int64_t` type.
*/
class Int64_t extends TFixedWidthIntegralType {
Int64_t() { this.hasGlobalOrStdName("int64_t") }

override string getAPrimaryQlClass() { result = "Int64_t" }
}

/**
* The C/C++ `uint8_t` type.
*/
class UInt8_t extends TFixedWidthIntegralType {
UInt8_t() { this.hasGlobalOrStdName("uint8_t") }

override string getAPrimaryQlClass() { result = "UInt8_t" }
}

/**
* The C/C++ `uint16_t` type.
*/
class UInt16_t extends TFixedWidthIntegralType {
UInt16_t() { this.hasGlobalOrStdName("uint16_t") }

override string getAPrimaryQlClass() { result = "UInt16_t" }
}

/**
* The C/C++ `uint32_t` type.
*/
class UInt32_t extends TFixedWidthIntegralType {
UInt32_t() { this.hasGlobalOrStdName("uint32_t") }

override string getAPrimaryQlClass() { result = "UInt32_t" }
}

/**
* The C/C++ `uint64_t` type.
*/
class UInt64_t extends TFixedWidthIntegralType {
UInt64_t() { this.hasGlobalOrStdName("uint64_t") }

override string getAPrimaryQlClass() { result = "UInt64_t" }
}

/**
* The C/C++ `int_least8_t` type.
*/
class Int_least8_t extends TMinimumWidthIntegralType {
Int_least8_t() { this.hasGlobalOrStdName("int_least8_t") }

override string getAPrimaryQlClass() { result = "Int_least8_t" }
}

/**
* The C/C++ `int_least16_t` type.
*/
class Int_least16_t extends TMinimumWidthIntegralType {
Int_least16_t() { this.hasGlobalOrStdName("int_least16_t") }

override string getAPrimaryQlClass() { result = "Int_least16_t" }
}

/**
* The C/C++ `int_least32_t` type.
*/
class Int_least32_t extends TMinimumWidthIntegralType {
Int_least32_t() { this.hasGlobalOrStdName("int_least32_t") }

override string getAPrimaryQlClass() { result = "Int_least32_t" }
}

/**
* The C/C++ `int_least64_t` type.
*/
class Int_least64_t extends TMinimumWidthIntegralType {
Int_least64_t() { this.hasGlobalOrStdName("int_least64_t") }

override string getAPrimaryQlClass() { result = "Int_least64_t" }
}

/**
* The C/C++ `uint_least8_t` type.
*/
class UInt_least8_t extends TMinimumWidthIntegralType {
UInt_least8_t() { this.hasGlobalOrStdName("uint_least8_t") }

override string getAPrimaryQlClass() { result = "UInt_least8_t" }
}

/**
* The C/C++ `uint_least16_t` type.
*/
class UInt_least16_t extends TMinimumWidthIntegralType {
UInt_least16_t() { this.hasGlobalOrStdName("uint_least16_t") }

override string getAPrimaryQlClass() { result = "UInt_least16_t" }
}

/**
* The C/C++ `uint_least32_t` type.
*/
class UInt_least32_t extends TMinimumWidthIntegralType {
UInt_least32_t() { this.hasGlobalOrStdName("uint_least32_t") }

override string getAPrimaryQlClass() { result = "UInt_least32_t" }
}

/**
* The C/C++ `uint_least64_t` type.
*/
class UInt_least64_t extends TMinimumWidthIntegralType {
UInt_least64_t() { this.hasGlobalOrStdName("uint_least64_t") }

override string getAPrimaryQlClass() { result = "UInt_least64_t" }
}

/**
* The C/C++ `int_fast8_t` type.
*/
class Int_fast8_t extends TFastestMinimumWidthIntegralType {
Int_fast8_t() { this.hasGlobalOrStdName("int_fast8_t") }

override string getAPrimaryQlClass() { result = "Int_fast8_t" }
}

/**
* The C/C++ `int_fast16_t` type.
*/
class Int_fast16_t extends TFastestMinimumWidthIntegralType {
Int_fast16_t() { this.hasGlobalOrStdName("int_fast16_t") }

override string getAPrimaryQlClass() { result = "Int_fast16_t" }
}

/**
* The C/C++ `int_fast32_t` type.
*/
class Int_fast32_t extends TFastestMinimumWidthIntegralType {
Int_fast32_t() { this.hasGlobalOrStdName("int_fast32_t") }

override string getAPrimaryQlClass() { result = "Int_fast32_t" }
}

/**
* The C/C++ `int_fast64_t` type.
*/
class Int_fast64_t extends TFastestMinimumWidthIntegralType {
Int_fast64_t() { this.hasGlobalOrStdName("int_fast64_t") }

override string getAPrimaryQlClass() { result = "Int_fast64_t" }
}

/**
* The C/C++ `uint_fast8_t` type.
*/
class UInt_fast8_t extends TFastestMinimumWidthIntegralType {
UInt_fast8_t() { this.hasGlobalOrStdName("uint_fast8_t") }

override string getAPrimaryQlClass() { result = "UInt_fast8_t" }
}

/**
* The C/C++ `uint_fast16_t` type.
*/
class UInt_fast16_t extends TFastestMinimumWidthIntegralType {
UInt_fast16_t() { this.hasGlobalOrStdName("uint_fast16_t") }

override string getAPrimaryQlClass() { result = "UInt_fast16_t" }
}

/**
* The C/C++ `uint_fast32_t` type.
*/
class UInt_fast32_t extends TFastestMinimumWidthIntegralType {
UInt_fast32_t() { this.hasGlobalOrStdName("uint_fast32_t") }

override string getAPrimaryQlClass() { result = "UInt_fast32_t" }
}

/**
* The C/C++ `uint_fast64_t` type.
*/
class UInt_fast64_t extends TFastestMinimumWidthIntegralType {
UInt_fast64_t() { this.hasGlobalOrStdName("uint_fast64_t") }

override string getAPrimaryQlClass() { result = "UInt_fast64_t" }
}

/**
* Type that models a type that is either a pointer or a reference type.
*/
class PointerOrReferenceType extends default::DerivedType {
PointerOrReferenceType() {
this instanceof default::PointerType or
this instanceof default::ReferenceType
}
}

/**
* Type that models a char type that is explicitly signed or unsigned.
*/
class ExplictlySignedOrUnsignedCharType extends default::CharType {
ExplictlySignedOrUnsignedCharType() {
isExplicitlySigned() or
isExplicitlyUnsigned()
}
}
Loading
Loading