Skip to content

Commit a60ef7c

Browse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/implement-rule-amendments-tc2
2 parents 3e6cf77 + 9a1d770 commit a60ef7c

24 files changed

+273
-48
lines changed

amendments.csv

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,Yes,Import
1111
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
3131
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy

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/rules/RULE-11-3/CastBetweenObjectPointerAndDifferentObjectType.ql

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ where
2323
baseTypeFrom = cast.getExpr().getType().(PointerToObjectType).getBaseType() and
2424
baseTypeTo = cast.getType().(PointerToObjectType).getBaseType() and
2525
// exception: cast to a char, signed char, or unsigned char is permitted
26-
not baseTypeTo.stripType() instanceof CharType and
26+
not (
27+
baseTypeTo.stripType() instanceof CharType and
28+
// Exception does not apply to _Atomic types
29+
not baseTypeFrom.hasSpecifier("atomic")
30+
) and
2731
(
2832
(
2933
baseTypeFrom.isVolatile() and not baseTypeTo.isVolatile()

c/misra/src/rules/RULE-11-8/CastRemovesConstOrVolatileQualification.ql

+4
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ where
2424
baseTypeFrom.isVolatile() and not baseTypeTo.isVolatile() and qualificationName = "volatile"
2525
or
2626
baseTypeFrom.isConst() and not baseTypeTo.isConst() and qualificationName = "const"
27+
or
28+
baseTypeFrom.hasSpecifier("atomic") and
29+
not baseTypeTo.hasSpecifier("atomic") and
30+
qualificationName = "atomic"
2731
)
2832
select cast, "Cast of pointer removes " + qualificationName + " qualification from its base type."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* @id c/misra/unsequenced-atomic-reads
3+
* @name RULE-13-2: The value of an atomic variable shall not depend on the evaluation order of interleaved threads
4+
* @description The value of an atomic variable shall not depend on evaluation order and
5+
* interleaving of threads.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-13-2
10+
* correctness
11+
* external/misra/c/2012/amendment3
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import semmle.code.cpp.dataflow.TaintTracking
17+
import codingstandards.c.misra
18+
import codingstandards.c.Ordering
19+
import codingstandards.c.orderofevaluation.VariableAccessOrdering
20+
21+
class AtomicAccessInFullExpressionOrdering extends Ordering::Configuration {
22+
AtomicAccessInFullExpressionOrdering() { this = "AtomicAccessInFullExpressionOrdering" }
23+
24+
override predicate isCandidate(Expr e1, Expr e2) {
25+
exists(AtomicVariableAccess a, AtomicVariableAccess b, FullExpr e | a = e1 and b = e2 |
26+
a.getTarget() = b.getTarget() and
27+
a.(ConstituentExpr).getFullExpr() = e and
28+
b.(ConstituentExpr).getFullExpr() = e and
29+
not a = b
30+
)
31+
}
32+
}
33+
34+
/**
35+
* A read of a variable specified as `_Atomic`.
36+
*
37+
* Note, it may be accessed directly, or by passing its address into the std atomic functions.
38+
*/
39+
class AtomicVariableAccess extends VariableAccess {
40+
AtomicVariableAccess() { getTarget().getType().hasSpecifier("atomic") }
41+
42+
/* Get the `atomic_<read|write>()` call this VarAccess occurs in. */
43+
FunctionCall getAtomicFunctionCall() {
44+
exists(AddressOfExpr addrParent, FunctionCall fc |
45+
fc.getTarget().getName().matches("__c11_atomic%") and
46+
addrParent = fc.getArgument(0) and
47+
addrParent.getAnOperand() = this and
48+
result = fc
49+
)
50+
}
51+
52+
/**
53+
* Gets an assigned expr, either in the form `x = <result>` or `atomic_store(&x, <result>)`.
54+
*/
55+
Expr getAnAssignedExpr() {
56+
result = getAtomicFunctionCall().getArgument(1)
57+
or
58+
exists(AssignExpr assign |
59+
assign.getLValue() = this and
60+
result = assign.getRValue()
61+
)
62+
}
63+
64+
/**
65+
* Gets the expression holding this variable access, either in the form `x` or `atomic_read(&x)`.
66+
*/
67+
Expr getARead() {
68+
result = getAtomicFunctionCall()
69+
or
70+
result = this
71+
}
72+
}
73+
74+
from
75+
AtomicAccessInFullExpressionOrdering config, FullExpr e, Variable v, AtomicVariableAccess va1,
76+
AtomicVariableAccess va2
77+
where
78+
not isExcluded(e, SideEffects3Package::unsequencedAtomicReadsQuery()) and
79+
e = va1.(ConstituentExpr).getFullExpr() and
80+
config.isUnsequenced(va1, va2) and
81+
v = va1.getTarget() and
82+
v = va2.getTarget() and
83+
// Exclude cases where the variable is assigned a value tainted by the other variable access.
84+
not exists(Expr write |
85+
write = va1.getAnAssignedExpr() and
86+
TaintTracking::localTaint(DataFlow::exprNode(va2.getARead()), DataFlow::exprNode(write))
87+
) and
88+
// Impose an ordering, show the first access.
89+
va1.getLocation().isBefore(va2.getLocation(), _)
90+
select e, "Atomic variable $@ has a $@ that is unsequenced with $@.", v, v.getName(), va1,
91+
"previous read", va2, "another read"

c/misra/src/rules/RULE-3-1/CharacterSequencesAndUsedWithinAComment.ql

+22-11
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,38 @@
1616
import cpp
1717
import codingstandards.c.misra
1818

19-
class IllegalCCommentCharacter extends string {
20-
IllegalCCommentCharacter() {
21-
this = "/*" or
22-
this = "//"
23-
}
19+
/* Character sequence is banned from all comment types */
20+
class IllegalCommentSequence extends string {
21+
IllegalCommentSequence() { this = "/*" }
2422
}
2523

26-
class IllegalCPPCommentCharacter extends string {
27-
IllegalCPPCommentCharacter() { this = "/*" }
24+
/* A regexp to check for illegal C-style comments */
25+
class IllegalCCommentRegexp extends string {
26+
IllegalCCommentRegexp() {
27+
// Regexp to match "//" in C-style comments, which do not appear to be URLs. General format
28+
// uses negative lookahead/lookbehind to match like `.*(?<!HTTP:)//(?!GITHUB.).*`. Broken down
29+
// into parts:
30+
// - `.*PATTERN.*` - look for the pattern anywhere in the comment.
31+
// - `(?<![a-zA-Z]:)` - negative lookbehind, exclude "http://github.com" by seeing "p:".
32+
// - `//` - the actual illegal sequence.
33+
// - `(?!(pattern))` - negative lookahead, exclude "http://github.com" by seeing "github.".
34+
// - `[a-zA-Z0-9\\-]+\\\\.` - Assume alphanumeric/hyphen followed by '.' is a domain name.
35+
this = ".*(?<![a-zA-Z]:)//(?![a-zA-Z0-9\\-]+\\\\.).*"
36+
}
37+
38+
string getDescription() { result = "//" }
2839
}
2940

3041
from Comment comment, string illegalSequence
3142
where
3243
not isExcluded(comment, SyntaxPackage::characterSequencesAndUsedWithinACommentQuery()) and
3344
(
34-
exists(IllegalCCommentCharacter c | illegalSequence = c |
35-
comment.(CStyleComment).getContents().indexOf(illegalSequence) > 0
45+
exists(IllegalCommentSequence c | illegalSequence = c |
46+
comment.getContents().indexOf(illegalSequence) > 1
3647
)
3748
or
38-
exists(IllegalCPPCommentCharacter c | illegalSequence = c |
39-
comment.(CppStyleComment).getContents().indexOf(illegalSequence) > 0
49+
exists(IllegalCCommentRegexp c | illegalSequence = c.getDescription() |
50+
comment.(CStyleComment).getContents().regexpMatch(c)
4051
)
4152
)
4253
select comment, "Comment contains an illegal sequence '" + illegalSequence + "'"

c/misra/test/rules/RULE-11-3/CastBetweenObjectPointerAndDifferentObjectType.expected

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
| test.c:21:3:21:16 | (int *)... | Cast performed between a pointer to object type (char) and a pointer to a different object type (int). |
77
| test.c:22:20:22:21 | (int *)... | Cast performed between a pointer to object type (char) and a pointer to a different object type (int). |
88
| test.c:23:3:23:18 | (long long *)... | Cast performed between a pointer to object type (int) and a pointer to a different object type (long long). |
9+
| test.c:26:3:26:13 | (char *)... | Cast performed between a pointer to object type (_Atomic(int)) and a pointer to a different object type (char). |
10+
| test.c:27:8:27:10 | (char *)... | Cast performed between a pointer to object type (_Atomic(int)) and a pointer to a different object type (char). |
11+
| test.c:28:3:28:21 | (_Atomic(char) *)... | Cast performed between a pointer to object type (_Atomic(int)) and a pointer to a different object type (_Atomic(char)). |
12+
| test.c:29:23:29:25 | (_Atomic(char) *)... | Cast performed between a pointer to object type (_Atomic(int)) and a pointer to a different object type (_Atomic(char)). |

c/misra/test/rules/RULE-11-3/test.c

+6
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ void f1(void) {
2121
(int *const)v2; // NON_COMPLIANT
2222
int *const v10 = v2; // NON_COMPLIANT
2323
(long long *)v10; // NON_COMPLIANT
24+
25+
_Atomic int *v11 = 0;
26+
(char *)v11; // NON_COMPLIANT
27+
v2 = v11; // NON_COMPLIANT
28+
(_Atomic char *)v11; // NON_COMPLIANT
29+
_Atomic char *v12 = v11; // NON_COMPLIANT
2430
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
| test.c:4:19:4:33 | (const char *)... | Cast of pointer removes volatile qualification from its base type. |
22
| test.c:6:13:6:21 | (char *)... | Cast of pointer removes const qualification from its base type. |
3+
| test.c:9:3:9:11 | (char *)... | Cast of pointer removes atomic qualification from its base type. |
4+
| test.c:10:7:10:7 | (char *)... | Cast of pointer removes atomic qualification from its base type. |
5+
| test.c:11:3:11:17 | (const char *)... | Cast of pointer removes atomic qualification from its base type. |
6+
| test.c:12:7:12:7 | (const char *)... | Cast of pointer removes atomic qualification from its base type. |

c/misra/test/rules/RULE-11-8/test.c

+7
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@ int f1(void) {
55
const char *c2 = (const char *)c; // COMPLIANT
66
char *d = (char *)c; // NON_COMPLIANT
77
const char *e = (const char *)d; // COMPLIANT
8+
_Atomic char *f = 0;
9+
(char *)f; // NON_COMPLIANT
10+
d = f; // NON_COMPLIANT
11+
(const char *)f; // NON_COMPLIANT
12+
e = f; // NON_COMPLIANT
13+
(const _Atomic char *)f; // COMPLIANT
14+
(const _Atomic char *)f; // COMPLIANT
815
return 0;
916
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (UnsequencedAtomicReads.ql:86,31-39)
2+
WARNING: module 'DataFlow' has been deprecated and may be removed in future (UnsequencedAtomicReads.ql:86,67-75)
3+
WARNING: module 'TaintTracking' has been deprecated and may be removed in future (UnsequencedAtomicReads.ql:86,5-18)
4+
| test.c:44:12:44:18 | ... + ... | Atomic variable $@ has a $@ that is unsequenced with $@. | test.c:42:15:42:16 | a1 | a1 | test.c:44:12:44:13 | a1 | previous read | test.c:44:17:44:18 | a1 | another read |
5+
| test.c:46:3:46:37 | ... + ... | Atomic variable $@ has a $@ that is unsequenced with $@. | test.c:42:15:42:16 | a1 | a1 | test.c:46:16:46:17 | a1 | previous read | test.c:46:35:46:36 | a1 | another read |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-13-2/UnsequencedAtomicReads.ql
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| test.c:6:12:6:18 | ... + ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:6:12:6:13 | l1 | side effect | test.c:6:12:6:13 | l1 | l1 | test.c:6:17:6:18 | l1 | side effect | test.c:6:17:6:18 | l1 | l1 |
2-
| test.c:7:12:7:18 | ... + ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:7:12:7:13 | l1 | side effect | test.c:7:12:7:13 | l1 | l1 | test.c:7:17:7:18 | l2 | side effect | test.c:7:17:7:18 | l2 | l2 |
3-
| test.c:17:3:17:21 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:17:8:17:9 | l1 | side effect | test.c:17:8:17:9 | l1 | l1 | test.c:17:13:17:14 | l1 | side effect | test.c:17:13:17:14 | l1 | l1 |
4-
| test.c:19:3:19:5 | call to foo | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:19:7:19:8 | l1 | side effect | test.c:19:7:19:8 | l1 | l1 | test.c:19:11:19:12 | l2 | side effect | test.c:19:11:19:12 | l2 | l2 |
5-
| test.c:25:3:25:5 | call to foo | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:25:7:25:10 | ... ++ | side effect | test.c:25:7:25:8 | l8 | l8 | test.c:25:13:25:14 | l8 | read | test.c:25:13:25:14 | l8 | l8 |
6-
| test.c:35:5:35:13 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:35:10:35:12 | ... ++ | side effect | test.c:35:10:35:10 | i | i | test.c:35:10:35:12 | ... ++ | side effect | test.c:35:10:35:10 | i | i |
1+
| test.c:8:12:8:18 | ... + ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:8:12:8:13 | l1 | side effect | test.c:8:12:8:13 | l1 | l1 | test.c:8:17:8:18 | l1 | side effect | test.c:8:17:8:18 | l1 | l1 |
2+
| test.c:9:12:9:18 | ... + ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:9:12:9:13 | l1 | side effect | test.c:9:12:9:13 | l1 | l1 | test.c:9:17:9:18 | l2 | side effect | test.c:9:17:9:18 | l2 | l2 |
3+
| test.c:19:3:19:21 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:19:8:19:9 | l1 | side effect | test.c:19:8:19:9 | l1 | l1 | test.c:19:13:19:14 | l1 | side effect | test.c:19:13:19:14 | l1 | l1 |
4+
| test.c:21:3:21:5 | call to foo | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:21:7:21:8 | l1 | side effect | test.c:21:7:21:8 | l1 | l1 | test.c:21:11:21:12 | l2 | side effect | test.c:21:11:21:12 | l2 | l2 |
5+
| test.c:27:3:27:5 | call to foo | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:27:7:27:10 | ... ++ | side effect | test.c:27:7:27:8 | l8 | l8 | test.c:27:13:27:14 | l8 | read | test.c:27:13:27:14 | l8 | l8 |
6+
| test.c:37:5:37:13 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:37:10:37:12 | ... ++ | side effect | test.c:37:10:37:10 | i | i | test.c:37:10:37:12 | ... ++ | side effect | test.c:37:10:37:10 | i | i |

c/misra/test/rules/RULE-13-2/test.c

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdatomic.h>
2+
13
void foo(int, int);
24

35
void unsequenced_sideeffects1() {
@@ -34,4 +36,15 @@ void unsequenced_sideeffects2() {
3436
for (i = 0; i < 10; i++) {
3537
test(i++); // NON_COMPLIANT
3638
}
39+
}
40+
41+
void atomics() {
42+
_Atomic int a1, a2;
43+
int l3 = a1 + a2; // COMPLIANT
44+
int l4 = a1 + a1; // NON_COMPLIANT
45+
a1 = a1 + 1; // COMPLIANT
46+
atomic_load(&a1) + atomic_load(&a1); // NON_COMPLIANT
47+
atomic_load(&a1) + atomic_load(&a2); // COMPLIANT
48+
atomic_store(&a1, atomic_load(&a1)); // COMPLIANT
49+
atomic_store(&a1, a1); // COMPLIANT
3750
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
| test.c:9:1:9:8 | /* /* */ | Comment contains an illegal sequence '/*' |
22
| test.c:12:1:12:8 | /* // */ | Comment contains an illegal sequence '//' |
33
| test.c:21:1:21:7 | // /* | Comment contains an illegal sequence '/*' |
4+
| test.c:30:1:30:27 | /* https://github.com // */ | Comment contains an illegal sequence '//' |
5+
| test.c:33:1:33:60 | /* a://b, a://b., ://a.b, a://b., a://.b, ://, a://, ://b */ | Comment contains an illegal sequence '//' |
6+
| test.c:42:1:42:8 | ///* foo | Comment contains an illegal sequence '/*' |

c/misra/test/rules/RULE-3-1/test.c

+21
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,25 @@
2020
// NON_COMPLIANT
2121
// /*
2222

23+
// COMPLIANT
24+
/* https://github.com */
25+
26+
// COMPLIANT
27+
/* https://name-with-hyphen-and-num-12345.com */
28+
29+
// NON_COMPLIANT
30+
/* https://github.com // */
31+
32+
// NON_COMPLIANT
33+
/* a://b, a://b., ://a.b, a://b., a://.b, ://, a://, ://b */
34+
35+
// COMPLIANT
36+
// https://github.com
37+
38+
// COMPLIANT
39+
//* foo
40+
41+
// NON_COMPLIANT
42+
///* foo
43+
2344
void f(){}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- `RULE-11-3` - `CastBetweenObjectPointerAndDifferentObjectType.ql`
2+
- Constrain exception that pointer types to may be cast to char types, so that it does not apply to atomic pointer types, in compliance with MISRA-C 2012 Amendment 4.
3+
- `RULE-11-8` - `CastRemovesConstOrVolatileQualification.ql`
4+
- Query expanded to detect cases of removing `_Atomic` qualification, in compliance with MISRA-C 2012 Amendment 4.
5+
- `EXP33-C`, `RULE-9-1`, `A8-5-0`, `EXP53-CPP` - `DoNotReadUninitializedMemory.ql`, `ObjectWithAutoStorageDurationReadBeforeInit.ql`, `MemoryNotInitializedBeforeItIsRead.ql`, `DoNotReadUninitializedMemory.ql`
6+
- Atomic local variables excluded from query results, in compliance with MISRA-C 2012 Amendment 4, and to reduce false positives in the other standards.
7+
- `RULE-13-2` - `UnsequencedAtomicReads.ql`
8+
- New query to find expressions which read an atomic variable more than once between sequence points, to address new case from MISRA-C 2012 Amendment 4.
9+
- `RULE-3-1` - `CharacterSequencesAndUsedWithinAComment.ql`
10+
- Add exception allowing URLs inside of cpp-style `/* ... */` comments, in compliance with MISRA-C 2012 Amendment 4.
11+
- No longer report cases of `//*some comment` in this rule.

cpp/autosar/src/codingstandards/cpp/HardwareOrProtocolInterface.qll

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import codingstandards.cpp.CommonTypes as CommonTypes
33

44
abstract class HardwareOrProtocolInterfaceClass extends Class { }
55

6+
class HardwareOrProtocolInterfaceComment extends Comment {
7+
HardwareOrProtocolInterfaceComment() {
8+
exists(getContents().regexpFind("(?m)^\\s*(//|\\*)\\s*@HardwareOrProtocolInterface\\s*$", _, _))
9+
}
10+
}
11+
612
class AnnotatedHardwareOrProtocolInterfaceClass extends HardwareOrProtocolInterfaceClass {
713
AnnotatedHardwareOrProtocolInterfaceClass() {
8-
exists(Comment c, string contents |
9-
c.getCommentedElement() = this.getADeclarationEntry() and
10-
contents =
11-
c.getContents()
12-
.splitAt("\n")
13-
.regexpFind("^\\s*(//|\\*)\\s*@HardwareOrProtocolInterface\\s*$", _, _)
14+
exists(HardwareOrProtocolInterfaceComment c |
15+
c.getCommentedElement() = this.getADeclarationEntry()
1416
)
1517
}
1618
}

cpp/autosar/src/rules/A2-3-1/InvalidCharacterInComment.ql

+13-11
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@
1818
import cpp
1919
import codingstandards.cpp.autosar
2020

21-
bindingset[s]
22-
string getCharOutsideBasicSourceCharSet(string s) {
23-
result = s.regexpFind("[\\u0000-\\u007f]", _, _) and
24-
not result.regexpMatch("[\\p{Alnum}\\p{Space}_{}\\[\\]#()<>%:;.?*+-/^&|~!=,\\\\\"'@]")
25-
or
26-
result = s.regexpFind("[\\u00c0-\\u00df][\\u0080-\\u00bf]", _, _)
27-
or
28-
result = s.regexpFind("[\\u00e0-\\u00ef][\\u0080-\\u00bf]{2}", _, _)
29-
or
30-
result = s.regexpFind("[\\u00f0-\\u00f7][\\u0080-\\u00bf]{3}", _, _)
21+
string getCharOutsideBasicSourceCharSet(Comment c) {
22+
exists(string s | s = c.getContents() |
23+
result =
24+
s.regexpFind("(?![\\p{Alnum}\\p{Space}_{}\\[\\]#()<>%:;.?*+-/^&|~!=,\\\\\"'@])[\\u0000-\\u007f]",
25+
_, _)
26+
or
27+
result = s.regexpFind("[\\u00c0-\\u00df][\\u0080-\\u00bf]", _, _)
28+
or
29+
result = s.regexpFind("[\\u00e0-\\u00ef][\\u0080-\\u00bf]{2}", _, _)
30+
or
31+
result = s.regexpFind("[\\u00f0-\\u00f7][\\u0080-\\u00bf]{3}", _, _)
32+
)
3133
}
3234

3335
from Comment c, string ch
3436
where
3537
not isExcluded(c, NamingPackage::invalidCharacterInCommentQuery()) and
36-
ch = getCharOutsideBasicSourceCharSet(c.getContents())
38+
ch = getCharOutsideBasicSourceCharSet(c)
3739
select c,
3840
"Comment uses the character '" + ch + "' that is outside the language basic character set."

0 commit comments

Comments
 (0)