Skip to content

Commit 79d7f21

Browse files
committed
EssentialTypes: Add support for unary logical operations
These should return essentially boolean type
1 parent a989829 commit 79d7f21

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ class EssentialBinaryLogicalOperationExpr extends EssentialExpr, BinaryLogicalOp
179179
override Type getEssentialType() { result instanceof BoolType }
180180
}
181181

182+
class EssentialUnaryLogicalOperationExpr extends EssentialExpr, UnaryLogicalOperation {
183+
override Type getEssentialType() { result instanceof BoolType }
184+
}
185+
182186
class EssentialEqualityOperationExpr extends EssentialExpr, EqualityOperation {
183187
override Type getEssentialType() { result instanceof BoolType }
184188
}

c/misra/test/c/misra/EssentialTypes.expected

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,35 @@
3838
| test.c:26:3:26:3 | f | float | float | essentially Floating type |
3939
| test.c:27:3:27:5 | f32 | float32_t | float32_t | essentially Floating type |
4040
| test.c:28:3:28:6 | cf32 | float | float | essentially Floating type |
41+
| test.c:32:13:32:16 | 1 | bool | bool | essentially Boolean type |
42+
| test.c:32:13:32:16 | (bool)... | bool | bool | essentially Boolean type |
43+
| test.c:33:20:33:20 | 1 | signed char | signed char | essentially Signed type |
44+
| test.c:33:20:33:20 | (unsigned int)... | unsigned int | unsigned int | essentially Unsigned type |
45+
| test.c:34:23:34:23 | 1 | signed char | signed char | essentially Signed type |
46+
| test.c:34:23:34:23 | (unsigned short)... | unsigned short | unsigned short | essentially Unsigned type |
47+
| test.c:35:17:35:18 | 1 | signed char | signed char | essentially Signed type |
48+
| test.c:36:21:36:21 | 1 | signed char | signed char | essentially Signed type |
49+
| test.c:36:21:36:21 | (signed short)... | signed short | signed short | essentially Signed type |
50+
| test.c:38:3:38:4 | ! ... | bool | bool | essentially Boolean type |
51+
| test.c:38:4:38:4 | b | bool | bool | essentially Boolean type |
52+
| test.c:39:3:39:4 | ! ... | bool | bool | essentially Boolean type |
53+
| test.c:39:4:39:4 | u | unsigned int | unsigned int | essentially Unsigned type |
54+
| test.c:40:3:40:5 | ! ... | bool | bool | essentially Boolean type |
55+
| test.c:40:4:40:5 | us | unsigned short | unsigned short | essentially Unsigned type |
56+
| test.c:41:3:41:4 | ! ... | bool | bool | essentially Boolean type |
57+
| test.c:41:4:41:4 | s | signed int | signed int | essentially Signed type |
58+
| test.c:42:3:42:5 | ! ... | bool | bool | essentially Boolean type |
59+
| test.c:42:4:42:5 | ss | signed short | signed short | essentially Signed type |
60+
| test.c:44:3:44:4 | ~ ... | int | int | essentially Signed type |
61+
| test.c:44:4:44:4 | (int)... | int | int | essentially Signed type |
62+
| test.c:44:4:44:4 | b | bool | bool | essentially Boolean type |
63+
| test.c:45:3:45:4 | ~ ... | unsigned int | unsigned int | essentially Unsigned type |
64+
| test.c:45:4:45:4 | u | unsigned int | unsigned int | essentially Unsigned type |
65+
| test.c:46:3:46:5 | ~ ... | unsigned short | unsigned short | essentially Unsigned type |
66+
| test.c:46:4:46:5 | (int)... | int | int | essentially Signed type |
67+
| test.c:46:4:46:5 | us | unsigned short | unsigned short | essentially Unsigned type |
68+
| test.c:47:3:47:4 | ~ ... | signed int | signed int | essentially Signed type |
69+
| test.c:47:4:47:4 | s | signed int | signed int | essentially Signed type |
70+
| test.c:48:3:48:5 | ~ ... | int | int | essentially Signed type |
71+
| test.c:48:4:48:5 | (int)... | int | int | essentially Signed type |
72+
| test.c:48:4:48:5 | ss | signed short | signed short | essentially Signed type |

c/misra/test/c/misra/test.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,24 @@ void testCategoriesForComplexTypes() {
2626
f; // Should be essentially Floating type
2727
f32; // Should be essentially Floating type
2828
cf32; // Should be essentially Floating type
29+
}
30+
31+
void testUnary() {
32+
_Bool b = true;
33+
unsigned int u = 1;
34+
unsigned short us = 1;
35+
signed int s = 1;
36+
signed short ss = 1;
37+
38+
!b; // Should be boolean
39+
!u; // Should be boolean
40+
!us; // Should be boolean
41+
!s; // Should be boolean
42+
!ss; // Should be boolean
43+
44+
~b; // Should be essentially signed
45+
~u; // Should be essentially unsigned
46+
~us; // Should be essentially unsigned
47+
~s; // Should be essentially signed
48+
~ss; // Should be essentially signed
2949
}

0 commit comments

Comments
 (0)