From 422b00b929f92a0bdf48c614974ed0c5b9280884 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Mon, 31 Oct 2022 16:30:34 -0400 Subject: [PATCH 01/23] language2 --- rules.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules.csv b/rules.csv index ec8b29eaf9..8cd7a19ed4 100644 --- a/rules.csv +++ b/rules.csv @@ -617,7 +617,7 @@ c,MISRA-C-2012,RULE-4-12,Yes,Required,,,Dynamic memory allocation shall not be u c,MISRA-C-2012,RULE-4-13,Yes,Advisory,,,Functions which are designed to provide operations on a resource should be called in an appropriate sequence,,Contracts,Hard, c,MISRA-C-2012,RULE-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, c,MISRA-C-2012,RULE-1-1,Yes,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation�s translation limits",,Language,Easy, -c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language,Easy, +c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language2,Hard, c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language,Hard, c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language,Medium, c,MISRA-C-2012,RULE-2-1,Yes,Required,,,A project shall not contain unreachable code,M0-1-1,DeadCode,Import, From 833f719971739076b2403edc877e6b4c54ac30e8 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Mon, 31 Oct 2022 17:37:42 -0400 Subject: [PATCH 02/23] Language2: add test RULE-1-4 --- c/misra/test/rules/RULE-1-4/test.c | 26 ++++++++++++++++++++++++++ c/misra/test/rules/RULE-1-4/test1.c | 1 + rules.csv | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 c/misra/test/rules/RULE-1-4/test.c create mode 100644 c/misra/test/rules/RULE-1-4/test1.c diff --git a/c/misra/test/rules/RULE-1-4/test.c b/c/misra/test/rules/RULE-1-4/test.c new file mode 100644 index 0000000000..126801f9e8 --- /dev/null +++ b/c/misra/test/rules/RULE-1-4/test.c @@ -0,0 +1,26 @@ +#include //NON_COMPLIANT +#include //NON_COMPLIANT +#include //NON_COMPLIANT +#include //NON_COMPLIANT + +#define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT +#define __STDC_WANT_LIB_EXT1__ 0 // 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 + + _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 +} \ No newline at end of file diff --git a/c/misra/test/rules/RULE-1-4/test1.c b/c/misra/test/rules/RULE-1-4/test1.c new file mode 100644 index 0000000000..bb3f3cfe9b --- /dev/null +++ b/c/misra/test/rules/RULE-1-4/test1.c @@ -0,0 +1 @@ +#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT \ No newline at end of file diff --git a/rules.csv b/rules.csv index ec8b29eaf9..ff8d4970cc 100644 --- a/rules.csv +++ b/rules.csv @@ -619,7 +619,7 @@ c,MISRA-C-2012,RULE-4-14,Yes,Required,,,The validity of values received from ext c,MISRA-C-2012,RULE-1-1,Yes,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation�s translation limits",,Language,Easy, c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language,Easy, c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language,Hard, -c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language,Medium, +c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language2,Medium, c,MISRA-C-2012,RULE-2-1,Yes,Required,,,A project shall not contain unreachable code,M0-1-1,DeadCode,Import, c,MISRA-C-2012,RULE-2-2,Yes,Required,,,There shall be no dead code,M0-1-9,DeadCode,Import, c,MISRA-C-2012,RULE-2-3,Yes,Advisory,,,A project should not contain unused type declarations,A0-1-6,DeadCode,Import, From 33867bb7d239d4493500bf446552de7a2a755d00 Mon Sep 17 00:00:00 2001 From: Kristen Newbury Date: Wed, 2 Nov 2022 10:22:40 -0400 Subject: [PATCH 03/23] Language2: rm DIR-2-1 --- rules.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules.csv b/rules.csv index ff8d4970cc..fdc8a08639 100644 --- a/rules.csv +++ b/rules.csv @@ -14,7 +14,7 @@ cpp,AUTOSAR,A1-1-2,Yes,Required,Non-Automated,Implementation / Toolchain,A warni cpp,AUTOSAR,A1-1-3,Yes,Required,Non-Automated,Toolchain,An optimization option that disregards strict standard compliance shall not be turned on in the chosen compiler.,,Toolchain,Easy,Note: this is currently only possible for compilations that do not use response files. cpp,AUTOSAR,A1-2-1,No,Required,Non-Automated,Toolchain,"When using a compiler toolchain (including preprocessor, compiler itself, linker, C++ standard libraries) in safety-related software, the tool confidence level (TCL) shall be determined. In case of TCL2 or TCL3, the compiler shall undergo a 'Qualification of a software tool', as per ISO 26262-8.11.4.6 [6].",,,,Allocated target not covered by CodeQL cpp,AUTOSAR,A1-4-1,No,Required,Non-Automated,Implementation / Verification,Code metrics and their valid boundaries shall be defined and code shall comply with defined boundaries of code metrics.,,,,Allocated target not covered by CodeQL -cpp,AUTOSAR,A1-4-3,No,Advisory,Automated,Implementation,All code should compile free of compiler warnings.,,,,"This should be checked via the compiler output, rather than CodeQL, which adds unecessary steps." +cpp,AUTOSAR,A1-4-3,No,Advisory,Automated,Implementation,All code should compile free of compiler warnings.,,,,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." cpp,AUTOSAR,A10-0-1,Yes,Required,Non-Automated,Design,Public inheritance shall be used to implement 'is-a' relationship.,,Inheritance,Audit,Report a list of Inheritance relationships. cpp,AUTOSAR,A10-0-2,Yes,Required,Non-Automated,Design,Membership or non-public inheritance shall be used to implement 'has-a' relationship.,,Inheritance,Audit,Report a list of membership relationships. cpp,AUTOSAR,A10-1-1,Yes,Required,Automated,Implementation,Class shall not be derived from more than one base class which is not an interface class.,,Inheritance,Easy, @@ -600,7 +600,7 @@ c,CERT-C,STR37-C,Yes,Rule,,,Arguments to character-handling functions must be re c,CERT-C,STR38-C,Yes,Rule,,,Do not confuse narrow and wide character strings and functions,,Strings3,Medium, c,CERT-C,WIN30-C,OutOfScope,Rule,,,Properly pair allocation and deallocation functions,DCL54-CPP,,Easy, c,MISRA-C-2012,RULE-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, -c,MISRA-C-2012,RULE-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, +c,MISRA-C-2012,DIR-2-1,No,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." c,MISRA-C-2012,RULE-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, c,MISRA-C-2012,RULE-4-1,No,Required,,,Run-time failures shall be minimized,,,, c,MISRA-C-2012,RULE-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import, From 8ec3b837cedf520b4dbbd85f01ee246c5cd063d2 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 11:03:45 -0400 Subject: [PATCH 04/23] checkpoint --- .vscode/tasks.json | 1 + .../LanguageExtensionsShouldNotBeUsed.ql | 20 + ...LanguageExtensionsShouldNotBeUsed.expected | 1 + .../LanguageExtensionsShouldNotBeUsed.qlref | 1 + c/misra/test/rules/RULE-1-2/test.c | 361 ++++++++++++++++++ .../cpp/exclusions/c/Language2.qll | 25 ++ .../cpp/exclusions/c/RuleMetadata.qll | 3 + rule_packages/c/Language2.json | 24 ++ rules.csv | 2 +- 9 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql create mode 100644 c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected create mode 100644 c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref create mode 100644 c/misra/test/rules/RULE-1-2/test.c create mode 100644 cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll create mode 100644 rule_packages/c/Language2.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d1f141cced..42f15d334a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -221,6 +221,7 @@ "Iterators", "Lambdas", "Language1", + "Language2", "Literals", "Loops", "Macros", diff --git a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql new file mode 100644 index 0000000000..eb676e2280 --- /dev/null +++ b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql @@ -0,0 +1,20 @@ +/** + * @id c/misra/language-extensions-should-not-be-used + * @name RULE-1-2: Language extensions should not be used + * @description Language extensions can have inconsistent behavior and should not be used. + * @kind problem + * @precision high + * @problem.severity error + * @tags external/misra/id/rule-1-2 + * maintainability + * readability + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.c.misra + +from +where + not isExcluded(x, Language2Package::languageExtensionsShouldNotBeUsedQuery()) and +select diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected new file mode 100644 index 0000000000..2ec1a0ac6c --- /dev/null +++ b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected @@ -0,0 +1 @@ +No expected results have yet been specified \ No newline at end of file diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref new file mode 100644 index 0000000000..965c95be2c --- /dev/null +++ b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref @@ -0,0 +1 @@ +rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-1-2/test.c b/c/misra/test/rules/RULE-1-2/test.c new file mode 100644 index 0000000000..0a2ca37057 --- /dev/null +++ b/c/misra/test/rules/RULE-1-2/test.c @@ -0,0 +1,361 @@ +#include +#include +// Note: Clang aims to support both clang and gcc extensions. +// This test case has been designed using lists compiled from: +// - https://clang.llvm.org/docs/LanguageExtensions.html +// - https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html + +#ifdef __has_builtin // NON_COMPLIANT +#endif +#ifdef __has_constexpr_builtin // NON_COMPLIANT +#endif +#ifdef __has_feature // NON_COMPLIANT +#endif +#ifdef __has_extension // NON_COMPLIANT +#endif +#ifdef __has_c_attribute // NON_COMPLIANT +#endif +#ifdef __has_attribute // NON_COMPLIANT +#endif +#ifdef __has_declspec_attribute // NON_COMPLIANT +#endif +#ifdef __is_identifier // NON_COMPLIANT +#endif +#ifdef __has_include // NON_COMPLIANT +#endif +#ifdef __has_include_next // NON_COMPLIANT +#endif +#ifdef __has_warning // NON_COMPLIANT +#endif + +#define A __BASE_FILE__ // NON_COMPLIANT +#define B __FILE_NAME__ // NON_COMPLIANT +#define C __COUNTER__ // NON_COMPLIANT +#define D __INCLUDE_LEVEL__ // NON_COMPLIANT +#define E__TIMESTAMP__ // NON_COMPLIANT +#define F __clang__ // NON_COMPLIANT +#define G __clang_major__ // NON_COMPLIANT +#define H __clang_minor__ // NON_COMPLIANT +#define I __clang_patchlevel__ // NON_COMPLIANT +#define J __clang_version__ // NON_COMPLIANT +#define K __clang_literal_encoding__ // NON_COMPLIANT +#define L __clang_wide_literal_encoding__ // NON_COMPLIANT + +typedef float float4 __attribute__((ext_vector_type(4))); // NON_COMPLIANT +typedef float float2 __attribute__((ext_vector_type(2))); // NON_COMPLIANT + +// Requires additional compiler flags to change the architecture +// typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t; +// typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t; + +typedef int int4 __attribute__((vector_size(4 * sizeof(int)))); // NON_COMPLIANT + +typedef int v4si __attribute__((__vector_size__(16))); // NON_COMPLIANT +typedef float float4 __attribute__((ext_vector_type(4))); // NON_COMPLIANT +typedef float float2 __attribute__((ext_vector_type(2))); // NON_COMPLIANT + +//// GCC features +void gf1() { + ({ + int y = 1; + int z; // NON_COMPLIANT + if (y > 0) + z = y; + else + z = -y; + z; + }); +} + +void gf2() { + // __label__ found; -- local labels not supported by clang +} + +void gf3() { + void *ptr; + // goto *ptr; -- not supported in clang +} + +void gf4() { + // void gf4a(){ -- not supported in clang + // + // } +} + +void gf5() { + __builtin_setjmp(0); // NON_COMPLIANT + __builtin_longjmp(0, 1); // NON_COMPLIANT +} + +void gf6() { + // not supported by clang + + //__builtin_apply_args(); + //__builtin_apply(0, 0, 0); + //__builtin_return(0); + //__builtin_va_arg_pack(); + //__builtin_va_arg_pack_len(); +} + +void gf7() { + int a = 0 ?: 0; // NON_COMPLIANT +} + +void gf8() { + typeof(int *); // NON_COMPLIANT +} + +void gf9() { + __int128 a; // NON_COMPLIANT +} + +void gf10() { + long long int a; // NON_COMPLIANT +} + +void gf11() { + __real__(0); // NON_COMPLIANT + __imag__(0); // NON_COMPLIANT +} + +void gf12() {} + +void gf13() { + // not supported on clang + + //_Decimal32 a; + //_Decimal64 b; + //_Decimal128 c; +} + +void gf14() { + // Not sure how to get this to work. + // typedef _Complex float __attribute__((mode(TC))) _Complex128; + // typedef _Complex float __attribute__((mode(XC))) _Complex80; +} + +void gf15() { + float f = 0x1.fp3; // NON_COMPLIANT +} + +void gf16() { + char contents[0]; // NON_COMPLIANT +} + +void gf17() { + // const __flash char ** p; // not supported in clang +} + +void gf18() { + // not supported by extractor - checked by looking for flags. + + // short _Fract, _Fract; + // long _Fract; +} + +struct gf19 {}; // NON_COMPLIANT + +void gf20(int n) { + // struct S { int x[n]; }; // will never be supported in clang +} + +#define gf21(format, args...) \ + printf(format, args) // NON_COMPLIANT -- note the issue here is explicitly + // naming the arguments. +#define gf21a(format, ...) printf(format, __VA_ARGS__) // COMPLIANT + +#define gf22 \ + "a" \ + \ +"b" // NON_COMPLIANT - additional spaces after a backslash +#define gf22a \ + "a" \ + "b" // COMPLIANT + +struct gf23s { + int a[1]; +}; +struct gf23s gf23f(); +void gf23() { + gf23f().a[0]; // NON_COMPLIANT in C90 +} + +void gf24(int f, int g) { + float beat_freqs[2] = {f - g, f + g}; // NON_COMPLIANT +} + +void gf25t(int N, int M, double out[M][N], const double in[N][M]); +void gf25() { + double x[3][2]; + double y[2][3]; + gf25t(3, 2, y, + x); // NON_COMPLIANT - in ISO C the const qualifier is formally attached + // to the element type of the array and not the array itself +} + +struct gf26t { + int a; + char b[2]; +} gf26v; +void gf26(int x, int y) { + gf26v = ((struct gf26t){x + y, 'z', 0}); // NON_COMPLIANT - compound literal +} + +void gf27() { + int a[6] = {[4] = 29, [2] = 15}; // NON_COMPLIANT in C90. +} + +void gf28() { + int a; + + // switch(a){ + // case: 0 ... 5: // Not supported in clang. + // ;; + // break; + // default: + // ;; + // break; + // } +} + +union gf29u { + int i; + double j; +}; + +void gf29() { + int x; + int y; + union gf29u z; + z = (union gf29u)x; // NON_COMPLIANT + z = (union gf29u)y; // NON_COMPLIANT +} + +__attribute__((access(read_only, 1))) int +gf30(const char *); // NON_COMPLIANT -- attributes are not portable. + +extern int __attribute__((alias("var_target"))) +gf31; // NON_COMPLIANT -- attributes are not portable. + +struct __attribute__((aligned(8))) gf32 { + short f[3]; +}; // NON_COMPLIANT -- attributes are not portable. + +void gf33() { +gf33l: + __attribute__((cold, unused)); // NON_COMPLIANT + return; +} + +enum gf34 { + oldval __attribute__((deprecated)), // NON_COMPLIANT + newval +}; + +void gf35() { + int x; + // __attribute__((assume(x == 42))); - Not supported in clang + + switch (x) { + case 1: + printf(""); + __attribute__((fallthrough)); // NON_COMPLIANT + case 2: + break; + } +} + +// Not supported in clang. +// int gf36 (uid_t); + +// int +// gf36 (int x) +// { +// return x == 0; +// } + +void gf37() { + int a$1; // NON_COMPLIANT +} + +void gf38() { + const char *c = "test\e"; // NON_COMPLIANT +} + +struct gf39s { + int x; + char y; +} gf39v; + +void gf39() { + __alignof__(gf39v.x); // NON_COMPLIANT +} + +// enum gf40 {}; // not supported in clang + +void gf41() { + printf("__FUNCTION__ = %s\n", __FUNCTION__); // NON_COMPLIANT + printf("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); // NON_COMPLIANT +} + +void gf42() { + __builtin_extract_return_addr(0); + __builtin_frob_return_addr(0); + __builtin_frame_address(0); +} + +struct gf43s { + int x; + char y; +} gf43v; + +void gf43() { + __builtin_offsetof(struct gf43s, x); // NON_COMPLIANT +} + +struct gf44s { + int x; + char y; +} gf44v; + +void gf44() { + int i; + __sync_fetch_and_add(&i, 0); // NON_COMPLIANT + __sync_fetch_and_sub(&i, 0); // NON_COMPLIANT + __sync_fetch_and_or(&i, 0); // NON_COMPLIANT + __sync_fetch_and_and(&i, 0); // NON_COMPLIANT + __sync_fetch_and_xor(&i, 0); // NON_COMPLIANT + __sync_fetch_and_nand(&i, 0); // NON_COMPLIANT + __sync_add_and_fetch(&i, 0); // NON_COMPLIANT + __sync_sub_and_fetch(&i, 0); // NON_COMPLIANT + __sync_or_and_fetch(&i, 0); // NON_COMPLIANT + __sync_and_and_fetch(&i, 0); // NON_COMPLIANT + __sync_xor_and_fetch(&i, 0); // NON_COMPLIANT + __sync_nand_and_fetch(&i, 0); // NON_COMPLIANT + + __sync_bool_compare_and_swap(&i, 0, 0); + __sync_val_compare_and_swap(&i, 0, 0); + __sync_lock_test_and_set(&i, 0, 0); + __sync_lock_release(&i, 0); +} + +void gf45() { + int i = 0b101010; // NON_COMPLIANT +} + +__thread int gf46; // NON_COMPLIANT + +void gf47() { // NON_COMPLIANT in versions < C11. + struct { + int a; + union { + int b; + float c; + }; + int d; + } f; +} + +void gf48(){ + __builtin_alloca(0); // NON_COMPLIANT (all __builtin functions are non-compliant.) +} \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll new file mode 100644 index 0000000000..a7a3836736 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll @@ -0,0 +1,25 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype Language2Query = TLanguageExtensionsShouldNotBeUsedQuery() + +predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { + query = + // `Query` instance for the `languageExtensionsShouldNotBeUsed` query + Language2Package::languageExtensionsShouldNotBeUsedQuery() and + queryId = + // `@id` for the `languageExtensionsShouldNotBeUsed` query + "c/misra/language-extensions-should-not-be-used" and + ruleId = "RULE-1-2" +} + +module Language2Package { + Query languageExtensionsShouldNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `languageExtensionsShouldNotBeUsed` query + TQueryC(TLanguage2PackageQuery(TLanguageExtensionsShouldNotBeUsedQuery())) + } +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll index ad05d9b737..69fc7d2d07 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll @@ -21,6 +21,7 @@ import IO2 import IO3 import IO4 import Language1 +import Language2 import Misc import Pointers1 import Pointers2 @@ -57,6 +58,7 @@ newtype TCQuery = TIO3PackageQuery(IO3Query q) or TIO4PackageQuery(IO4Query q) or TLanguage1PackageQuery(Language1Query q) or + TLanguage2PackageQuery(Language2Query q) or TMiscPackageQuery(MiscQuery q) or TPointers1PackageQuery(Pointers1Query q) or TPointers2PackageQuery(Pointers2Query q) or @@ -93,6 +95,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId) { isIO3QueryMetadata(query, queryId, ruleId) or isIO4QueryMetadata(query, queryId, ruleId) or isLanguage1QueryMetadata(query, queryId, ruleId) or + isLanguage2QueryMetadata(query, queryId, ruleId) or isMiscQueryMetadata(query, queryId, ruleId) or isPointers1QueryMetadata(query, queryId, ruleId) or isPointers2QueryMetadata(query, queryId, ruleId) or diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json new file mode 100644 index 0000000000..e1b2ea553b --- /dev/null +++ b/rule_packages/c/Language2.json @@ -0,0 +1,24 @@ +{ + "MISRA-C-2012": { + "RULE-1-2": { + "properties": { + "obligation": "advisory" + }, + "queries": [ + { + "description": "Language extensions can have inconsistent behavior and should not be used.", + "kind": "problem", + "name": "Language extensions should not be used", + "precision": "high", + "severity": "error", + "short_name": "LanguageExtensionsShouldNotBeUsed", + "tags": [ + "maintainability", + "readability" + ] + } + ], + "title": "Language extensions should not be used" + } + } +} \ No newline at end of file diff --git a/rules.csv b/rules.csv index 8cd7a19ed4..2477d5072a 100644 --- a/rules.csv +++ b/rules.csv @@ -600,7 +600,7 @@ c,CERT-C,STR37-C,Yes,Rule,,,Arguments to character-handling functions must be re c,CERT-C,STR38-C,Yes,Rule,,,Do not confuse narrow and wide character strings and functions,,Strings3,Medium, c,CERT-C,WIN30-C,OutOfScope,Rule,,,Properly pair allocation and deallocation functions,DCL54-CPP,,Easy, c,MISRA-C-2012,RULE-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, -c,MISRA-C-2012,RULE-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, +c,MISRA-C-2012,DIR-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, c,MISRA-C-2012,RULE-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, c,MISRA-C-2012,RULE-4-1,No,Required,,,Run-time failures shall be minimized,,,, c,MISRA-C-2012,RULE-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import, From 0358f6ef588eddae03060e097b29ddf2beb2ca08 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 8 Nov 2022 16:35:17 -0500 Subject: [PATCH 05/23] extractor --- c/misra/test/rules/RULE-1-2/test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/c/misra/test/rules/RULE-1-2/test.c b/c/misra/test/rules/RULE-1-2/test.c index 0a2ca37057..f71fb1ac4f 100644 --- a/c/misra/test/rules/RULE-1-2/test.c +++ b/c/misra/test/rules/RULE-1-2/test.c @@ -1,3 +1,7 @@ +// semmle-extractor-options:--clang -fhonor-infinity -std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library + +// do it on a translation unit -- flag first line + #include #include // Note: Clang aims to support both clang and gcc extensions. @@ -135,7 +139,7 @@ void gf14() { } void gf15() { - float f = 0x1.fp3; // NON_COMPLIANT + float f = 0x1.fp3; // NON_COMPLIANT } void gf16() { From ca41ed6734f7acca0940cdef72283cbea5cc5ad8 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:03:19 -0500 Subject: [PATCH 06/23] refactor query --- .../M7-4-1/UsageOfAssemblerNotDocumented.ql | 12 ++++++------ .../UsageOfAssemblerNotDocumented.qlref | 1 - .../UsageOfAssemblerNotDocumented.testref | 1 + .../UsageOfAssemblerNotDocumented.qll | 19 +++++++++++++++++++ .../UsageOfAssemblerNotDocumented.expected | 0 .../UsageOfAssemblerNotDocumented.ql | 2 ++ .../usageofassemblernotdocumented}/test.cpp | 0 rule_packages/cpp/BannedLibraries.json | 1 + 8 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.qlref create mode 100644 cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.testref create mode 100644 cpp/common/src/codingstandards/cpp/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.qll rename cpp/{autosar/test/rules/M7-4-1 => common/test/rules/usageofassemblernotdocumented}/UsageOfAssemblerNotDocumented.expected (100%) create mode 100644 cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql rename cpp/{autosar/test/rules/M7-4-1 => common/test/rules/usageofassemblernotdocumented}/test.cpp (100%) diff --git a/cpp/autosar/src/rules/M7-4-1/UsageOfAssemblerNotDocumented.ql b/cpp/autosar/src/rules/M7-4-1/UsageOfAssemblerNotDocumented.ql index 418a96ffee..f39b01b7ed 100644 --- a/cpp/autosar/src/rules/M7-4-1/UsageOfAssemblerNotDocumented.ql +++ b/cpp/autosar/src/rules/M7-4-1/UsageOfAssemblerNotDocumented.ql @@ -17,10 +17,10 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented -from AsmStmt a -where - not isExcluded(a, BannedLibrariesPackage::usageOfAssemblerNotDocumentedQuery()) and - not exists(Comment c | c.getCommentedElement() = a) and - not a.isAffectedByMacro() -select a, "Use of assembler is not documented." +class UsageOfAssemblerNotDocumentedQuery extends UsageOfAssemblerNotDocumentedSharedQuery { + UsageOfAssemblerNotDocumentedQuery() { + this = BannedLibrariesPackage::usageOfAssemblerNotDocumentedQuery() + } +} diff --git a/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.qlref b/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.qlref deleted file mode 100644 index 164f0c5b29..0000000000 --- a/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M7-4-1/UsageOfAssemblerNotDocumented.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.testref b/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.testref new file mode 100644 index 0000000000..ea9ce384ea --- /dev/null +++ b/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.testref @@ -0,0 +1 @@ +cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.qll b/cpp/common/src/codingstandards/cpp/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.qll new file mode 100644 index 0000000000..8cdb9cbbf0 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.qll @@ -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." +} diff --git a/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.expected b/cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected similarity index 100% rename from cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.expected rename to cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected diff --git a/cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql b/cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql new file mode 100644 index 0000000000..7f9e1041a2 --- /dev/null +++ b/cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql @@ -0,0 +1,2 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented diff --git a/cpp/autosar/test/rules/M7-4-1/test.cpp b/cpp/common/test/rules/usageofassemblernotdocumented/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M7-4-1/test.cpp rename to cpp/common/test/rules/usageofassemblernotdocumented/test.cpp diff --git a/rule_packages/cpp/BannedLibraries.json b/rule_packages/cpp/BannedLibraries.json index 4eb5896cfd..09b5d2f224 100644 --- a/rule_packages/cpp/BannedLibraries.json +++ b/rule_packages/cpp/BannedLibraries.json @@ -229,6 +229,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "UsageOfAssemblerNotDocumented", + "shared_implementation_short_name": "UsageOfAssemblerNotDocumented", "tags": [ "readability", "maintainability", From d91613ba69e3183cab7dd846d18d81d5c31d803c Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:41:35 -0500 Subject: [PATCH 07/23] refactor --- .../UsageOfAssemblerNotDocumented.expected | 1 + cpp/autosar/test/rules/M7-4-1/test.cpp | 12 +++++ .../cpp/exclusions/c/Language2.qll | 51 ++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.expected create mode 100644 cpp/autosar/test/rules/M7-4-1/test.cpp diff --git a/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.expected b/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.expected new file mode 100644 index 0000000000..aa625dd58a --- /dev/null +++ b/cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.expected @@ -0,0 +1 @@ +| test.cpp:8:42:8:58 | asm statement | Use of assembler is not documented. | diff --git a/cpp/autosar/test/rules/M7-4-1/test.cpp b/cpp/autosar/test/rules/M7-4-1/test.cpp new file mode 100644 index 0000000000..16e0f9ca91 --- /dev/null +++ b/cpp/autosar/test/rules/M7-4-1/test.cpp @@ -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; } \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll index a7a3836736..d471d09efd 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll @@ -3,9 +3,21 @@ import cpp import RuleMetadata import codingstandards.cpp.exclusions.RuleMetadata -newtype Language2Query = TLanguageExtensionsShouldNotBeUsedQuery() +newtype Language2Query = + TUsageOfAssemblyLanguageShouldBeDocumentedQuery() or + TLanguageExtensionsShouldNotBeUsedQuery() or + TCriticalUnspecifiedBehaviourQuery() 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 `languageExtensionsShouldNotBeUsed` query Language2Package::languageExtensionsShouldNotBeUsedQuery() and @@ -13,13 +25,50 @@ predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { // `@id` for the `languageExtensionsShouldNotBeUsed` query "c/misra/language-extensions-should-not-be-used" and ruleId = "RULE-1-2" + or + query = + // `Query` instance for the `criticalUnspecifiedBehaviour` query + Language2Package::criticalUnspecifiedBehaviourQuery() and + queryId = + // `@id` for the `criticalUnspecifiedBehaviour` query + "c/misra/critical-unspecified-behaviour" and + ruleId = "RULE-1-3" + 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 languageExtensionsShouldNotBeUsedQuery() { //autogenerate `Query` type result = // `Query` type for `languageExtensionsShouldNotBeUsed` query TQueryC(TLanguage2PackageQuery(TLanguageExtensionsShouldNotBeUsedQuery())) } + + Query criticalUnspecifiedBehaviourQuery() { + //autogenerate `Query` type + result = + // `Query` type for `criticalUnspecifiedBehaviour` query + TQueryC(TLanguage2PackageQuery(TCriticalUnspecifiedBehaviourQuery())) + } + + Query emergentLanguageFeaturesUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `emergentLanguageFeaturesUsed` query + TQueryC(TLanguage2PackageQuery(TEmergentLanguageFeaturesUsedQuery())) + } } From a894b13844f8847112b96c447db7fc9d1c8693af Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:41:42 -0500 Subject: [PATCH 08/23] refactor --- rule_packages/c/Language2.json | 65 +++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json index e1b2ea553b..be311f7552 100644 --- a/rule_packages/c/Language2.json +++ b/rule_packages/c/Language2.json @@ -1,5 +1,26 @@ { "MISRA-C-2012": { + "DIR-4-2": { + "properties": { + "obligation": "advisory" + }, + "queries": [ + { + "description": "", + "kind": "problem", + "name": "All usage of assembly language should be documented", + "precision": "very-high", + "severity": "error", + "short_name": "UsageOfAssemblyLanguageShouldBeDocumented", + "shared_implementation_short_name": "UsageOfAssemblerNotDocumented", + "tags": [ + "maintainability", + "readability" + ] + } + ], + "title": "All usage of assembly language should be documented" + }, "RULE-1-2": { "properties": { "obligation": "advisory" @@ -14,11 +35,53 @@ "short_name": "LanguageExtensionsShouldNotBeUsed", "tags": [ "maintainability", - "readability" + "readability", + "correctness" ] } ], "title": "Language extensions should not be used" + }, + "RULE-1-3": { + "properties": { + "obligation": "required" + }, + "queries": [ + { + "description": "", + "kind": "problem", + "name": "There shall be no occurrence of undefined or critical unspecified behaviour", + "precision": "high", + "severity": "error", + "short_name": "CriticalUnspecifiedBehaviour", + "tags": [ + "maintainability", + "readability", + "correctness" + ] + } + ], + "title": "There shall be no occurrence of undefined or critical unspecified behaviour" + }, + "RULE-1-4": { + "properties": { + "obligation": "required" + }, + "queries": [ + { + "description": "", + "kind": "problem", + "name": "Emergent language features shall not be used", + "precision": "very-high", + "severity": "error", + "short_name": "EmergentLanguageFeaturesUsed", + "tags": [ + "maintainability", + "readability" + ] + } + ], + "title": "Emergent language features shall not be used" } } } \ No newline at end of file From 524cf0b4db1902a4b8360ee9e80ea6f5d60a5134 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:41:56 -0500 Subject: [PATCH 09/23] refactor --- .../UsageOfAssemblerNotDocumented.expected | 1 + .../UsageOfAssemblerNotDocumented.ql | 2 ++ .../test/rules/usageofassemblernotdocumented/test.c | 12 ++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected create mode 100644 c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql create mode 100644 c/common/test/rules/usageofassemblernotdocumented/test.c diff --git a/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected b/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected new file mode 100644 index 0000000000..8c132cdb91 --- /dev/null +++ b/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected @@ -0,0 +1 @@ +| test.c:8:42:8:58 | asm statement | Use of assembler is not documented. | diff --git a/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql b/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql new file mode 100644 index 0000000000..7f9e1041a2 --- /dev/null +++ b/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql @@ -0,0 +1,2 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented diff --git a/c/common/test/rules/usageofassemblernotdocumented/test.c b/c/common/test/rules/usageofassemblernotdocumented/test.c new file mode 100644 index 0000000000..16e0f9ca91 --- /dev/null +++ b/c/common/test/rules/usageofassemblernotdocumented/test.c @@ -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; } \ No newline at end of file From b63c28ff5c94cf9b06804d6a23a55958f6d2c7ee Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:42:08 -0500 Subject: [PATCH 10/23] import --- ...ageOfAssemblyLanguageShouldBeDocumented.ql | 22 +++++++++++++++++++ ...AssemblyLanguageShouldBeDocumented.testref | 1 + 2 files changed, 23 insertions(+) create mode 100644 c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql create mode 100644 c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref diff --git a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql new file mode 100644 index 0000000000..250d98892c --- /dev/null +++ b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql @@ -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 + * @kind problem + * @precision very-high + * @problem.severity error + * @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() + } +} diff --git a/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref b/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref new file mode 100644 index 0000000000..3b0dc2fe5a --- /dev/null +++ b/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref @@ -0,0 +1 @@ +c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql \ No newline at end of file From e31b26c256dc20f68e51e5c839885e3e61f269fe Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:47:52 -0500 Subject: [PATCH 11/23] fixing rules --- rules.csv | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules.csv b/rules.csv index 75d17653e1..5066a86ff2 100644 --- a/rules.csv +++ b/rules.csv @@ -600,10 +600,10 @@ c,CERT-C,STR37-C,Yes,Rule,,,Arguments to character-handling functions must be re c,CERT-C,STR38-C,Yes,Rule,,,Do not confuse narrow and wide character strings and functions,,Strings3,Medium, c,CERT-C,WIN30-C,OutOfScope,Rule,,,Properly pair allocation and deallocation functions,DCL54-CPP,,Easy, c,MISRA-C-2012,DIR-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, -c,MISRA-C-2012,DIR-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, +c,MISRA-C-2012,DIR-2-1,No,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." c,MISRA-C-2012,DIR-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, c,MISRA-C-2012,DIR-4-1,No,Required,,,Run-time failures shall be minimized,,,, -c,MISRA-C-2012,DIR-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import, +c,MISRA-C-2012,DIR-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language2,Import, c,MISRA-C-2012,DIR-4-3,Yes,Required,,,Assembly language shall be encapsulated and isolated,,Language1,Medium, c,MISRA-C-2012,DIR-4-4,Yes,Advisory,,,Sections of code should not be commented out,A2-7-2,Syntax,Import, c,MISRA-C-2012,DIR-4-5,Yes,Advisory,,,Identifiers in the same name space with overlapping visibility should be typographically unambiguous,M2-10-1,Syntax,Easy, @@ -616,9 +616,9 @@ c,MISRA-C-2012,DIR-4-11,Yes,Required,,,The validity of values passed to library c,MISRA-C-2012,DIR-4-12,Yes,Required,,,Dynamic memory allocation shall not be used,,Banned,Medium, c,MISRA-C-2012,DIR-4-13,Yes,Advisory,,,Functions which are designed to provide operations on a resource should be called in an appropriate sequence,,Contracts,Hard, c,MISRA-C-2012,DIR-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, -c,MISRA-C-2012,RULE-1-1,Yes,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation�s translation limits",,Language,Easy, +c,MISRA-C-2012,RULE-1-1,No,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits",,Language,Easy,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language2,Hard, -c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language,Hard, +c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language2,Hard, c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language2,Medium, c,MISRA-C-2012,RULE-2-1,Yes,Required,,,A project shall not contain unreachable code,M0-1-1,DeadCode,Import, c,MISRA-C-2012,RULE-2-2,Yes,Required,,,There shall be no dead code,M0-1-9,DeadCode,Import, From 8080bc30a5d439364d00eb7d9c8a5e7a5899be82 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 9 Nov 2022 16:49:52 -0500 Subject: [PATCH 12/23] headers --- c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql | 1 + 1 file changed, 1 insertion(+) diff --git a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql index eb676e2280..8da2c09947 100644 --- a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql @@ -8,6 +8,7 @@ * @tags external/misra/id/rule-1-2 * maintainability * readability + * correctness * external/misra/obligation/advisory */ From bee4cffcd6bb2984717bfafe2802ff2948165fcf Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 18 Nov 2022 10:02:59 -0500 Subject: [PATCH 13/23] remove rule --- rule_packages/c/Language2.json | 25 ++----------------------- rules.csv | 2 +- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json index be311f7552..2fc720b57d 100644 --- a/rule_packages/c/Language2.json +++ b/rule_packages/c/Language2.json @@ -41,35 +41,14 @@ } ], "title": "Language extensions should not be used" - }, - "RULE-1-3": { - "properties": { - "obligation": "required" - }, - "queries": [ - { - "description": "", - "kind": "problem", - "name": "There shall be no occurrence of undefined or critical unspecified behaviour", - "precision": "high", - "severity": "error", - "short_name": "CriticalUnspecifiedBehaviour", - "tags": [ - "maintainability", - "readability", - "correctness" - ] - } - ], - "title": "There shall be no occurrence of undefined or critical unspecified behaviour" - }, + }, "RULE-1-4": { "properties": { "obligation": "required" }, "queries": [ { - "description": "", + "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", diff --git a/rules.csv b/rules.csv index 5066a86ff2..8031503680 100644 --- a/rules.csv +++ b/rules.csv @@ -618,7 +618,7 @@ c,MISRA-C-2012,DIR-4-13,Yes,Advisory,,,Functions which are designed to provide o c,MISRA-C-2012,DIR-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, c,MISRA-C-2012,RULE-1-1,No,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits",,Language,Easy,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language2,Hard, -c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language2,Hard, +c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language3,Hard, c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language2,Medium, c,MISRA-C-2012,RULE-2-1,Yes,Required,,,A project shall not contain unreachable code,M0-1-1,DeadCode,Import, c,MISRA-C-2012,RULE-2-2,Yes,Required,,,There shall be no dead code,M0-1-9,DeadCode,Import, From 38439e3ba821b479b1ab15683bb1cbeca8a6c26a Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 18 Nov 2022 10:44:06 -0500 Subject: [PATCH 14/23] adding 1-4 --- .../RULE-1-4/EmergentLanguageFeaturesUsed.ql | 20 +++++++++++++++++++ .../EmergentLanguageFeaturesUsed.expected | 1 + .../EmergentLanguageFeaturesUsed.qlref | 1 + .../cpp/exclusions/c/Language2.qll | 16 --------------- 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql create mode 100644 c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected create mode 100644 c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.qlref diff --git a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql new file mode 100644 index 0000000000..462523de50 --- /dev/null +++ b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql @@ -0,0 +1,20 @@ +/** + * @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 error + * @tags external/misra/id/rule-1-4 + * maintainability + * readability + * external/misra/obligation/required + */ + +import cpp +import codingstandards.c.misra + +from +where + not isExcluded(x, Language2Package::emergentLanguageFeaturesUsedQuery()) and +select diff --git a/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected b/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected new file mode 100644 index 0000000000..2ec1a0ac6c --- /dev/null +++ b/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected @@ -0,0 +1 @@ +No expected results have yet been specified \ No newline at end of file diff --git a/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.qlref b/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.qlref new file mode 100644 index 0000000000..6e3737f029 --- /dev/null +++ b/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.qlref @@ -0,0 +1 @@ +rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll index d471d09efd..9d270d34be 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll @@ -6,7 +6,6 @@ import codingstandards.cpp.exclusions.RuleMetadata newtype Language2Query = TUsageOfAssemblyLanguageShouldBeDocumentedQuery() or TLanguageExtensionsShouldNotBeUsedQuery() or - TCriticalUnspecifiedBehaviourQuery() or TEmergentLanguageFeaturesUsedQuery() predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { @@ -26,14 +25,6 @@ predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { "c/misra/language-extensions-should-not-be-used" and ruleId = "RULE-1-2" or - query = - // `Query` instance for the `criticalUnspecifiedBehaviour` query - Language2Package::criticalUnspecifiedBehaviourQuery() and - queryId = - // `@id` for the `criticalUnspecifiedBehaviour` query - "c/misra/critical-unspecified-behaviour" and - ruleId = "RULE-1-3" - or query = // `Query` instance for the `emergentLanguageFeaturesUsed` query Language2Package::emergentLanguageFeaturesUsedQuery() and @@ -58,13 +49,6 @@ module Language2Package { TQueryC(TLanguage2PackageQuery(TLanguageExtensionsShouldNotBeUsedQuery())) } - Query criticalUnspecifiedBehaviourQuery() { - //autogenerate `Query` type - result = - // `Query` type for `criticalUnspecifiedBehaviour` query - TQueryC(TLanguage2PackageQuery(TCriticalUnspecifiedBehaviourQuery())) - } - Query emergentLanguageFeaturesUsedQuery() { //autogenerate `Query` type result = From 3d14f979efa6679183e0a997d01a9f3eb7e59fc7 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 18 Nov 2022 17:31:46 -0500 Subject: [PATCH 15/23] emergent --- .../RULE-1-4/EmergentLanguageFeaturesUsed.ql | 9 ++-- .../EmergentLanguageFeaturesUsed.expected | 16 +++++- c/misra/test/rules/RULE-1-4/test.c | 4 +- c/misra/test/rules/RULE-1-4/test1.c | 1 - .../src/codingstandards/cpp/Emergent.qll | 49 +++++++++++++++++++ 5 files changed, 71 insertions(+), 8 deletions(-) delete mode 100644 c/misra/test/rules/RULE-1-4/test1.c create mode 100644 cpp/common/src/codingstandards/cpp/Emergent.qll diff --git a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql index 462523de50..e9a5591f61 100644 --- a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql +++ b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql @@ -13,8 +13,9 @@ 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." -from -where - not isExcluded(x, Language2Package::emergentLanguageFeaturesUsedQuery()) and -select diff --git a/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected b/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected index 2ec1a0ac6c..2745223358 100644 --- a/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected +++ b/c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected @@ -1 +1,15 @@ -No expected results have yet been specified \ No newline at end of file +| test.c:1:1:1:21 | #include | Usage of emergent language feature. | +| test.c:2:1:2:22 | #include | Usage of emergent language feature. | +| test.c:3:1:3:24 | #include | Usage of emergent language feature. | +| test.c:4:1:4:20 | #include | 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. | diff --git a/c/misra/test/rules/RULE-1-4/test.c b/c/misra/test/rules/RULE-1-4/test.c index 126801f9e8..7b31e6a555 100644 --- a/c/misra/test/rules/RULE-1-4/test.c +++ b/c/misra/test/rules/RULE-1-4/test.c @@ -4,7 +4,7 @@ #include //NON_COMPLIANT #define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT -#define __STDC_WANT_LIB_EXT1__ 0 // COMPLIANT +#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT _Noreturn void f0(); // NON_COMPLIANT @@ -12,7 +12,7 @@ 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 + // int i0 = _Generic(p, int : 0, long : 1); // NON_COMPLIANT[FALSE_NEGATIVE] _Atomic int i; // NON_COMPLIANT diff --git a/c/misra/test/rules/RULE-1-4/test1.c b/c/misra/test/rules/RULE-1-4/test1.c deleted file mode 100644 index bb3f3cfe9b..0000000000 --- a/c/misra/test/rules/RULE-1-4/test1.c +++ /dev/null @@ -1 +0,0 @@ -#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/Emergent.qll b/cpp/common/src/codingstandards/cpp/Emergent.qll new file mode 100644 index 0000000000..53f7e5599b --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/Emergent.qll @@ -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 { } + } \ No newline at end of file From 0c6aecf9fd2af61a58b87b0937949adc5810826b Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 18 Nov 2022 17:33:32 -0500 Subject: [PATCH 16/23] work --- .../LanguageExtensionsShouldNotBeUsed.ql | 21 - ...LanguageExtensionsShouldNotBeUsed.expected | 1 - .../LanguageExtensionsShouldNotBeUsed.qlref | 1 - c/misra/test/rules/RULE-1-2/test.c | 365 ------------------ rule_packages/c/Language2.json | 21 - rules.csv | 2 +- 6 files changed, 1 insertion(+), 410 deletions(-) delete mode 100644 c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql delete mode 100644 c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected delete mode 100644 c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref delete mode 100644 c/misra/test/rules/RULE-1-2/test.c diff --git a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql b/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql deleted file mode 100644 index 8da2c09947..0000000000 --- a/c/misra/src/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @id c/misra/language-extensions-should-not-be-used - * @name RULE-1-2: Language extensions should not be used - * @description Language extensions can have inconsistent behavior and should not be used. - * @kind problem - * @precision high - * @problem.severity error - * @tags external/misra/id/rule-1-2 - * maintainability - * readability - * correctness - * external/misra/obligation/advisory - */ - -import cpp -import codingstandards.c.misra - -from -where - not isExcluded(x, Language2Package::languageExtensionsShouldNotBeUsedQuery()) and -select diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected deleted file mode 100644 index 2ec1a0ac6c..0000000000 --- a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.expected +++ /dev/null @@ -1 +0,0 @@ -No expected results have yet been specified \ No newline at end of file diff --git a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref b/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref deleted file mode 100644 index 965c95be2c..0000000000 --- a/c/misra/test/rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-1-2/LanguageExtensionsShouldNotBeUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-1-2/test.c b/c/misra/test/rules/RULE-1-2/test.c deleted file mode 100644 index f71fb1ac4f..0000000000 --- a/c/misra/test/rules/RULE-1-2/test.c +++ /dev/null @@ -1,365 +0,0 @@ -// semmle-extractor-options:--clang -fhonor-infinity -std=c11 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../common/test/includes/standard-library - -// do it on a translation unit -- flag first line - -#include -#include -// Note: Clang aims to support both clang and gcc extensions. -// This test case has been designed using lists compiled from: -// - https://clang.llvm.org/docs/LanguageExtensions.html -// - https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html - -#ifdef __has_builtin // NON_COMPLIANT -#endif -#ifdef __has_constexpr_builtin // NON_COMPLIANT -#endif -#ifdef __has_feature // NON_COMPLIANT -#endif -#ifdef __has_extension // NON_COMPLIANT -#endif -#ifdef __has_c_attribute // NON_COMPLIANT -#endif -#ifdef __has_attribute // NON_COMPLIANT -#endif -#ifdef __has_declspec_attribute // NON_COMPLIANT -#endif -#ifdef __is_identifier // NON_COMPLIANT -#endif -#ifdef __has_include // NON_COMPLIANT -#endif -#ifdef __has_include_next // NON_COMPLIANT -#endif -#ifdef __has_warning // NON_COMPLIANT -#endif - -#define A __BASE_FILE__ // NON_COMPLIANT -#define B __FILE_NAME__ // NON_COMPLIANT -#define C __COUNTER__ // NON_COMPLIANT -#define D __INCLUDE_LEVEL__ // NON_COMPLIANT -#define E__TIMESTAMP__ // NON_COMPLIANT -#define F __clang__ // NON_COMPLIANT -#define G __clang_major__ // NON_COMPLIANT -#define H __clang_minor__ // NON_COMPLIANT -#define I __clang_patchlevel__ // NON_COMPLIANT -#define J __clang_version__ // NON_COMPLIANT -#define K __clang_literal_encoding__ // NON_COMPLIANT -#define L __clang_wide_literal_encoding__ // NON_COMPLIANT - -typedef float float4 __attribute__((ext_vector_type(4))); // NON_COMPLIANT -typedef float float2 __attribute__((ext_vector_type(2))); // NON_COMPLIANT - -// Requires additional compiler flags to change the architecture -// typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t; -// typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t; - -typedef int int4 __attribute__((vector_size(4 * sizeof(int)))); // NON_COMPLIANT - -typedef int v4si __attribute__((__vector_size__(16))); // NON_COMPLIANT -typedef float float4 __attribute__((ext_vector_type(4))); // NON_COMPLIANT -typedef float float2 __attribute__((ext_vector_type(2))); // NON_COMPLIANT - -//// GCC features -void gf1() { - ({ - int y = 1; - int z; // NON_COMPLIANT - if (y > 0) - z = y; - else - z = -y; - z; - }); -} - -void gf2() { - // __label__ found; -- local labels not supported by clang -} - -void gf3() { - void *ptr; - // goto *ptr; -- not supported in clang -} - -void gf4() { - // void gf4a(){ -- not supported in clang - // - // } -} - -void gf5() { - __builtin_setjmp(0); // NON_COMPLIANT - __builtin_longjmp(0, 1); // NON_COMPLIANT -} - -void gf6() { - // not supported by clang - - //__builtin_apply_args(); - //__builtin_apply(0, 0, 0); - //__builtin_return(0); - //__builtin_va_arg_pack(); - //__builtin_va_arg_pack_len(); -} - -void gf7() { - int a = 0 ?: 0; // NON_COMPLIANT -} - -void gf8() { - typeof(int *); // NON_COMPLIANT -} - -void gf9() { - __int128 a; // NON_COMPLIANT -} - -void gf10() { - long long int a; // NON_COMPLIANT -} - -void gf11() { - __real__(0); // NON_COMPLIANT - __imag__(0); // NON_COMPLIANT -} - -void gf12() {} - -void gf13() { - // not supported on clang - - //_Decimal32 a; - //_Decimal64 b; - //_Decimal128 c; -} - -void gf14() { - // Not sure how to get this to work. - // typedef _Complex float __attribute__((mode(TC))) _Complex128; - // typedef _Complex float __attribute__((mode(XC))) _Complex80; -} - -void gf15() { - float f = 0x1.fp3; // NON_COMPLIANT -} - -void gf16() { - char contents[0]; // NON_COMPLIANT -} - -void gf17() { - // const __flash char ** p; // not supported in clang -} - -void gf18() { - // not supported by extractor - checked by looking for flags. - - // short _Fract, _Fract; - // long _Fract; -} - -struct gf19 {}; // NON_COMPLIANT - -void gf20(int n) { - // struct S { int x[n]; }; // will never be supported in clang -} - -#define gf21(format, args...) \ - printf(format, args) // NON_COMPLIANT -- note the issue here is explicitly - // naming the arguments. -#define gf21a(format, ...) printf(format, __VA_ARGS__) // COMPLIANT - -#define gf22 \ - "a" \ - \ -"b" // NON_COMPLIANT - additional spaces after a backslash -#define gf22a \ - "a" \ - "b" // COMPLIANT - -struct gf23s { - int a[1]; -}; -struct gf23s gf23f(); -void gf23() { - gf23f().a[0]; // NON_COMPLIANT in C90 -} - -void gf24(int f, int g) { - float beat_freqs[2] = {f - g, f + g}; // NON_COMPLIANT -} - -void gf25t(int N, int M, double out[M][N], const double in[N][M]); -void gf25() { - double x[3][2]; - double y[2][3]; - gf25t(3, 2, y, - x); // NON_COMPLIANT - in ISO C the const qualifier is formally attached - // to the element type of the array and not the array itself -} - -struct gf26t { - int a; - char b[2]; -} gf26v; -void gf26(int x, int y) { - gf26v = ((struct gf26t){x + y, 'z', 0}); // NON_COMPLIANT - compound literal -} - -void gf27() { - int a[6] = {[4] = 29, [2] = 15}; // NON_COMPLIANT in C90. -} - -void gf28() { - int a; - - // switch(a){ - // case: 0 ... 5: // Not supported in clang. - // ;; - // break; - // default: - // ;; - // break; - // } -} - -union gf29u { - int i; - double j; -}; - -void gf29() { - int x; - int y; - union gf29u z; - z = (union gf29u)x; // NON_COMPLIANT - z = (union gf29u)y; // NON_COMPLIANT -} - -__attribute__((access(read_only, 1))) int -gf30(const char *); // NON_COMPLIANT -- attributes are not portable. - -extern int __attribute__((alias("var_target"))) -gf31; // NON_COMPLIANT -- attributes are not portable. - -struct __attribute__((aligned(8))) gf32 { - short f[3]; -}; // NON_COMPLIANT -- attributes are not portable. - -void gf33() { -gf33l: - __attribute__((cold, unused)); // NON_COMPLIANT - return; -} - -enum gf34 { - oldval __attribute__((deprecated)), // NON_COMPLIANT - newval -}; - -void gf35() { - int x; - // __attribute__((assume(x == 42))); - Not supported in clang - - switch (x) { - case 1: - printf(""); - __attribute__((fallthrough)); // NON_COMPLIANT - case 2: - break; - } -} - -// Not supported in clang. -// int gf36 (uid_t); - -// int -// gf36 (int x) -// { -// return x == 0; -// } - -void gf37() { - int a$1; // NON_COMPLIANT -} - -void gf38() { - const char *c = "test\e"; // NON_COMPLIANT -} - -struct gf39s { - int x; - char y; -} gf39v; - -void gf39() { - __alignof__(gf39v.x); // NON_COMPLIANT -} - -// enum gf40 {}; // not supported in clang - -void gf41() { - printf("__FUNCTION__ = %s\n", __FUNCTION__); // NON_COMPLIANT - printf("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); // NON_COMPLIANT -} - -void gf42() { - __builtin_extract_return_addr(0); - __builtin_frob_return_addr(0); - __builtin_frame_address(0); -} - -struct gf43s { - int x; - char y; -} gf43v; - -void gf43() { - __builtin_offsetof(struct gf43s, x); // NON_COMPLIANT -} - -struct gf44s { - int x; - char y; -} gf44v; - -void gf44() { - int i; - __sync_fetch_and_add(&i, 0); // NON_COMPLIANT - __sync_fetch_and_sub(&i, 0); // NON_COMPLIANT - __sync_fetch_and_or(&i, 0); // NON_COMPLIANT - __sync_fetch_and_and(&i, 0); // NON_COMPLIANT - __sync_fetch_and_xor(&i, 0); // NON_COMPLIANT - __sync_fetch_and_nand(&i, 0); // NON_COMPLIANT - __sync_add_and_fetch(&i, 0); // NON_COMPLIANT - __sync_sub_and_fetch(&i, 0); // NON_COMPLIANT - __sync_or_and_fetch(&i, 0); // NON_COMPLIANT - __sync_and_and_fetch(&i, 0); // NON_COMPLIANT - __sync_xor_and_fetch(&i, 0); // NON_COMPLIANT - __sync_nand_and_fetch(&i, 0); // NON_COMPLIANT - - __sync_bool_compare_and_swap(&i, 0, 0); - __sync_val_compare_and_swap(&i, 0, 0); - __sync_lock_test_and_set(&i, 0, 0); - __sync_lock_release(&i, 0); -} - -void gf45() { - int i = 0b101010; // NON_COMPLIANT -} - -__thread int gf46; // NON_COMPLIANT - -void gf47() { // NON_COMPLIANT in versions < C11. - struct { - int a; - union { - int b; - float c; - }; - int d; - } f; -} - -void gf48(){ - __builtin_alloca(0); // NON_COMPLIANT (all __builtin functions are non-compliant.) -} \ No newline at end of file diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json index 2fc720b57d..34afdc2b1b 100644 --- a/rule_packages/c/Language2.json +++ b/rule_packages/c/Language2.json @@ -21,27 +21,6 @@ ], "title": "All usage of assembly language should be documented" }, - "RULE-1-2": { - "properties": { - "obligation": "advisory" - }, - "queries": [ - { - "description": "Language extensions can have inconsistent behavior and should not be used.", - "kind": "problem", - "name": "Language extensions should not be used", - "precision": "high", - "severity": "error", - "short_name": "LanguageExtensionsShouldNotBeUsed", - "tags": [ - "maintainability", - "readability", - "correctness" - ] - } - ], - "title": "Language extensions should not be used" - }, "RULE-1-4": { "properties": { "obligation": "required" diff --git a/rules.csv b/rules.csv index 8031503680..429f9ede8f 100644 --- a/rules.csv +++ b/rules.csv @@ -617,7 +617,7 @@ c,MISRA-C-2012,DIR-4-12,Yes,Required,,,Dynamic memory allocation shall not be us c,MISRA-C-2012,DIR-4-13,Yes,Advisory,,,Functions which are designed to provide operations on a resource should be called in an appropriate sequence,,Contracts,Hard, c,MISRA-C-2012,DIR-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, c,MISRA-C-2012,RULE-1-1,No,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits",,Language,Easy,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." -c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language2,Hard, +c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language3,Hard, c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language3,Hard, c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language2,Medium, c,MISRA-C-2012,RULE-2-1,Yes,Required,,,A project shall not contain unreachable code,M0-1-1,DeadCode,Import, From 92356eb47f4b11562ea65749486334c6f7978eb3 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 18 Nov 2022 17:33:52 -0500 Subject: [PATCH 17/23] removal --- .../cpp/exclusions/c/Language2.qll | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll index 9d270d34be..0217551e59 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Language2.qll @@ -5,7 +5,6 @@ import codingstandards.cpp.exclusions.RuleMetadata newtype Language2Query = TUsageOfAssemblyLanguageShouldBeDocumentedQuery() or - TLanguageExtensionsShouldNotBeUsedQuery() or TEmergentLanguageFeaturesUsedQuery() predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { @@ -17,14 +16,6 @@ predicate isLanguage2QueryMetadata(Query query, string queryId, string ruleId) { "c/misra/usage-of-assembly-language-should-be-documented" and ruleId = "DIR-4-2" or - query = - // `Query` instance for the `languageExtensionsShouldNotBeUsed` query - Language2Package::languageExtensionsShouldNotBeUsedQuery() and - queryId = - // `@id` for the `languageExtensionsShouldNotBeUsed` query - "c/misra/language-extensions-should-not-be-used" and - ruleId = "RULE-1-2" - or query = // `Query` instance for the `emergentLanguageFeaturesUsed` query Language2Package::emergentLanguageFeaturesUsedQuery() and @@ -42,13 +33,6 @@ module Language2Package { TQueryC(TLanguage2PackageQuery(TUsageOfAssemblyLanguageShouldBeDocumentedQuery())) } - Query languageExtensionsShouldNotBeUsedQuery() { - //autogenerate `Query` type - result = - // `Query` type for `languageExtensionsShouldNotBeUsed` query - TQueryC(TLanguage2PackageQuery(TLanguageExtensionsShouldNotBeUsedQuery())) - } - Query emergentLanguageFeaturesUsedQuery() { //autogenerate `Query` type result = From c6b41b3e4da2eaf3a385bc0665dc00d4ed2f9504 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 18 Nov 2022 17:42:49 -0500 Subject: [PATCH 18/23] package surgery --- rules.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules.csv b/rules.csv index 429f9ede8f..f6b1e42b0b 100644 --- a/rules.csv +++ b/rules.csv @@ -600,7 +600,7 @@ c,CERT-C,STR37-C,Yes,Rule,,,Arguments to character-handling functions must be re c,CERT-C,STR38-C,Yes,Rule,,,Do not confuse narrow and wide character strings and functions,,Strings3,Medium, c,CERT-C,WIN30-C,OutOfScope,Rule,,,Properly pair allocation and deallocation functions,DCL54-CPP,,Easy, c,MISRA-C-2012,DIR-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, -c,MISRA-C-2012,DIR-2-1,No,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." +c,MISRA-C-2012,DIR-2-1,No,Required,,,All source files shall compile without any compilation errors,A1-4-3,,Medium,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." c,MISRA-C-2012,DIR-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, c,MISRA-C-2012,DIR-4-1,No,Required,,,Run-time failures shall be minimized,,,, c,MISRA-C-2012,DIR-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language2,Import, @@ -616,7 +616,7 @@ c,MISRA-C-2012,DIR-4-11,Yes,Required,,,The validity of values passed to library c,MISRA-C-2012,DIR-4-12,Yes,Required,,,Dynamic memory allocation shall not be used,,Banned,Medium, c,MISRA-C-2012,DIR-4-13,Yes,Advisory,,,Functions which are designed to provide operations on a resource should be called in an appropriate sequence,,Contracts,Hard, c,MISRA-C-2012,DIR-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, -c,MISRA-C-2012,RULE-1-1,No,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits",,Language,Easy,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." +c,MISRA-C-2012,RULE-1-1,No,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits",,,Easy,"This should be checked via the compiler output, rather than CodeQL, which adds unnecessary steps." c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language3,Hard, c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language3,Hard, c,MISRA-C-2012,RULE-1-4,Yes,Required,,,Emergent language features shall not be used,,Language2,Medium, From b144d5cd8293b7aaac88fda435a3a5c37072fa54 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Mon, 21 Nov 2022 11:21:46 -0500 Subject: [PATCH 19/23] formatting --- .../src/codingstandards/cpp/Emergent.qll | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/Emergent.qll b/cpp/common/src/codingstandards/cpp/Emergent.qll index 53f7e5599b..9036c12bd7 100644 --- a/cpp/common/src/codingstandards/cpp/Emergent.qll +++ b/cpp/common/src/codingstandards/cpp/Emergent.qll @@ -1,49 +1,49 @@ -import cpp +import cpp /** - * Namespace for containing emergent language features in C11. + * 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" - } + 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 GenericMacro extends EmergentLanguageFeature, Macro { - GenericMacro() { getBody().indexOf("_Generic") = 0 } + } + + 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 NoReturnSpecificer extends EmergentLanguageFeature, Function { - NoReturnSpecificer() { getASpecifier().getName() = "noreturn" } + } + + class LibExt1Macro extends EmergentLanguageFeature, Macro { + LibExt1Macro() { + getName() = "__STDC_WANT_LIB_EXT1__" and + getBody() = "1" } - - class AlignOf extends EmergentLanguageFeature, AlignofTypeOperator { } - } \ No newline at end of file + } + + class GenericMacro extends EmergentLanguageFeature, Macro { + GenericMacro() { getBody().indexOf("_Generic") = 0 } + } + + class NoReturnSpecificer extends EmergentLanguageFeature, Function { + NoReturnSpecificer() { getASpecifier().getName() = "noreturn" } + } + + class AlignOf extends EmergentLanguageFeature, AlignofTypeOperator { } +} From cb9596c60606a1a7af486c08cd10e80d27a4e11a Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Mon, 21 Nov 2022 16:24:42 -0500 Subject: [PATCH 20/23] removed identical test case --- .../UsageOfAssemblerNotDocumented.expected | 1 - .../UsageOfAssemblerNotDocumented.ql | 2 -- .../test/rules/usageofassemblernotdocumented/test.c | 12 ------------ ...UsageOfAssemblyLanguageShouldBeDocumented.testref | 2 +- 4 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected delete mode 100644 c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql delete mode 100644 c/common/test/rules/usageofassemblernotdocumented/test.c diff --git a/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected b/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected deleted file mode 100644 index 8c132cdb91..0000000000 --- a/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.expected +++ /dev/null @@ -1 +0,0 @@ -| test.c:8:42:8:58 | asm statement | Use of assembler is not documented. | diff --git a/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql b/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql deleted file mode 100644 index 7f9e1041a2..0000000000 --- a/c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql +++ /dev/null @@ -1,2 +0,0 @@ -// GENERATED FILE - DO NOT MODIFY -import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented diff --git a/c/common/test/rules/usageofassemblernotdocumented/test.c b/c/common/test/rules/usageofassemblernotdocumented/test.c deleted file mode 100644 index 16e0f9ca91..0000000000 --- a/c/common/test/rules/usageofassemblernotdocumented/test.c +++ /dev/null @@ -1,12 +0,0 @@ -// 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; } \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref b/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref index 3b0dc2fe5a..ea9ce384ea 100644 --- a/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref +++ b/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref @@ -1 +1 @@ -c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql \ No newline at end of file +cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql \ No newline at end of file From 501ecef7e18da6b727b40c776fe18e8591f8a0e1 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Mon, 21 Nov 2022 16:45:57 -0500 Subject: [PATCH 21/23] fix --- .../DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql | 2 +- c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql | 2 +- rule_packages/c/Language2.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql index 250d98892c..95388b46bc 100644 --- a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql +++ b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql @@ -1,7 +1,7 @@ /** * @id c/misra/usage-of-assembly-language-should-be-documented * @name DIR-4-2: All usage of assembly language should be documented - * @description + * @description Assembly language is not portable and should be documented. * @kind problem * @precision very-high * @problem.severity error diff --git a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql index e9a5591f61..e5c55d4fc5 100644 --- a/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql +++ b/c/misra/src/rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql @@ -4,7 +4,7 @@ * @description Emergent language features may have unpredictable behavior and should not be used. * @kind problem * @precision very-high - * @problem.severity error + * @problem.severity warning * @tags external/misra/id/rule-1-4 * maintainability * readability diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json index 34afdc2b1b..7f25091ab6 100644 --- a/rule_packages/c/Language2.json +++ b/rule_packages/c/Language2.json @@ -6,7 +6,7 @@ }, "queries": [ { - "description": "", + "description": "Assembly language is not portable and should be documented.", "kind": "problem", "name": "All usage of assembly language should be documented", "precision": "very-high", @@ -31,7 +31,7 @@ "kind": "problem", "name": "Emergent language features shall not be used", "precision": "very-high", - "severity": "error", + "severity": "warning", "short_name": "EmergentLanguageFeaturesUsed", "tags": [ "maintainability", From 0c9c40a81d92e399ab080723e76817f077ea6ffd Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 22 Nov 2022 11:06:23 -0500 Subject: [PATCH 22/23] warning --- .../rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql | 2 +- rule_packages/c/Language2.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql index 95388b46bc..d1a8a80046 100644 --- a/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql +++ b/c/misra/src/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.ql @@ -4,7 +4,7 @@ * @description Assembly language is not portable and should be documented. * @kind problem * @precision very-high - * @problem.severity error + * @problem.severity warning * @tags external/misra/id/dir-4-2 * maintainability * readability diff --git a/rule_packages/c/Language2.json b/rule_packages/c/Language2.json index 7f25091ab6..66f219a025 100644 --- a/rule_packages/c/Language2.json +++ b/rule_packages/c/Language2.json @@ -10,7 +10,7 @@ "kind": "problem", "name": "All usage of assembly language should be documented", "precision": "very-high", - "severity": "error", + "severity": "warning", "short_name": "UsageOfAssemblyLanguageShouldBeDocumented", "shared_implementation_short_name": "UsageOfAssemblerNotDocumented", "tags": [ From c48658f12905353576d7092da8d71a4477f13b5f Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 22 Nov 2022 11:06:41 -0500 Subject: [PATCH 23/23] adding back --- c/misra/test/rules/RULE-1-4/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/misra/test/rules/RULE-1-4/test.c b/c/misra/test/rules/RULE-1-4/test.c index 7b31e6a555..153c722c94 100644 --- a/c/misra/test/rules/RULE-1-4/test.c +++ b/c/misra/test/rules/RULE-1-4/test.c @@ -12,7 +12,7 @@ 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] + int i0 = _Generic(p, int : 0, long : 1); // NON_COMPLIANT[FALSE_NEGATIVE] _Atomic int i; // NON_COMPLIANT