Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EssentialType: Implement correct essential types for bitwise binary operators &, ^ and |. #787

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions c/misra/src/codingstandards/c/misra/EssentialTypes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class EssentialEqualityOperationExpr extends EssentialExpr, EqualityOperation {
override Type getEssentialType() { result instanceof BoolType }
}

class EssentialBinaryBitwiseOperationExpr extends EssentialExpr, BinaryBitwiseOperation {
EssentialBinaryBitwiseOperationExpr() {
class EssentialShiftOperationExpr extends EssentialExpr, BinaryBitwiseOperation {
EssentialShiftOperationExpr() {
this instanceof LShiftExpr or
this instanceof RShiftExpr
}
Expand Down Expand Up @@ -353,6 +353,51 @@ class EssentialBinaryArithmeticExpr extends EssentialExpr, BinaryArithmeticOpera
}
}

class EssentialBinaryBitwiseExpr extends EssentialExpr, BinaryBitwiseOperation {
EssentialBinaryBitwiseExpr() {
not this instanceof LShiftExpr and
not this instanceof RShiftExpr
}

override Type getEssentialType() {
exists(
Type leftEssentialType, Type rightEssentialType,
EssentialTypeCategory leftEssentialTypeCategory,
EssentialTypeCategory rightEssentialTypeCategory
|
leftEssentialType = getEssentialType(getLeftOperand()) and
rightEssentialType = getEssentialType(getRightOperand()) and
leftEssentialTypeCategory = getEssentialTypeCategory(leftEssentialType) and
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType)
|
if
leftEssentialTypeCategory = EssentiallySignedType() and
rightEssentialTypeCategory = EssentiallySignedType()
then
if exists(getValue())
then result = stlr(this)
else (
if leftEssentialType.getSize() > rightEssentialType.getSize()
then result = leftEssentialType
else result = rightEssentialType
)
else
if
leftEssentialTypeCategory = EssentiallyUnsignedType() and
rightEssentialTypeCategory = EssentiallyUnsignedType()
then
if exists(getValue())
then result = utlr(this)
else (
if leftEssentialType.getSize() > rightEssentialType.getSize()
then result = leftEssentialType
else result = rightEssentialType
)
else result = this.getStandardType()
)
}
}

/**
* A named Enum type, as per D.5.
*/
Expand Down
Loading
Loading