Skip to content

Commit f7cd25e

Browse files
committed
BuiltInTypeRules: Handle bit fields in switch cases
1 parent bc7bf51 commit f7cd25e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cpp/misra/src/codingstandards/cpp/misra/BuiltInTypeRules.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,16 @@ predicate isPreConversionAssignment(Expr source, Type targetType, string context
243243
exists(SwitchCase case, SwitchStmt switch |
244244
case.getExpr() = source and
245245
case.getSwitchStmt() = switch and
246-
targetType = switch.getExpr().getFullyConverted().getType() and
247246
context = "switch case"
247+
|
248+
if switch.getExpr().(FieldAccess).getTarget() instanceof BitField
249+
then
250+
// For the MISRA type rules we treat bit fields as a special case
251+
targetType = getBitFieldType(switch.getExpr().(FieldAccess).getTarget())
252+
else
253+
// Regular variable initialization
254+
// Get the type of the switch expression, which is the type of the case expression
255+
targetType = switch.getExpr().getFullyConverted().getType()
248256
)
249257
or
250258
// Class aggregate literal initialization

0 commit comments

Comments
 (0)