Skip to content

Commit e1a0d6d

Browse files
authored
Merge branch 'main' into michaelrfairhurst/implement-concurrency9-package
2 parents 8553103 + 259dc5c commit e1a0d6d

File tree

148 files changed

+3195
-981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3195
-981
lines changed

.github/workflows/upgrade_codeql_dependencies.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
5454
5555
- name: Create Pull Request
56-
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
56+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
5757
with:
5858
title: "Upgrade `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}"
5959
body: |

amendments.csv

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
language,standard,amendment,rule_id,supportable,implementation_category,implemented,difficulty
2-
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,No,Easy
2+
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,Yes,Easy
33
c,MISRA-C-2012,Amendment3,DIR-4-9,Yes,Refine,No,Easy
44
c,MISRA-C-2012,Amendment3,DIR-4-11,Yes,Refine,No,Import
55
c,MISRA-C-2012,Amendment3,RULE-1-4,Yes,Replace,No,Easy
6-
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,No,Easy
7-
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,No,Easy
8-
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,No,Import
9-
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,No,Easy
10-
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,No,Import
11-
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,No,Import
6+
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,Yes,Easy
7+
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,Yes,Easy
8+
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,Yes,Import
9+
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,Yes,Easy
10+
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,Yes,Import
11+
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,Yes,Import
1212
c,MISRA-C-2012,Amendment3,RULE-21-11,Yes,Clarification,Yes,Import
1313
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,No,Easy
14-
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,No,Easy
15-
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,No,Easy
16-
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,No,Very Hard
14+
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,Yes,Easy
15+
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,Yes,Easy
16+
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,Yes,Very Hard
1717
c,MISRA-C-2012,Amendment4,RULE-18-6,Yes,Expand,No,Medium
1818
c,MISRA-C-2012,Amendment4,RULE-18-8,Yes,Split,Yes,Easy
1919
c,MISRA-C-2012,Amendment4,RULE-2-2,Yes,Clarification,Yes,Import
2020
c,MISRA-C-2012,Amendment4,RULE-2-7,Yes,Clarification,Yes,Import
21-
c,MISRA-C-2012,Amendment4,RULE-3-1,Yes,Refine,No,Easy
21+
c,MISRA-C-2012,Amendment4,RULE-3-1,Yes,Refine,Yes,Easy
2222
c,MISRA-C-2012,Amendment4,RULE-8-6,Yes,Clarification,Yes,Import
2323
c,MISRA-C-2012,Amendment4,RULE-8-9,Yes,Clarification,Yes,Import
2424
c,MISRA-C-2012,Amendment4,RULE-9-4,Yes,Clarification,Yes,Import
2525
c,MISRA-C-2012,Amendment4,RULE-10-1,Yes,Clarification,Yes,Import
2626
c,MISRA-C-2012,Amendment4,RULE-18-3,Yes,Clarification,Yes,Import
2727
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,No,Easy
28-
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,No,Easy
28+
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,Yes,Easy
2929
c,MISRA-C-2012,Amendment4,RULE-9-2,Yes,Refine,No,Import
3030
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,Yes,Import
31-
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,No,Easy
31+
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
3232
c,MISRA-C-2012,Corrigendum2,RULE-8-2,Yes,Clarification,Yes,Import
33-
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,No,Easy
33+
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,Yes,Easy
3434
c,MISRA-C-2012,Corrigendum2,RULE-8-7,Yes,Clarification,Yes,Import
3535
c,MISRA-C-2012,Corrigendum2,RULE-10-1,Yes,Clarification,Yes,Import
36-
c,MISRA-C-2012,Corrigendum2,RULE-10-2,Yes,Refine,No,Easy
36+
c,MISRA-C-2012,Corrigendum2,RULE-10-2,Yes,Refine,Yes,Easy
3737
c,MISRA-C-2012,Corrigendum2,RULE-10-3,Yes,Clarification,Yes,Import
3838
c,MISRA-C-2012,Corrigendum2,RULE-11-3,Yes,Clarification,Yes,Import
3939
c,MISRA-C-2012,Corrigendum2,RULE-11-6,Yes,Clarification,Yes,Import
4040
c,MISRA-C-2012,Corrigendum2,RULE-13-2,Yes,Clarification,Yes,Import
4141
c,MISRA-C-2012,Corrigendum2,RULE-13-6,Yes,Clarification,Yes,Import
42-
c,MISRA-C-2012,Corrigendum2,RULE-14-3,Yes,Refine,No,Easy
42+
c,MISRA-C-2012,Corrigendum2,RULE-14-3,Yes,Refine,Yes,Easy
4343
c,MISRA-C-2012,Corrigendum2,RULE-15-7,Yes,Clarification,Yes,Import
4444
c,MISRA-C-2012,Corrigendum2,RULE-17-4,Yes,Clarification,Yes,Import
4545
c,MISRA-C-2012,Corrigendum2,RULE-17-5,Yes,Clarification,Yes,Import
46-
c,MISRA-C-2012,Corrigendum2,RULE-18-1,Yes,Refine,No,Easy
46+
c,MISRA-C-2012,Corrigendum2,RULE-18-1,Yes,Refine,Yes,Easy
4747
c,MISRA-C-2012,Corrigendum2,RULE-20-14,No,Clarification,Yes,Import
4848
c,MISRA-C-2012,Corrigendum2,RULE-21-19,Yes,Clarification,Yes,Import
49-
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,No,Easy
50-
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,Yes,Import
49+
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,Yes,Easy
50+
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,Yes,Import

