Skip to content

Commit 1e6f7dd

Browse files
authored
Merge branch 'github:main' into Contracts5
2 parents 973e074 + c9eb8d0 commit 1e6f7dd

File tree

54 files changed

+756
-54
lines changed

Some content is hidden

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

54 files changed

+756
-54
lines changed

.github/pull_request_template.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ _**Author:**_ Is a change note required?
3232
- [ ] Yes
3333
- [ ] No
3434

35+
🚨🚨🚨
36+
_**Reviewer:**_ Confirm that format of *shared* queries (not the .qll file, the
37+
.ql file that imports it) is valid by running them within VS Code.
38+
- [ ] Confirmed
39+
40+
3541
_**Reviewer:**_ Confirm that either a change note is not required or the change note is required and has been added.
3642
- [ ] Confirmed
3743

.vscode/tasks.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
"Declarations",
207207
"Declarations1",
208208
"Declarations2",
209+
"Declarations3",
210+
"Declarations4",
209211
"Exceptions1",
210212
"Exceptions2",
211213
"Expressions",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.c:1:5:1:6 | definition of g1 | The identifier g1 has external linkage and is redefined $@. | test1.c:1:5:1:6 | definition of g1 | here |
2+
| test.c:6:6:6:7 | definition of f2 | The identifier f2 has external linkage and is redefined $@. | test1.c:6:6:6:7 | definition of f2 | here |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.identifierwithexternallinkageonedefinitionshared.IdentifierWithExternalLinkageOneDefinitionShared
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int g1 = 1; // NON_COMPLIANT
2+
static int g2 = 1; // COMPLIANT; internal linkage
3+
4+
inline void f1() {} // COMPLIANT; inline functions are an exception
5+
6+
void f2() {} // NON_COMPLIANT
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int g1 = 0; // NON_COMPLIANT
2+
static int g2 = 1; // COMPLIANT; internal linkage
3+
4+
inline void f1() {} // COMPLIANT; inline functions are an exception
5+
6+
void f2() {} // NON_COMPLIANT

c/misra/src/rules/RULE-5-5/IdentifiersNotDistinctFromMacroNames.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import cpp
1616
import codingstandards.c.misra
17-
import codingstandards.c.Identifiers
17+
import codingstandards.cpp.Identifiers
1818

1919
from Macro m, InterestingIdentifiers i, string mName, string iName
2020
where

c/misra/src/rules/RULE-5-6/TypedefNameNotUnique.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import cpp
1616
import codingstandards.c.misra
17-
import codingstandards.c.Identifiers
17+
import codingstandards.cpp.Identifiers
1818

1919
from TypedefType t, InterestingIdentifiers d
2020
where

c/misra/src/rules/RULE-5-7/TagNameNotUnique.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import cpp
1616
import codingstandards.c.misra
17-
import codingstandards.c.Identifiers
17+
import codingstandards.cpp.Identifiers
1818

1919
from Struct s, InterestingIdentifiers s2
2020
where
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @id c/misra/function-types-not-in-prototype-form
3+
* @name RULE-8-2: Function types shall be in prototype form with named parameters
4+
* @description Omission of parameter types or names prevents the compiler from doing type checking
5+
* when those functions are used and therefore may result in undefined behaviour.
6+
* @kind problem
7+
* @precision medium
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-8-2
10+
* correctness
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.Identifiers
17+
18+
/**
19+
* `Parameter`s without names
20+
*/
21+
class UnnamedParameter extends Parameter {
22+
UnnamedParameter() { not this.isNamed() }
23+
}
24+
25+
/*
26+
* This is a copy of the private `hasZeroParamDecl` predicate from the standard set of
27+
* queries as of the `codeql-cli/2.11.2` tag in `github/codeql`.
28+
*/
29+
30+
predicate hasZeroParamDecl(Function f) {
31+
exists(FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() |
32+
not fde.isImplicit() and
33+
not fde.hasVoidParamList() and
34+
fde.getNumberOfParameters() = 0 and
35+
not fde.isDefinition()
36+
)
37+
}
38+
39+
from Function f, string msg
40+
where
41+
not isExcluded(f, Declarations4Package::functionTypesNotInPrototypeFormQuery()) and
42+
f instanceof InterestingIdentifiers and
43+
(
44+
f.getAParameter() instanceof UnnamedParameter and
45+
msg = "Function " + f + " declares parameter that is unnamed."
46+
or
47+
hasZeroParamDecl(f) and
48+
msg = "Function " + f + " does not specifiy void for no parameters present."
49+
or
50+
//parameters declared in declaration list (not in function signature)
51+
//have placeholder file location associated only
52+
exists(Parameter p |
53+
p.getFunction() = f and
54+
not p.getFile() = f.getFile() and
55+
msg = "Function " + f + " declares parameter in unsupported declaration list."
56+
)
57+
)
58+
select f, msg

0 commit comments

Comments
 (0)