Skip to content

Commit e7b9b67

Browse files
committed
RULE-7-0-4: exclude insertion operator
1 parent e489771 commit e7b9b67

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

change_notes/2026-04-25-fix-performance-inappropriate-bitwise-or-shift-operands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
- Improved evaluation performance.
33
- `RULE-7-0-4` - `InappropriateBitwiseOrShiftOperands.ql`:
44
- Improved evaluation performance.
5+
- Remove false positives related to the `insertion operator`.

cpp/misra/src/rules/RULE-7-0-4/InappropriateBitwiseOrShiftOperands.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ predicate isConstantExpression(Expr e) {
2424

2525
bindingset[right, leftType]
2626
pragma[inline_late]
27-
predicate isValidShiftConstantRange(Expr right, Type leftType) {
27+
predicate isValidShiftConstantRange(Expr right, MisraCpp23BuiltInTypes::NumericType leftType) {
2828
exists(int value |
2929
value = right.getValue().toInt() and
3030
value >= 0 and
31-
value < leftType.getSize() * 8
31+
value < leftType.getBuiltInSize() * 8
3232
)
3333
}
3434

@@ -99,7 +99,10 @@ where
9999
)
100100
or
101101
// Shift operators - right operand must be unsigned or constant in valid range
102-
exists(BinaryShiftOpOrAssignOp shift, Expr right, Type rightType, Type leftType |
102+
exists(
103+
BinaryShiftOpOrAssignOp shift, Expr right, Type rightType,
104+
MisraCpp23BuiltInTypes::NumericType leftType
105+
|
103106
right = shift.getRightOperand() and
104107
x = right and
105108
rightType = right.getExplicitlyConverted().getType() and
@@ -110,7 +113,7 @@ where
110113
not isValidShiftConstantRange(right, leftType) and
111114
message =
112115
"Shift operator '" + shift.getOperator() + "' shifts by " + right.getValue().toInt() +
113-
" which is not within the valid range 0.." + ((leftType.getSize() * 8) - 1) + "."
116+
" which is not within the valid range 0.." + ((leftType.getBuiltInSize() * 8) - 1) + "."
114117
else (
115118
not MisraCpp23BuiltInTypes::isUnsignedType(rightType) and
116119
message =

0 commit comments

Comments
 (0)