Skip to content

Add option to force assertions to always abort#4677

Open
celskeggs wants to merge 3 commits intonasa:develfrom
celskeggs:patch-26
Open

Add option to force assertions to always abort#4677
celskeggs wants to merge 3 commits intonasa:develfrom
celskeggs:patch-26

Conversation

@celskeggs
Copy link
Collaborator

@celskeggs celskeggs commented Jan 31, 2026

Related Issue(s) n/a
Has Unit Tests (y/n) n
Documentation Included (y/n) y
Generative AI was used in this contribution (y/n) n

Change Description

Add an option to let projects decide whether the framework should force assertions to always abort.

If enabled, this option allows prevents code from running after an assertion trips. This enables additional compiler optimizations.

If disabled, this option allows the FATAL event handler to decide whether code should continue running after an assertion trips. This is the default and is consistent with the existing assertion behavior in F Prime. Therefore, users should not observe any change in behavior unless they make the decision to change the configuration.

Rationale

When assertions have the possibility of returning, the compiler needs to generate code for that case. This code can in some cases be complex enough to prevent inlining of otherwise short functions when under -Os. This can result in increased code size and performance degradation.

The existing default behavior is important for projects that need the ability to disable abort-on-FATAL and abort-on-ASSERT at runtime. However, just because this behavior is needed for some projects, does not mean it should be required for all projects.

While the ability to provide alternative assertion hooks is valuable, it is insufficient, as it is often not possible for the compiler to predict the assertion hook that will be used at compile time. The compiler needs to be confident that Fw::SwAssert cannot return at the point of each use.

Testing/Review Recommendations

Please consider whether the newly introduced option has the right name and description.

Future Work

None in particular.

AI Usage (see policy)

Not used.

s_assertHook->doAssert();
}
return 0;
#if FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
I8 SwAssert(FILE_NAME_ARG file, FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0);
defaultSwAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0);
defaultSwAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 2, arg1, arg2, 0, 0, 0, 0);
defaultSwAssert(file, lineNo, 2, arg1, arg2, 0, 0, 0, 0);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 3, arg1, arg2, arg3, 0, 0, 0);
defaultSwAssert(file, lineNo, 3, arg1, arg2, arg3, 0, 0, 0);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0);
defaultSwAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0);
defaultSwAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6);
defaultSwAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6);
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6) {
FW_ASSERT_NORETURN void defaultSwAssert(FILE_NAME_ARG file,

Check notice

Code scanning / CodeQL

Function too long Note

defaultSwAssert has too many parameters (9, while 6 are allowed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant