Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5f54152

Browse filesBrowse files
authored
Merge branch 'main' into release-automation/bump-version-to-2.27.0-dev
2 parents 74b4b8e + 177293e commit 5f54152
Copy full SHA for 5f54152
Expand file treeCollapse file tree

25 files changed

+279
-54
lines changed

‎.github/workflows/finalize-release.yml

Copy file name to clipboardExpand all lines: .github/workflows/finalize-release.yml
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ jobs:
109109
git switch main
110110
git pull --ff-only origin main
111111
112-
git switch -c release-automation/bump-version
112+
git switch -c "release-automation/bump-version-to-$NEXT_VERSION"
113113
114114
# We are running the script in the tooling directory with the release directory as the working directory
115115
../tooling/scripts/release/bump-version.sh "$NEXT_VERSION"
116116
117117
git add -u .
118118
git commit -m "Bump version to $NEXT_VERSION"
119-
git push --set-upstream origin release-automation/bump-version
119+
git push --set-upstream origin "release-automation/bump-version-to-$NEXT_VERSION"
120120
121-
gh pr create --repo $GITHUB_REPOSITORY --base main --head release-automation/bump-version --body "Bump the version of main to $NEXT_VERSION" --title "Bump version to $NEXT_VERSION"
121+
gh pr create --repo $GITHUB_REPOSITORY --base main --head "release-automation/bump-version-to-$NEXT_VERSION" --body "Bump the version of main to $NEXT_VERSION" --title "Bump version to $NEXT_VERSION"
122122
working-directory: release

‎c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql

Copy file name to clipboardExpand all lines: c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql
+19-8Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,33 @@
1212

1313
import cpp
1414
import codingstandards.c.misra
15+
import codingstandards.cpp.Compiler
1516

16-
predicate isAppropriatePrimitive(Type type) {
17-
/* An appropriate primitive types to which a bit-field can be declared. */
18-
type instanceof IntType and
17+
Type getSupportedBitFieldType(Compiler compiler) {
18+
compiler instanceof UnsupportedCompiler and
1919
(
20-
type.(IntegralType).isExplicitlySigned() or
21-
type.(IntegralType).isExplicitlyUnsigned()
20+
result instanceof IntType and
21+
(
22+
result.(IntegralType).isExplicitlySigned() or
23+
result.(IntegralType).isExplicitlyUnsigned()
24+
)
25+
or
26+
result instanceof BoolType
2227
)
2328
or
24-
type instanceof BoolType
29+
(compiler instanceof Gcc or compiler instanceof Clang) and
30+
(
31+
result instanceof IntegralOrEnumType
32+
or
33+
result instanceof BoolType
34+
)
2535
}
2636

2737
from BitField bitField
2838
where
2939
not isExcluded(bitField,
3040
BitfieldTypesPackage::bitFieldsShallOnlyBeDeclaredWithAnAppropriateTypeQuery()) and
3141
/* A violation would neither be an appropriate primitive type nor an appropriate typedef. */
32-
not isAppropriatePrimitive(bitField.getType().resolveTypedefs())
33-
select bitField, "Bit-field " + bitField + " is declared on type " + bitField.getType() + "."
42+
not getSupportedBitFieldType(getCompiler(bitField.getFile())) =
43+
bitField.getType().resolveTypedefs()
44+
select bitField, "Bit-field '" + bitField + "' is declared on type '" + bitField.getType() + "'."
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| test.c:6:7:6:8 | x1 | Bit-field x1 is declared on type int. |
2-
| test.c:10:15:10:16 | x5 | Bit-field x5 is declared on type signed long. |
3-
| test.c:12:15:12:16 | x6 | Bit-field x6 is declared on type signed char. |
4-
| test.c:14:14:14:15 | x7 | Bit-field x7 is declared on type Color. |
1+
| test.c:6:7:6:8 | x1 | Bit-field 'x1' is declared on type 'int'. |
2+
| test.c:10:15:10:16 | x5 | Bit-field 'x5' is declared on type 'signed long'. |
3+
| test.c:12:15:12:16 | x6 | Bit-field 'x6' is declared on type 'signed char'. |
4+
| test.c:14:14:14:15 | x7 | Bit-field 'x7' is declared on type 'Color'. |

‎c/misra/test/rules/RULE-6-1/clang/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.expected

Copy file name to clipboardExpand all lines: c/misra/test/rules/RULE-6-1/clang/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.expected
Whitespace-only changes.
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options:--mimic clang --std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
typedef unsigned int UINT16;
2+
3+
enum Color { R, G, B };
4+
5+
struct SampleStruct {
6+
int x1 : 2; // COMPLIANT
7+
unsigned int x2 : 2; // COMPLIANT - explicitly unsigned
8+
signed int x3 : 2; // COMPLIANT - explicitly signed
9+
UINT16 x4 : 2; // COMPLIANT - type alias resolves to a compliant type
10+
signed long x5 : 2; // COMPLIANT
11+
signed char x6 : 2; // COMPLIANT
12+
enum Color x7 : 3; // COMPLIANT
13+
//_Atomic(int) x8 : 2; // NON_COMPLIANT[COMPILER_CHECKED] - atomic types are
14+
// not permitted for bit-fields.
15+
} sample_struct;

‎c/misra/test/rules/RULE-6-1/gcc/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.expected

Copy file name to clipboardExpand all lines: c/misra/test/rules/RULE-6-1/gcc/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.expected
Whitespace-only changes.
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options:--mimic gcc --std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
typedef unsigned int UINT16;
2+
3+
enum Color { R, G, B };
4+
5+
struct SampleStruct {
6+
int x1 : 2; // COMPLIANT
7+
unsigned int x2 : 2; // COMPLIANT - explicitly unsigned
8+
signed int x3 : 2; // COMPLIANT - explicitly signed
9+
UINT16 x4 : 2; // COMPLIANT - type alias resolves to a compliant type
10+
signed long x5 : 2; // COMPLIANT
11+
signed char x6 : 2; // COMPLIANT
12+
enum Color x7 : 3; // COMPLIANT
13+
//_Atomic(int) x8 : 2; // NON_COMPLIANT[COMPILER_CHECKED] - atomic types are
14+
// not permitted for bit-fields.
15+
} sample_struct;

‎c/misra/test/rules/RULE-6-1/options

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options:--no-clang --std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A3-3-1` - `ExternalLinkageNotDeclaredInHeaderFile.ql`:
2+
- Adjust the alert message to comply with the style guide.
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `CTR55-CPP` - `DoNotUseAnAdditiveOperatorOnAnIterator.ql`:
2+
- Address reported FP in #374. Improve logic on valid end checks and size checks on iterators.
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `RULE-6-1` - `BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql`:
2+
- Address FP reported in #318. Add support for implementation specific bitfield types for Clang and Gcc.

‎cpp/autosar/src/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.ql

Copy file name to clipboardExpand all lines: cpp/autosar/src/rules/A3-3-1/ExternalLinkageNotDeclaredInHeaderFile.ql
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ where
3838
// Main functions are an exception to the rule
3939
not de.getDeclaration() instanceof MainFunction and
4040
if de.getDeclaration() instanceof Function then kind = "function" else kind = "object"
41-
select de, "Externally linked " + kind + " " + de.getName() + " not declared in header file."
41+
select de, "Externally linked " + kind + " '" + de.getName() + "' not declared in header file."
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| test.cpp:3:5:3:6 | definition of g1 | Externally linked object g1 not declared in header file. |
2-
| test.cpp:4:12:4:13 | declaration of g2 | Externally linked object g2 not declared in header file. |
3-
| test.cpp:10:5:10:6 | definition of l1 | Externally linked object l1 not declared in header file. |
4-
| test.cpp:11:6:11:7 | definition of f1 | Externally linked function f1 not declared in header file. |
5-
| test.cpp:22:5:22:5 | definition of f | Externally linked function f not declared in header file. |
6-
| test.cpp:25:5:25:6 | declaration of f1 | Externally linked function f1 not declared in header file. |
1+
| test.cpp:3:5:3:6 | definition of g1 | Externally linked object 'g1' not declared in header file. |
2+
| test.cpp:4:12:4:13 | declaration of g2 | Externally linked object 'g2' not declared in header file. |
3+
| test.cpp:10:5:10:6 | definition of l1 | Externally linked object 'l1' not declared in header file. |
4+
| test.cpp:11:6:11:7 | definition of f1 | Externally linked function 'f1' not declared in header file. |
5+
| test.cpp:22:5:22:5 | definition of f | Externally linked function 'f' not declared in header file. |
6+
| test.cpp:25:5:25:6 | declaration of f1 | Externally linked function 'f1' not declared in header file. |

‎cpp/autosar/test/rules/A3-3-1/test.cpp

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A3-3-1/test.cpp
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ namespace n {
3535
void f5() { // COMPLIANT
3636
int i = 0;
3737
}
38-
} // namespace n
38+
} // namespace n
39+
40+
const int c = 1; // COMPLIANT - internal linkage
41+
const char *const str2 = "foo"; // COMPLIANT - internal linkage
42+
constexpr int k = 1; // COMPLIANT - internal linkage

‎cpp/cert/src/rules/CTR52-CPP/GuaranteeGenericCppLibraryFunctionsDoNotOverflow.ql

Copy file name to clipboardExpand all lines: cpp/cert/src/rules/CTR52-CPP/GuaranteeGenericCppLibraryFunctionsDoNotOverflow.ql
+1-10Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,7 @@ where
8080
iteratorCreationCall = outputContainer.getAnIteratorFunctionCall() and
8181
iteratorCreationCall = c.getOutputIteratorSource()
8282
|
83-
// Guarded by a bounds check that ensures our destination is larger than "some" value
84-
exists(
85-
GuardCondition guard, ContainerAccessWithoutRangeCheck::ContainerSizeCall sizeCall,
86-
boolean branch
87-
|
88-
globalValueNumber(sizeCall.getQualifier()) =
89-
globalValueNumber(iteratorCreationCall.getQualifier()) and
90-
guard.controls(c.getBasicBlock(), branch) and
91-
relOpWithSwapAndNegate(guard, sizeCall, _, Greater(), _, branch)
92-
)
83+
sizeCompareBoundsChecked(iteratorCreationCall, c)
9384
or
9485
// Container created with sufficient size for the input
9586
exists(ContainerAccessWithoutRangeCheck::ContainerConstructorCall outputIteratorConstructor |

‎cpp/cert/src/rules/CTR55-CPP/DoNotUseAnAdditiveOperatorOnAnIterator.ql

Copy file name to clipboardExpand all lines: cpp/cert/src/rules/CTR55-CPP/DoNotUseAnAdditiveOperatorOnAnIterator.ql
+72-15Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,81 @@
1414
import cpp
1515
import codingstandards.cpp.cert
1616
import codingstandards.cpp.Iterators
17+
import semmle.code.cpp.controlflow.Dominance
1718

18-
from ContainerIteratorAccess it
19+
/**
20+
* Models a call to an iterator's `operator+`
21+
*/
22+
class AdditionOperatorFunctionCall extends AdditiveOperatorFunctionCall {
23+
AdditionOperatorFunctionCall() { this.getTarget().hasName("operator+") }
24+
}
25+
26+
/**
27+
* There exists a calculation for the reference one passed the end of some container
28+
* An example derivation is:
29+
* `end = begin() + size()`
30+
*/
31+
Expr getDerivedReferenceToOnePassedTheEndElement(Expr containerReference) {
32+
exists(
33+
ContainerAccessWithoutRangeCheck::ContainerSizeCall size,
34+
ContainerAccessWithoutRangeCheck::ContainerBeginCall begin, AdditionOperatorFunctionCall calc
35+
|
36+
result = calc
37+
|
38+
DataFlow::localFlow(DataFlow::exprNode(size), DataFlow::exprNode(calc.getAChild+())) and
39+
DataFlow::localFlow(DataFlow::exprNode(begin), DataFlow::exprNode(calc.getAChild+())) and
40+
//make sure its the same container providing its size as giving the begin
41+
globalValueNumber(begin.getQualifier()) = globalValueNumber(size.getQualifier()) and
42+
containerReference = begin.getQualifier()
43+
)
44+
}
45+
46+
/**
47+
* a wrapper predicate for a couple of types of permitted end bounds checks
48+
*/
49+
Expr getReferenceToOnePassedTheEndElement(Expr containerReference) {
50+
//a container end access - v.end()
51+
result instanceof ContainerAccessWithoutRangeCheck::ContainerEndCall and
52+
containerReference = result.(FunctionCall).getQualifier()
53+
or
54+
result = getDerivedReferenceToOnePassedTheEndElement(containerReference)
55+
}
56+
57+
/**
58+
* some guard exists like: `iterator != end`
59+
* where a relevant`.end()` call flowed into end
60+
*/
61+
predicate isUpperBoundEndCheckedIteratorAccess(IteratorSource source, ContainerIteratorAccess it) {
62+
exists(
63+
Expr referenceToOnePassedTheEndElement, BasicBlock basicBlockOfIteratorAccess,
64+
GuardCondition upperBoundCheck, ContainerIteratorAccess checkedIteratorAccess,
65+
Expr containerReferenceFromEndGuard
66+
|
67+
//sufficient end guard
68+
referenceToOnePassedTheEndElement =
69+
getReferenceToOnePassedTheEndElement(containerReferenceFromEndGuard) and
70+
//guard controls the access
71+
upperBoundCheck.controls(basicBlockOfIteratorAccess, _) and
72+
basicBlockOfIteratorAccess.contains(it) and
73+
//guard is comprised of end check and an iterator access
74+
DataFlow::localFlow(DataFlow::exprNode(referenceToOnePassedTheEndElement),
75+
DataFlow::exprNode(upperBoundCheck.getChild(_))) and
76+
upperBoundCheck.getChild(_) = checkedIteratorAccess and
77+
//make sure its the same iterator being checked in the guard as accessed
78+
checkedIteratorAccess.getOwningContainer() = it.getOwningContainer() and
79+
//if its the end call itself (or its parts), make sure its the same container providing its end as giving the iterator
80+
globalValueNumber(containerReferenceFromEndGuard) = globalValueNumber(source.getQualifier()) and
81+
// and the guard call we match must be after the assignment call (to avoid valid guards protecting new iterator accesses further down)
82+
source.getASuccessor*() = upperBoundCheck
83+
)
84+
}
85+
86+
from ContainerIteratorAccess it, IteratorSource source
1987
where
2088
not isExcluded(it, IteratorsPackage::doNotUseAnAdditiveOperatorOnAnIteratorQuery()) and
2189
it.isAdditiveOperation() and
2290
not exists(RangeBasedForStmt fs | fs.getUpdate().getAChild*() = it) and
23-
// we get the neraby assignment
24-
not exists(STLContainer c, FunctionCall nearbyAssigningIteratorCall, FunctionCall guardCall |
25-
nearbyAssigningIteratorCall = it.getANearbyAssigningIteratorCall() and
26-
// we look for calls to size or end
27-
(guardCall = c.getACallToSize() or guardCall = c.getAnIteratorEndFunctionCall()) and
28-
// such that the call to size is before this
29-
// access
30-
guardCall = it.getAPredecessor*() and
31-
// and it uses the same qualifier as the one we were just assigned
32-
nearbyAssigningIteratorCall.getQualifier().(VariableAccess).getTarget() =
33-
guardCall.getQualifier().(VariableAccess).getTarget() and
34-
// and the size call we match must be after the assignment call
35-
nearbyAssigningIteratorCall.getASuccessor*() = guardCall
36-
)
91+
source = it.getANearbyAssigningIteratorCall() and
92+
not isUpperBoundEndCheckedIteratorAccess(source, it) and
93+
not sizeCompareBoundsChecked(source, it)
3794
select it, "Increment of iterator may overflow since its bounds are not checked."
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
| test.cpp:8:7:8:7 | i | Increment of iterator may overflow since its bounds are not checked. |
22
| test.cpp:9:9:9:9 | i | Increment of iterator may overflow since its bounds are not checked. |
33
| test.cpp:10:9:10:9 | i | Increment of iterator may overflow since its bounds are not checked. |
4-
| test.cpp:27:31:27:31 | i | Increment of iterator may overflow since its bounds are not checked. |
4+
| test.cpp:22:18:22:18 | i | Increment of iterator may overflow since its bounds are not checked. |
5+
| test.cpp:28:31:28:31 | i | Increment of iterator may overflow since its bounds are not checked. |
6+
| test.cpp:41:5:41:8 | end2 | Increment of iterator may overflow since its bounds are not checked. |
7+
| test.cpp:53:42:53:42 | i | Increment of iterator may overflow since its bounds are not checked. |
8+
| test.cpp:64:15:64:15 | i | Increment of iterator may overflow since its bounds are not checked. |

‎cpp/cert/test/rules/CTR55-CPP/test.cpp

Copy file name to clipboardExpand all lines: cpp/cert/test/rules/CTR55-CPP/test.cpp
+39-2Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,47 @@ void f1(std::vector<int> &v) {
2020
}
2121
for (auto i = v.begin(),
2222
l = (i + std::min(static_cast<std::vector<int>::size_type>(10),
23-
v.size()));
24-
i != l; ++i) { // COMPLIANT
23+
v.size())); // NON_COMPLIANT - technically in the
24+
// calculation
25+
i != l; ++i) { // COMPLIANT
2526
}
2627

2728
for (auto i = v.begin();; ++i) { // NON_COMPLIANT
2829
}
30+
}
31+
32+
void test_fp_reported_in_374(std::vector<int> &v) {
33+
{
34+
auto end = v.end();
35+
for (auto i = v.begin(); i != end; ++i) { // COMPLIANT
36+
}
37+
}
38+
39+
{
40+
auto end2 = v.end();
41+
end2++; // NON_COMPLIANT
42+
for (auto i = v.begin(); i != end2;
43+
++i) { // NON_COMPLIANT[FALSE_NEGATIVE] - case of invalidations to
44+
// check before use expected to be less frequent, can model in
45+
// future if need be
46+
}
47+
}
48+
}
49+
50+
void test(std::vector<int> &v, std::vector<int> &v2) {
51+
{
52+
auto end = v2.end();
53+
for (auto i = v.begin(); i != end; ++i) { // NON_COMPLIANT - wrong check
54+
}
55+
}
56+
}
57+
58+
void test2(std::vector<int> &v) {
59+
auto i = v.begin();
60+
while (1) {
61+
auto i2 = ((i != v.end()) != 0);
62+
if (!i2)
63+
break;
64+
(void)((++i)); // COMPLIANT[FALSE_POSITIVE]
65+
}
2966
}
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/** A module to reason about the compiler used to compile translation units. */
2+
3+
import cpp
4+
import codingstandards.cpp.Scope
5+
6+
newtype Compiler =
7+
Gcc() or
8+
Clang() or
9+
UnsupportedCompiler()
10+
11+
/** Get the match pattern to detect the compiler being mimicked by the extractor to determine the compiler used to compile a file. */
12+
string getMimicMatch(Compiler compiler) {
13+
result = ["%gcc", "%g++"] and compiler instanceof Gcc
14+
or
15+
result = ["%clang", "%clang++"] and compiler instanceof Clang
16+
}
17+
18+
/** Get the compiler used to compile the translation unit the file `f` is part of. */
19+
Compiler getCompiler(File f) {
20+
exists(Compilation compilation, TranslationUnit translationUnit |
21+
compilation.getAFileCompiled() = translationUnit and
22+
(f = translationUnit or f = translationUnit.getAUserFile())
23+
|
24+
if exists(int mimicIndex | compilation.getArgument(mimicIndex) = "--mimic")
25+
then
26+
exists(int mimicIndex |
27+
compilation.getArgument(mimicIndex) = "--mimic" and
28+
(
29+
compilation.getArgument(mimicIndex + 1).matches(getMimicMatch(result))
30+
or
31+
forall(string match | match = getMimicMatch(_) |
32+
not compilation.getArgument(mimicIndex + 1).matches(match)
33+
) and
34+
result = UnsupportedCompiler()
35+
)
36+
)
37+
else result = UnsupportedCompiler()
38+
)
39+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.