-
Notifications
You must be signed in to change notification settings - Fork 67
Language 2 #128
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
Language 2 #128
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
422b00b
language2
jsinglet 833f719
Language2: add test RULE-1-4
knewbury01 33867bb
Language2: rm DIR-2-1
knewbury01 8ec3b83
checkpoint
jsinglet a1df6d4
Merge pull request #112 from knewbury01/knewbury01/Language2
jsinglet 308ee91
Merge remote-tracking branch 'upstream/language2' into jsinglet/langu…
jsinglet 0358f6e
extractor
jsinglet bd1b68c
Merge remote-tracking branch 'origin/jsinglet/rule-fix-dir-1-2' into …
jsinglet ca41ed6
refactor query
jsinglet d91613b
refactor
jsinglet a894b13
refactor
jsinglet 524cf0b
refactor
jsinglet b63c28f
import
jsinglet e31b26c
fixing rules
jsinglet 8080bc3
headers
jsinglet bee4cff
remove rule
jsinglet 38439e3
adding 1-4
jsinglet 3d14f97
emergent
jsinglet 0c6aecf
work
jsinglet 92356eb
removal
jsinglet c6b41b3
package surgery
jsinglet f2a9dcb
Merge branch 'main' into jsinglet/language2
jsinglet b144d5c
formatting
jsinglet b7e7ee6
Merge remote-tracking branch 'origin/jsinglet/language2' into jsingle…
jsinglet cb9596c
removed identical test case
jsinglet 501ecef
fix
jsinglet 0c9c40a
warning
jsinglet c48658f
adding back
jsinglet 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,7 @@ | |
"Iterators", | ||
"Lambdas", | ||
"Language1", | ||
"Language2", | ||
"Literals", | ||
"Loops", | ||
"Macros", | ||
|
22 changes: 22 additions & 0 deletions
22
c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.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,22 @@ | ||
/** | ||
* @id c/misra/usage-of-assembly-language-should-be-documented | ||
* @name DIR-4-2: All usage of assembly language should be documented | ||
* @description Assembly language is not portable and should be documented. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity warning | ||
* @tags external/misra/id/dir-4-2 | ||
* maintainability | ||
* readability | ||
* external/misra/obligation/advisory | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented | ||
|
||
class UsageOfAssemblyLanguageShouldBeDocumentedQuery extends UsageOfAssemblerNotDocumentedSharedQuery { | ||
UsageOfAssemblyLanguageShouldBeDocumentedQuery() { | ||
this = Language2Package::usageOfAssemblyLanguageShouldBeDocumentedQuery() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.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,21 @@ | ||
/** | ||
* @id c/misra/emergent-language-features-used | ||
* @name RULE-1-4: Emergent language features shall not be used | ||
* @description Emergent language features may have unpredictable behavior and should not be used. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity warning | ||
* @tags external/misra/id/rule-1-4 | ||
* maintainability | ||
* readability | ||
* external/misra/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.c.misra | ||
import codingstandards.cpp.Emergent | ||
|
||
from C11::EmergentLanguageFeature ef | ||
where not isExcluded(ef, Language2Package::emergentLanguageFeaturesUsedQuery()) | ||
select ef, "Usage of emergent language feature." | ||
|
1 change: 1 addition & 0 deletions
1
c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref
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 @@ | ||
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql |
15 changes: 15 additions & 0 deletions
15
c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
| test.c:1:1:1:21 | #include <stdalign.h> | Usage of emergent language feature. | | ||
| test.c:2:1:2:22 | #include <stdatomic.h> | Usage of emergent language feature. | | ||
| test.c:3:1:3:24 | #include <stdnoreturn.h> | Usage of emergent language feature. | | ||
| test.c:4:1:4:20 | #include <threads.h> | Usage of emergent language feature. | | ||
| test.c:6:1:6:49 | #define MACRO(x) _Generic((x), int : 0, long : 1) | Usage of emergent language feature. | | ||
| test.c:7:1:7:32 | #define __STDC_WANT_LIB_EXT1__ 1 | Usage of emergent language feature. | | ||
| test.c:9:16:9:17 | f0 | Usage of emergent language feature. | | ||
| test.c:12:26:12:40 | atomic_new_type | Usage of emergent language feature. | | ||
| test.c:17:15:17:15 | i | Usage of emergent language feature. | | ||
| test.c:19:3:19:10 | alignas(...) | Usage of emergent language feature. | | ||
| test.c:20:3:20:9 | alignas(...) | Usage of emergent language feature. | | ||
| test.c:21:11:21:23 | alignof(int) | Usage of emergent language feature. | | ||
| test.c:22:12:22:23 | alignof(int) | Usage of emergent language feature. | | ||
| test.c:24:27:24:28 | i3 | Usage of emergent language feature. | | ||
| test.c:25:28:25:29 | i4 | Usage of emergent language feature. | |
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-1-4/EmergentLanguageFeaturesUsed.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,26 @@ | ||
#include <stdalign.h> //NON_COMPLIANT | ||
#include <stdatomic.h> //NON_COMPLIANT | ||
#include <stdnoreturn.h> //NON_COMPLIANT | ||
#include <threads.h> //NON_COMPLIANT | ||
|
||
#define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT | ||
#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT | ||
|
||
_Noreturn void f0(); // NON_COMPLIANT | ||
|
||
typedef int new_type; // COMPLIANT | ||
typedef _Atomic new_type atomic_new_type; // NON_COMPLIANT | ||
|
||
void f(int p) { | ||
int i0 = _Generic(p, int : 0, long : 1); // NON_COMPLIANT[FALSE_NEGATIVE] | ||
|
||
_Atomic int i; // NON_COMPLIANT | ||
|
||
_Alignas(4) int i1; // NON_COMPLIANT | ||
alignas(4) int i2; // NON_COMPLIANT | ||
int a = _Alignof(int); // NON_COMPLIANT | ||
int a1 = alignof(int); // NON_COMPLIANT | ||
|
||
static thread_local int i3; // NON_COMPLIANT | ||
static _Thread_local int i4; // NON_COMPLIANT | ||
} |
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
1 change: 0 additions & 1 deletion
1
cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.qlref
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.testref
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 @@ | ||
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.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,49 @@ | ||
import cpp | ||
|
||
/** | ||
* Namespace for containing emergent language features in C11. | ||
*/ | ||
module C11 { | ||
abstract class EmergentLanguageFeature extends Element { } | ||
|
||
class AlignAsAttribute extends EmergentLanguageFeature, Attribute { | ||
AlignAsAttribute() { getName() = "_Alignas" } | ||
} | ||
|
||
class AtomicVariableSpecifier extends EmergentLanguageFeature, Variable { | ||
AtomicVariableSpecifier() { | ||
getType().(DerivedType).getBaseType*().getASpecifier().getName() = "atomic" | ||
} | ||
} | ||
|
||
class AtomicDeclaration extends EmergentLanguageFeature, Declaration { | ||
AtomicDeclaration() { getASpecifier().getName() = "atomic" } | ||
} | ||
|
||
class ThreadLocalDeclaration extends EmergentLanguageFeature, Declaration { | ||
ThreadLocalDeclaration() { getASpecifier().getName() = "is_thread_local" } | ||
} | ||
|
||
class EmergentHeader extends EmergentLanguageFeature, Include { | ||
EmergentHeader() { | ||
getIncludedFile().getBaseName() = ["stdalign.h", "stdatomic.h", "stdnoreturn.h", "threads.h"] | ||
} | ||
} | ||
|
||
class LibExt1Macro extends EmergentLanguageFeature, Macro { | ||
LibExt1Macro() { | ||
getName() = "__STDC_WANT_LIB_EXT1__" and | ||
getBody() = "1" | ||
} | ||
} | ||
|
||
class GenericMacro extends EmergentLanguageFeature, Macro { | ||
GenericMacro() { getBody().indexOf("_Generic") = 0 } | ||
} | ||
|
||
class NoReturnSpecificer extends EmergentLanguageFeature, Function { | ||
NoReturnSpecificer() { getASpecifier().getName() = "noreturn" } | ||
} | ||
|
||
class AlignOf extends EmergentLanguageFeature, AlignofTypeOperator { } | ||
} |
42 changes: 42 additions & 0 deletions
42
cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll
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,42 @@ | ||
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ | ||
import cpp | ||
import RuleMetadata | ||
import codingstandards.cpp.exclusions.RuleMetadata | ||
|
||
newtype Language2Query = | ||
TUsageOfAssemblyLanguageShouldBeDocumentedQuery() or | ||
TEmergentLanguageFeaturesUsedQuery() | ||
|
||
predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { | ||
query = | ||
// `Query` instance for the `usageOfAssemblyLanguageShouldBeDocumented` query | ||
Language2Package::usageOfAssemblyLanguageShouldBeDocumentedQuery() and | ||
queryId = | ||
// `@id` for the `usageOfAssemblyLanguageShouldBeDocumented` query | ||
"c/misra/usage-of-assembly-language-should-be-documented" and | ||
ruleId = "DIR-4-2" | ||
or | ||
query = | ||
// `Query` instance for the `emergentLanguageFeaturesUsed` query | ||
Language2Package::emergentLanguageFeaturesUsedQuery() and | ||
queryId = | ||
// `@id` for the `emergentLanguageFeaturesUsed` query | ||
"c/misra/emergent-language-features-used" and | ||
ruleId = "RULE-1-4" | ||
} | ||
|
||
module Language2Package { | ||
Query usageOfAssemblyLanguageShouldBeDocumentedQuery() { | ||
//autogenerate `Query` type | ||
result = | ||
// `Query` type for `usageOfAssemblyLanguageShouldBeDocumented` query | ||
TQueryC(TLanguage2PackageQuery(TUsageOfAssemblyLanguageShouldBeDocumentedQuery())) | ||
} | ||
|
||
Query emergentLanguageFeaturesUsedQuery() { | ||
//autogenerate `Query` type | ||
result = | ||
// `Query` type for `emergentLanguageFeaturesUsed` query | ||
TQueryC(TLanguage2PackageQuery(TEmergentLanguageFeaturesUsedQuery())) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...codingstandards/cpp/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.qll
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,19 @@ | ||
/** | ||
* Provides a library which includes a `problems` predicate for reporting | ||
* undocumented uses of assembly. | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.cpp.Customizations | ||
import codingstandards.cpp.Exclusions | ||
|
||
abstract class UsageOfAssemblerNotDocumentedSharedQuery extends Query { } | ||
|
||
Query getQuery() { result instanceof UsageOfAssemblerNotDocumentedSharedQuery } | ||
|
||
query predicate problems(AsmStmt a, string message) { | ||
not isExcluded(a, getQuery()) and | ||
not exists(Comment c | c.getCommentedElement() = a) and | ||
not a.isAffectedByMacro() and | ||
message = "Use of assembler is not documented." | ||
} |
1 change: 1 addition & 0 deletions
1
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
| test.cpp:8:42:8:58 | asm statement | Use of assembler is not documented. | |
2 changes: 2 additions & 0 deletions
2
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.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,2 @@ | ||
// GENERATED FILE - DO NOT MODIFY | ||
import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented |
12 changes: 12 additions & 0 deletions
12
cpp/common/test/rules/usageofassemblernotdocumented/test.cpp
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,12 @@ | ||
// COMPLIANT | ||
void test_assembly_is_documented() { | ||
// This comment serves as documentation | ||
__asm__("ret\n"); | ||
} | ||
|
||
// NON_COMPLIANT | ||
void test_assembly_is_not_documented() { __asm__("ret\n"); } | ||
|
||
// COMPLIANT | ||
#define RETURN __asm__("ret\n") | ||
void test_undocumented_assembly_from_macro() { RETURN; } |
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,45 @@ | ||
{ | ||
"MISRA-C-2012": { | ||
"DIR-4-2": { | ||
"properties": { | ||
"obligation": "advisory" | ||
}, | ||
"queries": [ | ||
{ | ||
"description": "Assembly language is not portable and should be documented.", | ||
"kind": "problem", | ||
"name": "All usage of assembly language should be documented", | ||
"precision": "very-high", | ||
"severity": "warning", | ||
"short_name": "UsageOfAssemblyLanguageShouldBeDocumented", | ||
"shared_implementation_short_name": "UsageOfAssemblerNotDocumented", | ||
"tags": [ | ||
"maintainability", | ||
"readability" | ||
] | ||
} | ||
], | ||
"title": "All usage of assembly language should be documented" | ||
}, | ||
"RULE-1-4": { | ||
"properties": { | ||
"obligation": "required" | ||
}, | ||
"queries": [ | ||
{ | ||
"description": "Emergent language features may have unpredictable behavior and should not be used.", | ||
"kind": "problem", | ||
"name": "Emergent language features shall not be used", | ||
"precision": "very-high", | ||
"severity": "warning", | ||
"short_name": "EmergentLanguageFeaturesUsed", | ||
"tags": [ | ||
"maintainability", | ||
"readability" | ||
] | ||
} | ||
], | ||
"title": "Emergent language features shall not be used" | ||
} | ||
} | ||
} |
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
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
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.