Skip to content

Commit

Permalink
M5-0-3: Consider static casts to be cvalues, as per spec
Browse files Browse the repository at this point in the history
  • Loading branch information
lcartey committed Nov 27, 2024
1 parent a183198 commit b8d399e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
| test.cpp:12:8:12:14 | ... + ... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:12:8:12:14 | ... + ... | expression |
| test.cpp:14:8:14:13 | ... + ... | Implicit conversion converts cvalue $@ from signed short to signed int. | test.cpp:14:8:14:13 | ... + ... | expression |
| test.cpp:23:13:23:19 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:23:13:23:19 | ... + ... | expression |
| test.cpp:30:12:30:18 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:30:12:30:18 | ... + ... | expression |
| test.cpp:25:13:25:45 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:25:13:25:45 | static_cast<int8_t>... | expression |
| test.cpp:31:12:31:18 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:31:12:31:18 | ... + ... | expression |
| test.cpp:33:12:33:44 | (int16_t)... | Implicit conversion converts cvalue $@ from signed char to signed short. | test.cpp:33:12:33:44 | static_cast<int8_t>... | expression |
3 changes: 3 additions & 0 deletions cpp/autosar/test/rules/M5-0-3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ void test_func_call() {
std::int8_t l1;
int16_arg(l1 + l1); // NON_COMPLIANT
int16_arg(static_cast<std::int16_t>(l1 + l1)); // COMPLIANT
int16_arg(static_cast<std::int8_t>(l1 + l1)); // NON_COMPLIANT
}

std::int16_t test_return(int test) {
std::int8_t l1;
if (test > 0) {
return l1 + l1; // NON_COMPLIANT
} else if (test < 0) {
return static_cast<std::int8_t>(l1 + l1); // NON_COMPLIANT
} else {
return static_cast<std::int16_t>(l1 + l1); // COMPLIANT
}
Expand Down
12 changes: 2 additions & 10 deletions cpp/common/src/codingstandards/cpp/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,9 @@ module MisraExpr {
private predicate isCValue(Expr e) {
not e.isConstant() and
(
exists(ReturnStmt return |
e = return.getExpr() and
// Only return statements which are not explicitly casted are considered
not exists(Cast c | not c.isImplicit() and c.getExpr() = e)
)
exists(ReturnStmt return | e = return.getExpr().getExplicitlyConverted())
or
exists(FunctionCall call |
e = call.getAnArgument() and
// // Only function arguments which are not explicitly casted are considered
not exists(Cast c | not c.isImplicit() and c.getExpr() = e)
)
exists(FunctionCall call | e = call.getAnArgument().getExplicitlyConverted())
)
or
isCValue(e.(ParenthesisExpr).getExpr())
Expand Down

0 comments on commit b8d399e

Please sign in to comment.