Skip to content

First pass at addressing cross-compiler compatibility in MISRA 2023. #884

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format c tests, c ql files
  • Loading branch information
MichaelRFairhurst committed Apr 8, 2025
commit 8f521a56d661d919ed519f3112a2ecc9d680b9f5
Original file line number Diff line number Diff line change
@@ -34,7 +34,9 @@ string getAllowedTypesString(TgMathInvocation call) {
else result = "essentially signed, unsigned, or real floating type"
}

from TgMathInvocation call, Expr convertedArg, Expr unconverted, int argIndex, Type type, EssentialTypeCategory category
from
TgMathInvocation call, Expr convertedArg, Expr unconverted, int argIndex, Type type,
EssentialTypeCategory category
where
not isExcluded(call, EssentialTypes2Package::tgMathArgumentWithInvalidEssentialTypeQuery()) and
// We must handle conversions specially, as clang inserts casts in the macro body we want to ignore.
Original file line number Diff line number Diff line change
@@ -58,9 +58,7 @@ Type canonicalize(Type type) {
else result = type
}

Type getEffectiveStandardType(Expr e) {
result = canonicalize(getPromotedType(e))
}
Type getEffectiveStandardType(Expr e) { result = canonicalize(getPromotedType(e)) }

from TgMathInvocation call, Type firstType
where
4 changes: 1 addition & 3 deletions c/misra/src/rules/RULE-21-25/InvalidMemoryOrderArgument.ql
Original file line number Diff line number Diff line change
@@ -77,9 +77,7 @@ module MemoryOrderFlowConfig implements DataFlow::ConfigSig {
}

predicate isSink(DataFlow::Node node) {
exists(AtomicallySequencedCall call |
call.getAMemoryOrderArgument() = node.asExpr()
)
exists(AtomicallySequencedCall call | call.getAMemoryOrderArgument() = node.asExpr())
}
}

6 changes: 3 additions & 3 deletions c/misra/test/rules/RULE-18-10/test.c
Original file line number Diff line number Diff line change
@@ -57,9 +57,9 @@ void f1(
} p20,

// Unknown array length types:
int p21[], // COMPLIANT
int p22[][2], // COMPLIANT
int (*p23)[], // COMPLIANT
int p21[], // COMPLIANT
int p22[][2], // COMPLIANT
int (*p23)[], // COMPLIANT
// int (*p24)[2][], // doesn't compile
int (*p25)[][2], // COMPLIANT

2 changes: 1 addition & 1 deletion c/misra/test/rules/RULE-18-8/test.c
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ void f1(int n,
int p1[n], // COMPLIANT
// Pointers to variably-modified types are not VLAs.
int p2[n][n],
int p3[], // array of unknown length is converted to pointer
int p3[], // array of unknown length is converted to pointer
int p4[][n] // array of unknown length are not VLAs.
) {}