c/cert/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

c/cert/src/rules/PRE31-C/SideEffectsInArgumentsToUnsafeMacros.ql

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import cpp
1515
import codingstandards.c.cert
1616
import codingstandards.cpp.Macro
1717
import codingstandards.cpp.SideEffect
18-
import codingstandards.cpp.StructuralEquivalence
1918
import codingstandards.cpp.sideeffect.DefaultEffects
2019
import codingstandards.cpp.sideeffect.Customizations
2120
import semmle.code.cpp.valuenumbering.HashCons

c/cert/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

c/common/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

c/common/test/includes/standard-library/stdatomic.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define ATOMIC_VAR_INIT(value) (value)
2+
#define atomic_init __c11_atomic_init
23
#define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj)))
34
typedef _Atomic(int) atomic_int;
45

c/common/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards-tests
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| test.c:4:13:4:18 | ... + ... | Array pointer p2 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
2-
| test.c:5:13:5:18 | ... + ... | Array pointer p3 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
3-
| test.c:6:13:6:18 | & ... | Array pointer p4 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
4-
| test.c:11:8:11:11 | ... -- | Array pointer p7 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
5-
| test.c:12:8:12:9 | p3 | Array pointer p8 points 1 element passed the end of $@. | test.c:2:7:2:8 | l1 | l1 |
1+
| test.c:4:13:4:18 | ... + ... | Array pointer p2 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
2+
| test.c:5:13:5:18 | ... + ... | Array pointer p3 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
3+
| test.c:6:13:6:18 | & ... | Array pointer p4 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
4+
| test.c:11:8:11:11 | ... -- | Array pointer p7 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |
5+
| test.c:12:8:12:9 | p3 | Array pointer p8 points 1 element past the end of $@. | test.c:2:7:2:8 | l1 | l1 |

c/common/test/rules/readofuninitializedmemory/test.c

+2
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,6 @@ void test_non_default_init() {
9494
static struct A ss;
9595
use_struct_A(
9696
ss); // COMPLIANT - static struct type variables are zero initialized
97+
_Atomic int x;
98+
use_int(x); // COMPLIANT - atomics are special, covered by other rules
9799
}

c/misra/src/codingstandards/c/misra/EssentialTypes.qll

+42-13
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import codingstandards.c.misra
66
import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
77
import MisraExpressions
88

9+
newtype TEssentialFloatCategory =
10+
Real() or
11+
Complex()
12+
913
newtype TEssentialTypeCategory =
1014
EssentiallyBooleanType() or
1115
EssentiallyCharacterType() or
1216
EssentiallyEnumType() or
1317
EssentiallySignedType() or
1418
EssentiallyUnsignedType() or
15-
EssentiallyFloatingType()
19+
EssentiallyFloatingType(TEssentialFloatCategory c)
1620

1721
/** An essential type category, as specified by Appendix D.1. */
1822
class EssentialTypeCategory extends TEssentialTypeCategory {
@@ -27,7 +31,9 @@ class EssentialTypeCategory extends TEssentialTypeCategory {
2731
or
2832
this = EssentiallyUnsignedType() and result = "essentially Unsigned type"
2933
or
30-
this = EssentiallyFloatingType() and result = "essentially Floating type"
34+
this = EssentiallyFloatingType(Real()) and result = "essentially Floating type"
35+
or
36+
this = EssentiallyFloatingType(Complex()) and result = "essentially Complex Floating type"
3137
}
3238
}
3339

