Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 41 additions & 17 deletions Fw/Types/Assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Fw/Types/format.hpp>
#include <cassert>
#include <cstdio>
#include <cstdlib>

#if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
#define fileIdFs "Assert: 0x%08" PRIx32 ":%" PRI_FwSizeType ""
Expand Down Expand Up @@ -105,15 +106,15 @@
}

// Default handler of SwAssert functions
I8 defaultSwAssert(FILE_NAME_ARG file,
FwSizeType lineNo,
FwSizeType numArgs,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6) {
FW_ASSERT_NORETURN void defaultSwAssert(FILE_NAME_ARG file,

Check notice

Code scanning / CodeQL

Use of basic integral type Note

file uses the basic integral type char rather than a typedef with size and signedness.

Check notice

Code scanning / CodeQL

Function too long Note

defaultSwAssert has too many parameters (9, while 6 are allowed).
FwSizeType lineNo,
FwSizeType numArgs,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6) {
if (nullptr == s_assertHook) {
CHAR assertMsg[FW_ASSERT_TEXT_SIZE];
defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, assertMsg,
Expand All @@ -124,23 +125,37 @@
s_assertHook->reportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6);
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.
abort();
#endif
}

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);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}

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);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}

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);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg2 has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}

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);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg3 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg2 has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}

I8 SwAssert(FILE_NAME_ARG file,
Expand All @@ -149,7 +164,10 @@
FwAssertArgType arg3,
FwAssertArgType arg4,
FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0);
defaultSwAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg2 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg3 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg4 has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}

I8 SwAssert(FILE_NAME_ARG file,
Expand All @@ -159,7 +177,10 @@
FwAssertArgType arg4,
FwAssertArgType arg5,
FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0);
defaultSwAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg2 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg3 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg4 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg5 has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}

I8 SwAssert(FILE_NAME_ARG file,
Expand All @@ -170,7 +191,10 @@
FwAssertArgType arg5,
FwAssertArgType arg6,
FwSizeType lineNo) {
return defaultSwAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6);
defaultSwAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6);

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg2 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg1 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter lineNo has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter file has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg6 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg5 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg4 has not been checked.

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter arg3 has not been checked.
#if !FW_ASSERTIONS_ALWAYS_ABORT

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
return 0;
#endif
}
} // namespace Fw

Expand Down
24 changes: 14 additions & 10 deletions Fw/Types/Assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@
#define FW_ASSERT_NO_OVERFLOW(value, T) \
FW_ASSERT((value) <= std::numeric_limits<T>::max(), static_cast<FwAssertArgType>(value))

#if FW_ASSERTIONS_ALWAYS_ABORT
#define FW_ASSERT_NORETURN __attribute__((noreturn))
#endif

// F' Assertion functions can technically return even though the intention is for the assertion to terminate the
// program. This breaks static analysis depending on assertions, since the analyzer has to assume the assertion will
// return. When supported, annotate assertion functions as noreturn when statically analyzing.
#ifndef CLANG_ANALYZER_NORETURN
#ifndef FW_ASSERT_NORETURN
#ifndef __has_feature
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
#if __has_feature(attribute_analyzer_noreturn)
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
#define FW_ASSERT_NORETURN __attribute__((analyzer_noreturn))
#else
#define CLANG_ANALYZER_NORETURN
#define FW_ASSERT_NORETURN
#endif
#endif

Expand All @@ -79,31 +83,31 @@

namespace Fw {
//! Assert with no arguments
I8 SwAssert(FILE_NAME_ARG file, FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
I8 SwAssert(FILE_NAME_ARG file, FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;

//! Assert with one argument
I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
I8 SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;

//! Assert with two arguments
I8 SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;

//! Assert with three arguments
I8 SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;

//! Assert with four arguments
I8 SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg1,
FwAssertArgType arg2,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;

//! Assert with five arguments
I8 SwAssert(FILE_NAME_ARG file,
Expand All @@ -112,7 +116,7 @@ I8 SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg3,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;

//! Assert with six arguments
I8 SwAssert(FILE_NAME_ARG file,
Expand All @@ -122,7 +126,7 @@ I8 SwAssert(FILE_NAME_ARG file,
FwAssertArgType arg4,
FwAssertArgType arg5,
FwAssertArgType arg6,
FwSizeType lineNo) NOINLINE CLANG_ANALYZER_NORETURN;
FwSizeType lineNo) NOINLINE FW_ASSERT_NORETURN;
} // namespace Fw

// Base class for declaring an assert hook
Expand Down
8 changes: 8 additions & 0 deletions default/config/FpConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ extern "C" {
#define FW_ASSERT_LEVEL (FW_FILENAME_ASSERT) //!< Defines the type of assert used
#endif

// Decide whether the framework should force assertions to always abort.
// If enabled, allows additional compiler optimizations and prevents code from running after an assertion trips.
// If disabled (default), allows the FATAL event handler to decide whether code should continue running after an
// assertion trips.
#ifndef FW_ASSERTIONS_ALWAYS_ABORT
#define FW_ASSERTIONS_ALWAYS_ABORT 0
#endif

// Adjust various configuration parameters in the architecture. Some of the above enables may disable some of the values

// The size of the object name stored in the object base class. Larger names will be truncated.
Expand Down
Loading