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

FP: Misra 6.1 bool bitfields in --std=c11 or later #6128

Merged
merged 2 commits into from
Mar 28, 2024
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ jobs:
# rules 5.4 and 5.5 which have standard-dependent options.
../../cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test.c --std=c89 --platform=unix64
python3 ../misra.py -verify misra/misra-test.c.dump
# Test slight MISRA differences in C11 standard
../../cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test-c11.c --std=c11 --platform=unix64
python3 ../misra.py -verify misra/misra-test-c11.c.dump
danmar marked this conversation as resolved.
Show resolved Hide resolved
# TODO: do we need to verify something here?
../../cppcheck --dump -DDUMMY --suppress=uninitvar --suppress=uninitStructMember --std=c89 misra/misra-test.h
../../cppcheck --dump misra/misra-test.cpp
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ jobs:
rem rules 5.4 and 5.5 which have standard-dependent options.
..\..\cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra\misra-test.c --std=c89 --platform=unix64 || exit /b !errorlevel!
python3 ..\misra.py -verify misra\misra-test.c.dump || exit /b !errorlevel!
rem Test slight MISRA differences in C11 standard
..\..\cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra\misra-test-c11.c --std=c11 --platform=unix64 || exit /b !errorlevel!
python3 ..\misra.py -verify misra\misra-test-c11.c.dump || exit /b !errorlevel!
rem TODO: do we need to verify something here?
..\..\cppcheck --dump -DDUMMY --suppress=uninitvar --suppress=uninitStructMember --std=c89 misra\misra-test.h || exit /b !errorlevel!
..\..\cppcheck --dump misra\misra-test.cpp || exit /b !errorlevel!
Expand Down
2 changes: 1 addition & 1 deletion addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ def misra_6_1(self, data):
if data.standards.c == 'c89':
if token.valueType.type != 'int' and not isUnsignedType(token.variable.typeStartToken.str):
self.reportError(token, 6, 1)
elif data.standards.c == 'c99':
elif data.standards.c in ('c99', 'c11', 'c17', 'c18'):
if token.valueType.type == 'bool':
continue

Expand Down
25 changes: 25 additions & 0 deletions addons/test/misra/misra-test-c11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// To test:
// ~/cppcheck/cppcheck --dump misra/misra-test-c11.c --std=c11
// ~/cppcheck/cppcheck --dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test-c11.c --std=c11 --platform=unix64 && python3 ../misra.py -verify misra/misra-test-c11.c.dump

#include <stdint.h>

typedef unsigned int UINT_TYPEDEF;
struct struct_with_bitfields
{
unsigned int a:2; // Compliant
signed int b:2; // Compliant
UINT_TYPEDEF c:2; // Compliant
int d:2; // 6.1 - plain int not compliant
signed long f:2; // Compliant in c99 or later - explicitly signed integer type
unsigned int g:1; // Compliant
signed int h:1; // 6.2 - signed int with size 1 is not compliant
uint16_t i:1; // Compliant
bool j:1; // Compliant in C99 or later
};

static void misra6_1_fn(void) {
// "Use" occurrence should not generate warnings
struct_with_bitfields s;
s.h = 61;
}
1 change: 1 addition & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ struct struct_with_bitfields
unsigned int g:1; // Compliant
signed int h:1; // 6.2 - signed int with size 1 is not compliant
uint16_t i:1; // Compliant
bool j:1; // 6.1 - bool not legal until c99
};

static void misra6_1_fn(void) {
Expand Down
Loading