@@ -145,8 +151,11 @@ EssentialTypeCategory getEssentialTypeCategory(Type type) {
145151
essentialType instanceof NamedEnumType and
146152
not essentialType instanceof MisraBoolType
147153
or
148-
result = EssentiallyFloatingType() and
149-
essentialType instanceof FloatingPointType
154+
result = EssentiallyFloatingType(Real()) and
155+
essentialType instanceof RealNumberType
156+
or
157+
result = EssentiallyFloatingType(Complex()) and
158+
essentialType instanceof ComplexNumberType
150159
)
151160
}
152161

@@ -168,6 +177,17 @@ Type getEssentialType(Expr e) {
168177

169178
Type getEssentialTypeBeforeConversions(Expr e) { result = e.(EssentialExpr).getEssentialType() }
170179

180+
/**
181+
* For most essential types, `Type.getSize()` is correct, except for complex floating types.
182+
*
183+
* For complex floating types, the size is the size of the real part, so we divide by 2.
184+
*/
185+
int getEssentialSize(Type essentialType) {
186+
if getEssentialTypeCategory(essentialType) = EssentiallyFloatingType(Complex())
187+
then result = essentialType.getSize() / 2
188+
else result = essentialType.getSize()
189+
}
190+
171191
class EssentialExpr extends Expr {
172192
Type getEssentialType() { result = this.getType() }
173193

@@ -308,12 +328,14 @@ class EssentialBinaryOperationSubjectToUsualConversions extends EssentialExpr, B
308328
exists(
309329
Type leftEssentialType, Type rightEssentialType,
310330
EssentialTypeCategory leftEssentialTypeCategory,
311-
EssentialTypeCategory rightEssentialTypeCategory
331+
EssentialTypeCategory rightEssentialTypeCategory, int intTypeSize
312332
|
313333
leftEssentialType = getEssentialType(getLeftOperand()) and
314334
rightEssentialType = getEssentialType(getRightOperand()) and
315335
leftEssentialTypeCategory = getEssentialTypeCategory(leftEssentialType) and
316-
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType)
336+
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType) and
337+
// For rules around addition/subtraction with char types:
338+
intTypeSize = any(IntType i | i.isSigned()).getSize()
317339
|
318340
if
319341
leftEssentialTypeCategory = rightEssentialTypeCategory and
@@ -336,14 +358,18 @@ class EssentialBinaryOperationSubjectToUsualConversions extends EssentialExpr, B
336358
class EssentialAddExpr extends EssentialBinaryOperationSubjectToUsualConversions, AddExpr {
337359
override Type getEssentialType() {
338360
exists(
339-
EssentialTypeCategory operandTypeCategory, EssentialTypeCategory otherOperandTypeCategory
361+
Type otherOperandType, EssentialTypeCategory operandTypeCategory,
362+
EssentialTypeCategory otherOperandTypeCategory, int intTypeSize
340363
|
341364
operandTypeCategory = getEssentialTypeCategory(getEssentialType(getAnOperand())) and
342-
otherOperandTypeCategory = getEssentialTypeCategory(getEssentialType(getAnOperand()))
365+
otherOperandType = getEssentialType(getAnOperand()) and
366+
otherOperandTypeCategory = getEssentialTypeCategory(otherOperandType) and
367+
intTypeSize = any(IntType i).getSize()
343368
|
344369
if
345370
operandTypeCategory = EssentiallyCharacterType() and
346-
otherOperandTypeCategory instanceof EssentiallySignedOrUnsignedType
371+
otherOperandTypeCategory instanceof EssentiallySignedOrUnsignedType and
372+
otherOperandType.getSize() <= intTypeSize
347373
then result instanceof PlainCharType
348374
else result = super.getEssentialType()
349375
)
@@ -356,15 +382,18 @@ class EssentialAddExpr extends EssentialBinaryOperationSubjectToUsualConversions
356382
class EssentialSubExpr extends EssentialBinaryOperationSubjectToUsualConversions, SubExpr {
357383
override Type getEssentialType() {
358384
exists(
359-
EssentialTypeCategory leftEssentialTypeCategory,
360-
EssentialTypeCategory rightEssentialTypeCategory
385+
EssentialTypeCategory leftEssentialTypeCategory, Type rightEssentialType,
386+
EssentialTypeCategory rightEssentialTypeCategory, int intTypeSize
361387
|
362388
leftEssentialTypeCategory = getEssentialTypeCategory(getEssentialType(getLeftOperand())) and
363-
rightEssentialTypeCategory = getEssentialTypeCategory(getEssentialType(getRightOperand()))
389+
rightEssentialType = getEssentialType(getRightOperand()) and
390+
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType) and
391+
intTypeSize = any(IntType i).getSize()
364392
|
365393
if
366394
leftEssentialTypeCategory = EssentiallyCharacterType() and
367-
rightEssentialTypeCategory instanceof EssentiallySignedOrUnsignedType
395+
rightEssentialTypeCategory instanceof EssentiallySignedOrUnsignedType and
396+
rightEssentialType.getSize() <= intTypeSize
368397
then result instanceof PlainCharType
369398
else result = super.getEssentialType()
370399
)

c/misra/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards
2-
version: 2.42.0-dev
2+
version: 2.44.0-dev
33
description: MISRA C 2012
44
suites: codeql-suites
55
license: MIT

c/misra/src/rules/DIR-4-6/PlainNumericalTypeUsedOverExplicitTypedef.ql

+51-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class BuiltInNumericType extends BuiltInType {
2929
this instanceof DoubleType
3030
or
3131
this instanceof LongDoubleType
32+
or
33+
this instanceof ComplexNumberType
3234
}
3335
}
3436

@@ -38,22 +40,64 @@ predicate forbiddenBuiltinNumericUsedInDecl(Variable var, string message) {
3840
message = "The type " + var.getType() + " is not a fixed-width numeric type."
3941
}
4042

43+
class SizedTypeString extends string {
44+
string pattern;
45+
int size;
46+
47+
bindingset[this]
48+
pragma[inline]
49+
SizedTypeString() {
50+
pattern = "(u?int|c?float)(4|8|16|32|64|128)_t" and
51+
this.regexpMatch(pattern) and
52+
size = this.regexpCapture(pattern, 2).toInt()
53+
}
54+
55+
bindingset[this]
56+
pragma[inline]
57+
int getSize() { result = size }
58+
59+
bindingset[this]
60+
pragma[inline]
61+
predicate isComplex() { this.charAt(0) = "c" }
62+
}
63+
64+
predicate forbiddenComplexType(CTypedefType typedef, string message) {
65+
typedef.getName().(SizedTypeString).isComplex() and
66+
(
67+
if typedef.getBaseType().stripTopLevelSpecifiers() instanceof ComplexNumberType
68+
then
69+
typedef.getSize() * 8 != typedef.getName().(SizedTypeString).getSize() * 2 and
70+
message = "The typedef type " + typedef.getName() + " does not have its indicated real size."
71+
else message = "The typedef type " + typedef.getName() + " is not a complex type."
72+
)
73+
}
74+
75+
predicate forbiddenRealType(CTypedefType typedef, string message) {
76+
not typedef.getName().(SizedTypeString).isComplex() and
77+
(
78+
if typedef.getBaseType().stripTopLevelSpecifiers() instanceof ComplexNumberType
79+
then message = "The typedef name " + typedef.getName() + " does not indicate a complex type."
80+
else (
81+
typedef.getSize() * 8 != typedef.getName().(SizedTypeString).getSize() and
82+
message = "The typedef type " + typedef.getName() + " does not have its indicated size."
83+
)
84+
)
85+
}
86+
4187
predicate forbiddenTypedef(CTypedefType typedef, string message) {
4288
/* If the typedef's name contains an explicit size */
4389
(
44-
if typedef.getName().regexpMatch("u?(int|float)(4|8|16|32|64|128)_t")
90+
if typedef.getName() instanceof SizedTypeString
4591
then (
46-
/* Then the actual type size should match. */
47-
not typedef.getSize() * 8 =
48-
// times 8 because getSize() gets the size in bytes
49-
typedef.getName().regexpCapture("u?(int|float)(4|8|16|32|64|128)_t", 2).toInt() and
50-
message = "The typedef type " + typedef.getName() + " does not have its indicated size."
92+
forbiddenRealType(typedef, message)
93+
or
94+
forbiddenComplexType(typedef, message)
5195
) else (
5296
(
5397
// type def is to a built in numeric type
5498
typedef.getBaseType() instanceof BuiltInNumericType and
5599
// but does not include the size in the name
56-
not typedef.getName().regexpMatch("u?(int|float)(4|8|16|32|64|128)_t")
100+
not typedef.getName() instanceof SizedTypeString
57101
or
58102
// this is a typedef to a forbidden type def
59103
forbiddenTypedef(typedef.getBaseType(), _)

0 commit comments

Comments
 (0)