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

Merged
merged 15 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
lcartey marked this conversation as resolved.
Show resolved Hide resolved
}

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
lcartey marked this conversation as resolved.
Show resolved Hide resolved
leftEssentialTypeCategory = EssentiallySignedType() and
rightEssentialTypeCategory = EssentiallySignedType()
then
if exists(getValue())
then result = stlr(this)
else (
if leftEssentialType.getSize() > rightEssentialType.getSize()
lcartey marked this conversation as resolved.
Show resolved Hide resolved
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