Skip to content

Commit ac739c8

Browse files
committed
Fix Autosar tests when compiled with qcc
1 parent 2036ff2 commit ac739c8

File tree

9 files changed

+36
-34
lines changed

9 files changed

+36
-34
lines changed

cpp/autosar/src/rules/A18-1-2/VectorboolSpecializationUsed.ql

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
import cpp
1919
import codingstandards.cpp.autosar
2020

21-
predicate isVectorBool(ClassTemplateInstantiation c) {
22-
(
23-
c.getNamespace() instanceof StdNamespace
21+
class StdNS extends Namespace {
22+
StdNS() {
23+
this instanceof StdNamespace
2424
or
25-
c.getNamespace().isInline() and
26-
c.getNamespace().getParentNamespace() instanceof StdNamespace
27-
) and
25+
this.isInline() and
26+
this.getParentNamespace() instanceof StdNS
27+
}
28+
}
29+
30+
predicate isVectorBool(ClassTemplateInstantiation c) {
31+
c.getNamespace() instanceof StdNS and
2832
c.getTemplateArgument(0) instanceof BoolType and
2933
c.getSimpleName() = "vector"
3034
}

cpp/autosar/test/rules/M0-1-4/SingleUseMemberPODVariable.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
| test.cpp:36:24:36:29 | unused | Member POD variable unused in C1 is only $@. | test.cpp:36:31:36:31 | initializer for unused | used once |
21
| test_global_or_namespace.cpp:16:7:16:7 | x | Member POD variable x in GA is only $@. | test_global_or_namespace.cpp:38:6:38:6 | x | used once |
32
| test_global_or_namespace.cpp:54:7:54:7 | x | Member POD variable x in N1A is only $@. | test_global_or_namespace.cpp:76:6:76:6 | x | used once |
43
| test_member.cpp:5:7:5:8 | m2 | Member POD variable m2 in A is only $@. | test_member.cpp:9:21:9:25 | constructor init of field m2 | used once |

cpp/autosar/test/rules/M0-1-4/test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ void test_templates() {
3333
}
3434

3535
class C1 {
36-
static constexpr int unused{1}; // NON_COMPLIANT
37-
static constexpr int used{2}; // COMPLIANT
36+
static constexpr int used{2}; // COMPLIANT
3837
int test_use() { return used; }
3938
static constexpr int size{3}; // COMPLIANT
4039
std::array<bool, size> array{false, false}; // size is used here

cpp/common/src/codingstandards/cpp/Iterators.qll

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import cpp
66
import semmle.code.cpp.dataflow.DataFlow
77
import semmle.code.cpp.dataflow.TaintTracking
88

9+
class StdNS extends Namespace {
10+
StdNS() {
11+
this instanceof StdNamespace
12+
or
13+
this.isInline() and
14+
this.getParentNamespace() instanceof StdNS
15+
}
16+
}
17+
918
abstract class ContainerAccess extends VariableAccess {
1019
abstract Variable getOwningContainer();
1120
}
@@ -168,11 +177,7 @@ class ContainerInvalidationOperation extends FunctionCall {
168177
]
169178
)
170179
or
171-
exists(FunctionCall fc |
172-
fc.getTarget().getNamespace().getName() = "std" and
173-
fc.getTarget().getName() in ["swap", "operator>>", "getline"] and
174-
this = fc
175-
)
180+
this.getTarget().hasGlobalOrStdName(["swap", "operator>>", "getline"])
176181
)
177182
)
178183
}
@@ -195,7 +200,7 @@ class ContainerInvalidationOperation extends FunctionCall {
195200
/** An iterator type in the `std` namespace. */
196201
class StdIteratorType extends UserType {
197202
StdIteratorType() {
198-
getNamespace().getName() = "std" and
203+
this.getNamespace() instanceof StdNS and
199204
getSimpleName().matches("%_iterator") and
200205
not getSimpleName().matches("const_%")
201206
}
@@ -247,16 +252,11 @@ class AdditiveOperatorFunctionCall extends FunctionCall {
247252
*/
248253
class STLContainer extends Class {
249254
STLContainer() {
250-
getNamespace().getName() = "std" and
251-
getSimpleName() in [
255+
this.hasGlobalOrStdName([
252256
"vector", "list", "deque", "set", "multiset", "map", "multimap", "stack", "queue",
253257
"priority_queue", "string", "forward_list", "unordered_set", "unordered_multiset",
254258
"unordered_map", "unordered_multimap", "valarray", "string", "basic_string"
255-
]
256-
or
257-
getSimpleName() = "string"
258-
or
259-
getSimpleName() = "basic_string"
259+
])
260260
}
261261

262262
/**
@@ -291,7 +291,7 @@ class STLContainer extends Class {
291291
IteratorSource getAConstIteratorEndFunctionCall() { result = getACallTo("cend") }
292292

293293
IteratorSource getANonConstIteratorFunctionCall() {
294-
result = getACallToAFunction() and
294+
//result = this.getACallToAFunction() and
295295
result.getTarget().getType() instanceof NonConstIteratorType
296296
}
297297

@@ -343,24 +343,24 @@ class STLContainerVariable extends Variable {
343343
* to create this functionality.
344344
*/
345345
class IteratorRangeModel extends Function {
346-
IteratorRangeModel() { hasQualifiedName("std", "lexicographical_compare") }
346+
IteratorRangeModel() { this.hasGlobalOrStdName("lexicographical_compare") }
347347

348348
int getAnIndexOfAStartRange() {
349-
(hasQualifiedName("std", "lexicographical_compare") and result = [0, 1])
349+
(this.hasGlobalOrStdName("lexicographical_compare") and result = [0, 1])
350350
}
351351

352352
int getAnIndexOfAEndRange() {
353-
(hasQualifiedName("std", "lexicographical_compare") and result = [2, 3])
353+
(this.hasGlobalOrStdName("lexicographical_compare") and result = [2, 3])
354354
}
355355

356356
int getAnIteratorArgumentIndex() {
357-
(hasQualifiedName("std", "lexicographical_compare") and result = [0, 1, 2, 3])
357+
(this.hasGlobalOrStdName("lexicographical_compare") and result = [0, 1, 2, 3])
358358
}
359359

360360
predicate getAPairOfStartEndIndexes(int start, int end) {
361-
hasQualifiedName("std", "lexicographical_compare") and start = 0 and end = 1
361+
this.hasGlobalOrStdName("lexicographical_compare") and start = 0 and end = 1
362362
or
363-
hasQualifiedName("std", "lexicographical_compare") and start = 2 and end = 3
363+
this.hasGlobalOrStdName("lexicographical_compare") and start = 2 and end = 3
364364
}
365365
}
366366

@@ -378,7 +378,7 @@ class IteratorRangeFunctionCall extends FunctionCall {
378378
count(Expr e |
379379
e = getAnArgument() and
380380
e.getType() instanceof IteratorType and
381-
getTarget().getNamespace().getName() = "std" and
381+
getTarget().getNamespace() instanceof StdNS and
382382
not getTarget().getName() in ["operator==", "operator!="]
383383
) > 1
384384
}

cpp/common/src/codingstandards/cpp/rules/exithandlerthrowsexception/ExitHandlerThrowsException.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ExitHandler extends ExceptionThrowingFunction {
1717
Call c;
1818

1919
ExitHandler() {
20-
c.getTarget().hasQualifiedName("std", ["atexit", "at_quick_exit"]) and
20+
c.getTarget().hasGlobalOrStdName(["atexit", "at_quick_exit"]) and
2121
c.getArgument(0) = this.getAnAccess()
2222
}
2323

cpp/common/src/codingstandards/cpp/standardlibrary/CStdLib.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import cpp
44

55
/** The function `std::quick_exit`. */
66
class StdQuickExit extends Function {
7-
StdQuickExit() { hasQualifiedName("std", "quick_exit") }
7+
StdQuickExit() { this.hasGlobalOrStdName("quick_exit") }
88
}
99

1010
/** The function `std::abort`. */
1111
class StdAbort extends Function {
12-
StdAbort() { hasQualifiedName("std", "abort") }
12+
StdAbort() { this.hasGlobalOrStdName("abort") }
1313
}
1414

1515
/** The function `std::_Exit`. */
1616
class Std_Exit extends Function {
17-
Std_Exit() { hasQualifiedName("std", "_Exit") }
17+
Std_Exit() { this.hasGlobalOrStdName("_Exit") }
1818
}

0 commit comments

Comments
 (0)