Skip to content

Commit ebc07fe

Browse files
committed
EssentialTypes: Handle typedefs
When computing EssentialTypeCategories, ensure we resolve any typedefs first.
1 parent 2d70f7b commit ebc07fe

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

c/misra/src/codingstandards/c/misra/EssentialTypes.qll

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,32 @@ private IntegralType stlr(Expr const) {
7474
}
7575

7676
/**
77-
* Define the essential type category for an IntegralOrEnumType.
77+
* Define the essential type category for an essentialType or a typedef of an essentialType.
7878
*/
79-
EssentialTypeCategory getEssentialTypeCategory(Type at) {
80-
result = EssentiallyBooleanType() and at instanceof MisraBoolType
81-
or
82-
result = EssentiallyCharacterType() and at instanceof PlainCharType
83-
or
84-
result = EssentiallySignedType() and
85-
at.(IntegralType).isSigned() and
86-
not at instanceof PlainCharType
87-
or
88-
result = EssentiallyUnsignedType() and
89-
at.(IntegralType).isUnsigned() and
90-
not at instanceof PlainCharType
91-
or
92-
result = EssentiallyEnumType() and at instanceof Enum and not at instanceof MisraBoolType
93-
or
94-
result = EssentiallyFloatingType() and
95-
at instanceof FloatingPointType
79+
EssentialTypeCategory getEssentialTypeCategory(Type type) {
80+
exists(Type essentialType |
81+
// Resolve typedefs to ensure
82+
essentialType = type.getUnderlyingType()
83+
|
84+
result = EssentiallyBooleanType() and essentialType instanceof MisraBoolType
85+
or
86+
result = EssentiallyCharacterType() and essentialType instanceof PlainCharType
87+
or
88+
result = EssentiallySignedType() and
89+
essentialType.(IntegralType).isSigned() and
90+
not essentialType instanceof PlainCharType
91+
or
92+
result = EssentiallyUnsignedType() and
93+
essentialType.(IntegralType).isUnsigned() and
94+
not essentialType instanceof PlainCharType
95+
or
96+
result = EssentiallyEnumType() and
97+
essentialType instanceof Enum and
98+
not essentialType instanceof MisraBoolType
99+
or
100+
result = EssentiallyFloatingType() and
101+
essentialType instanceof FloatingPointType
102+
)
96103
}
97104

98105
/**

0 commit comments

Comments
 (0)