8 changes: 4 additions & 4 deletions c/misra/test/rules/RULE-21-22/test.c
Original file line number Diff line number Diff line change
@@ -322,8 +322,8 @@ void f1() {
remquo(i, i, c); // COMPLIANT

/* Test casts */
cos((char) i); // NON-COMPLIANT
cos((int) c); // COMPLIANT
cos((int) (char) i); // COMPLIANT
cos((char) (int) c); // NON-COMPLIANT
cos((char)i); // NON-COMPLIANT
cos((int)c); // COMPLIANT
cos((int)(char)i); // COMPLIANT
cos((char)(int)c); // NON-COMPLIANT
}
68 changes: 34 additions & 34 deletions c/misra/test/rules/RULE-21-25/test.c
Original file line number Diff line number Diff line change
@@ -21,52 +21,52 @@ void f(int p) {
atomic_load_explicit(&l1, memory_order_release); // NON-COMPLIANT

// Implicit values:
atomic_store(&l1, 0); // COMPLIANT
atomic_load(&l1); // COMPLIANT
atomic_flag_test_and_set(&l2); // COMPLIANT
atomic_flag_clear(&l2); // COMPLIANT
atomic_exchange(&l1, 0); // COMPLIANT
atomic_store(&l1, 0); // COMPLIANT
atomic_load(&l1); // COMPLIANT
atomic_flag_test_and_set(&l2); // COMPLIANT
atomic_flag_clear(&l2); // COMPLIANT
atomic_exchange(&l1, 0); // COMPLIANT
atomic_compare_exchange_strong(&l1, ptr, 1); // COMPLIANT
atomic_compare_exchange_weak(&l1, ptr, 1); // COMPLIANT
atomic_fetch_add(&l1, 0); // COMPLIANT
atomic_fetch_sub(&l1, 0); // COMPLIANT
atomic_fetch_or(&l1, 0); // COMPLIANT
atomic_fetch_xor(&l1, 0); // COMPLIANT
atomic_fetch_and(&l1, 0); // COMPLIANT
atomic_fetch_add(&l1, 0); // COMPLIANT
atomic_fetch_sub(&l1, 0); // COMPLIANT
atomic_fetch_or(&l1, 0); // COMPLIANT
atomic_fetch_xor(&l1, 0); // COMPLIANT
atomic_fetch_and(&l1, 0); // COMPLIANT

// Compliant flowed values (one test per sink):
atomic_store_explicit(&l1, 0, g1); // COMPLIANT
atomic_load_explicit(&l1, g1); // COMPLIANT
atomic_flag_test_and_set_explicit(&l2, g1); // COMPLIANT
atomic_flag_clear_explicit(&l2, g1); // COMPLIANT
atomic_exchange_explicit(&l1, 0, g1); // COMPLIANT
atomic_store_explicit(&l1, 0, g1); // COMPLIANT
atomic_load_explicit(&l1, g1); // COMPLIANT
atomic_flag_test_and_set_explicit(&l2, g1); // COMPLIANT
atomic_flag_clear_explicit(&l2, g1); // COMPLIANT
atomic_exchange_explicit(&l1, 0, g1); // COMPLIANT
atomic_compare_exchange_strong_explicit(&l1, ptr, 1, g1, g1); // COMPLIANT
atomic_compare_exchange_weak_explicit(&l1, ptr, 1, g1, g1); // COMPLIANT
atomic_fetch_add_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_sub_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_or_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_xor_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_and_explicit(&l1, 0, g1); // COMPLIANT
atomic_thread_fence(g1); // COMPLIANT
atomic_signal_fence(g1); // COMPLIANT
atomic_fetch_add_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_sub_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_or_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_xor_explicit(&l1, 0, g1); // COMPLIANT
atomic_fetch_and_explicit(&l1, 0, g1); // COMPLIANT
atomic_thread_fence(g1); // COMPLIANT
atomic_signal_fence(g1); // COMPLIANT

// Non-compliant flowed values (one test per sink):
atomic_store_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_load_explicit(&l1, g2); // NON-COMPLIANT
atomic_flag_test_and_set_explicit(&l2, g2); // NON-COMPLIANT
atomic_flag_clear_explicit(&l2, g2); // NON-COMPLIANT
atomic_exchange_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_store_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_load_explicit(&l1, g2); // NON-COMPLIANT
atomic_flag_test_and_set_explicit(&l2, g2); // NON-COMPLIANT
atomic_flag_clear_explicit(&l2, g2); // NON-COMPLIANT
atomic_exchange_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_compare_exchange_strong_explicit(&l1, ptr, 1, g2, g1); // NON-COMPLIANT
atomic_compare_exchange_strong_explicit(&l1, ptr, 1, g1, g2); // NON-COMPLIANT
atomic_compare_exchange_weak_explicit(&l1, ptr, 1, g2, g1); // NON-COMPLIANT
atomic_compare_exchange_weak_explicit(&l1, ptr, 1, g1, g2); // NON-COMPLIANT
atomic_fetch_add_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_sub_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_or_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_xor_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_and_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_thread_fence(g2); // NON-COMPLIANT
atomic_signal_fence(g2); // NON-COMPLIANT
atomic_fetch_add_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_sub_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_or_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_xor_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_fetch_and_explicit(&l1, 0, g2); // NON-COMPLIANT
atomic_thread_fence(g2); // NON-COMPLIANT
atomic_signal_fence(g2); // NON-COMPLIANT

// Non-compliant flowed values (one test per source):
atomic_thread_fence(g2); // NON-COMPLIANT
Loading
Oops, something went wrong.