-
Notifications
You must be signed in to change notification settings - Fork 66
Add support for implementation specific bitfield types #564
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a9d71bb
Add support for implementation specific bitfield types
rvermeulen f1c4dac
Merge branch 'main' into rvermeulen/fix-rule-6-1
rvermeulen 4dc49a1
Address incorrect format code elements in alert message
rvermeulen b87fec5
Add test case with atomic types for documentation
rvermeulen 645d4e9
Merge branch 'main' into rvermeulen/fix-rule-6-1
knewbury01 570dd80
Properly format the test case
rvermeulen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
c/misra/test/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
| test.c:6:7:6:8 | x1 | Bit-field x1 is declared on type int. | | ||
| test.c:10:15:10:16 | x5 | Bit-field x5 is declared on type signed long. | | ||
| test.c:12:15:12:16 | x6 | Bit-field x6 is declared on type signed char. | | ||
| test.c:14:14:14:15 | x7 | Bit-field x7 is declared on type Color. | | ||
| test.c:14:14:14:15 | x7 | Bit-field x7 is declared on type Color. | |
Empty file.
1 change: 1 addition & 0 deletions
1
c/misra/test/rules/RULE-6-1/clang/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
semmle-extractor-options:--mimic clang --std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
typedef unsigned int UINT16; | ||
|
||
enum Color { R, G, B }; | ||
|
||
struct SampleStruct { | ||
int x1 : 2; // COMPLIANT | ||
unsigned int x2 : 2; // COMPLIANT - explicitly unsigned | ||
signed int x3 : 2; // COMPLIANT - explicitly signed | ||
UINT16 x4 : 2; // COMPLIANT - type alias resolves to a compliant type | ||
signed long x5 : 2; // COMPLIANT | ||
signed char x6 : 2; // COMPLIANT | ||
enum Color x7 : 3; // COMPLIANT | ||
} sample_struct; |
Empty file.
1 change: 1 addition & 0 deletions
1
c/misra/test/rules/RULE-6-1/gcc/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
semmle-extractor-options:--mimic gcc --std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
typedef unsigned int UINT16; | ||
|
||
enum Color { R, G, B }; | ||
|
||
struct SampleStruct { | ||
int x1 : 2; // COMPLIANT | ||
unsigned int x2 : 2; // COMPLIANT - explicitly unsigned | ||
signed int x3 : 2; // COMPLIANT - explicitly signed | ||
UINT16 x4 : 2; // COMPLIANT - type alias resolves to a compliant type | ||
signed long x5 : 2; // COMPLIANT | ||
signed char x6 : 2; // COMPLIANT | ||
enum Color x7 : 3; // COMPLIANT | ||
} sample_struct; | ||
rvermeulen marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
semmle-extractor-options:--no-clang --std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `RULE-6-1` - `BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql`: | ||
- Address FP reported in #318. Add support for implementation specific bitfield types for Clang and Gcc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** A module to reason about the compiler used to compile translation units. */ | ||
|
||
import cpp | ||
import codingstandards.cpp.Scope | ||
|
||
newtype Compiler = | ||
Gcc() or | ||
Clang() or | ||
UnsupportedCompiler() | ||
|
||
/** Get the match pattern to detect the compiler being mimicked by the extractor to determine the compiler used to compile a file. */ | ||
string getMimicMatch(Compiler compiler) { | ||
result = ["%gcc", "%g++"] and compiler instanceof Gcc | ||
or | ||
result = ["%clang", "%clang++"] and compiler instanceof Clang | ||
} | ||
|
||
/** Get the compiler used to compile the translation unit the file `f` is part of. */ | ||
Compiler getCompiler(File f) { | ||
exists(Compilation compilation, TranslationUnit translationUnit | | ||
compilation.getAFileCompiled() = translationUnit and | ||
(f = translationUnit or f = translationUnit.getAUserFile()) | ||
| | ||
if exists(int mimicIndex | compilation.getArgument(mimicIndex) = "--mimic") | ||
then | ||
exists(int mimicIndex | | ||
compilation.getArgument(mimicIndex) = "--mimic" and | ||
( | ||
compilation.getArgument(mimicIndex + 1).matches(getMimicMatch(result)) | ||
or | ||
forall(string match | match = getMimicMatch(_) | | ||
not compilation.getArgument(mimicIndex + 1).matches(match) | ||
) and | ||
result = UnsupportedCompiler() | ||
) | ||
) | ||
else result = UnsupportedCompiler() | ||
) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.