Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#1896 from ApexAI/iox-1394-fix-axiv…
Browse files Browse the repository at this point in the history
…ion-warnings-for-multiple-files

iox-1394 fix axivion warnings for multiple files
  • Loading branch information
elBoberido authored Feb 15, 2023
2 parents b7e88f0 + 19784fa commit 697adc9
Show file tree
Hide file tree
Showing 22 changed files with 205 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace iox
template <uint64_t N>
struct FromImpl<string<N>, std::string>
{
static std::string fromImpl(const string<N>& value);
static std::string fromImpl(const string<N>& value) noexcept;
};

template <uint64_t N>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace iox
{
template <uint64_t N>
inline std::string FromImpl<string<N>, std::string>::fromImpl(const string<N>& value)
inline std::string FromImpl<string<N>, std::string>::fromImpl(const string<N>& value) noexcept
{
return std::string(value.c_str(), value.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ template <typename StringType>
inline const ValueType& ExpectWithValue<Derived, ValueType>::expect(const StringType& msg) const& noexcept
{
using Self = ExpectWithValue<Derived, ValueType>;
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const_cast avoids code duplication, is safe since the constness
// of the return value is restored
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const_cast avoids code duplication, is safe since the constness of the return value is restored
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<const ValueType&>(const_cast<Self*>(this)->expect(msg));
}
Expand All @@ -84,8 +83,7 @@ template <typename StringType>
inline const ValueType&& ExpectWithValue<Derived, ValueType>::expect(const StringType& msg) const&& noexcept
{
using Self = ExpectWithValue<Derived, ValueType>;
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const_cast avoids code duplication, is safe since the constness
// of the return value is restored
// AXIVION Next Construct AutosarC++19_03-A5.2.3 : const_cast avoids code duplication, is safe since the constness of the return value is restored
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<const ValueType&&>(std::move(const_cast<Self*>(this)->expect(msg)));
}
Expand Down
4 changes: 3 additions & 1 deletion iceoryx_hoofs/include/iceoryx_hoofs/cxx/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct range
range(T t) noexcept
: m_value(t)
{
// AXIVION Next Construct AutosarC++19_03-A1.4.3 : False positive! 't >= Minimum' depends on input parameter
cxx::Expects((t >= Minimum) && (t <= Maximum));
}

Expand All @@ -216,7 +217,8 @@ template <typename T>
constexpr bool isPowerOfTwo(const T n) noexcept
{
static_assert(std::is_unsigned<T>::value && !std::is_same<T, bool>::value, "Only unsigned integer are allowed!");
return n && ((n & (n - 1U)) == 0U);
// AXIVION Next Construct AutosarC++19_03-M0.1.2, AutosarC++19_03-M0.1.9, FaultDetection-DeadBranches : False positive! 'n' can be zero.
return (n > 0) && ((n & (n - 1U)) == 0U);
}
} // namespace iox

Expand Down
1 change: 1 addition & 0 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace internal
/// compiler an unused variable. "static_cast" produces an useless-cast warning
/// on gcc and this approach solves it cleanly.
template <typename T>
// AXIVION Next Construct AutosarC++19_03-M0.1.8 : No side effects are the intended behavior of the function
inline void IOX_DISCARD_RESULT_IMPL(T&&) noexcept
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ inline T* RelativePointer<T>::getPtr(const segment_id_t id, const offset_t offse
return nullptr;
}
const auto* const basePtr = getBasePtr(id);
// AXIVION Next Construct AutosarC++19_03-A5.2.4, AutosarC++19_03-M5.2.8, AutosarC++19_03-M5.2.6, AutosarC++19_03-M5.2.9 : Cast
// needed for pointer arithmetic
// AXIVION Next Construct AutosarC++19_03-A5.2.4, AutosarC++19_03-M5.2.8, AutosarC++19_03-M5.2.6, AutosarC++19_03-M5.2.9 : Cast needed for pointer arithmetic
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast, performance-no-int-to-ptr)
return reinterpret_cast<ptr_t>(offset + reinterpret_cast<offset_t>(basePtr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct PosixCallDetails
/// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define posixCall(f) \
internal::createPosixCallBuilder( \
f, \
&(f), \
(#f), \
__FILE__, \
__LINE__, \
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/memory/include/iox/bump_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BumpAllocator
void deallocate() noexcept;

private:
cxx::byte_t* m_startAddress{nullptr};
uint64_t m_startAddress{0U};
uint64_t m_length{0U};
uint64_t m_currentPosition{0U};
};
Expand Down
9 changes: 6 additions & 3 deletions iceoryx_hoofs/memory/include/iox/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace iox
/// @note value + alignment - 1 must not exceed the maximum value for type T
/// @note alignment must be a power of two
template <typename T>
// AXIVION Next Construct AutosarC++19_03-A2.10.5, AutosarC++19_03-M17.0.3: The function is in the 'iox' namespace which prevents easy misuse
// AXIVION Next Construct AutosarC++19_03-A2.10.5, AutosarC++19_03-M17.0.3 : The function is in the 'iox' namespace which prevents easy misuse
T align(const T value, const T alignment) noexcept
{
return (value + (alignment - 1)) & (-alignment);
return (value + (alignment - 1)) & (~alignment + 1);
}

/// @brief allocates aligned memory which can only be free'd by alignedFree
Expand All @@ -45,16 +45,19 @@ void alignedFree(void* const memory) noexcept;

/// template recursion stopper for maximum alignment calculation
template <std::size_t S = 0>
// AXIVION Next Construct AutosarC++19_03-A2.10.5 : The function is in the 'iox' namespace which prevents easy misuse
constexpr std::size_t maxAlignment() noexcept
{
return S;
}

/// calculate maximum alignment of supplied types
template <typename T, typename... Args>
// AXIVION Next Construct AutosarC++19_03-A2.10.5 : The function is in the 'iox' namespace which prevents easy misuse
constexpr std::size_t maxAlignment() noexcept
{
return (alignof(T) > maxAlignment<Args...>()) ? alignof(T) : maxAlignment<Args...>();
auto remainingMaxAlignment = maxAlignment<Args...>();
return (alignof(T) > remainingMaxAlignment) ? alignof(T) : remainingMaxAlignment;
}

/// template recursion stopper for maximum size calculation
Expand Down
24 changes: 13 additions & 11 deletions iceoryx_hoofs/memory/source/bump_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
namespace iox
{
BumpAllocator::BumpAllocator(void* const startAddress, const uint64_t length) noexcept
: m_startAddress(static_cast<cxx::byte_t*>(startAddress))
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : required for low level memory management
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
: m_startAddress(reinterpret_cast<uint64_t>(startAddress))
, m_length(length)
{
}
Expand All @@ -40,20 +42,20 @@ cxx::expected<void*, BumpAllocatorError> BumpAllocator::allocate(const uint64_t
return cxx::error<BumpAllocatorError>(BumpAllocatorError::REQUESTED_ZERO_SIZED_MEMORY);
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) required for low level pointer alignment
uint64_t currentAddress = reinterpret_cast<uint64_t>(m_startAddress) + m_currentPosition;
uint64_t alignedPosition = align(currentAddress, static_cast<uint64_t>(alignment));
const uint64_t currentAddress{m_startAddress + m_currentPosition};
uint64_t alignedPosition{align(currentAddress, alignment)};

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) required for low level pointer alignment
alignedPosition -= reinterpret_cast<uint64_t>(m_startAddress);
alignedPosition -= m_startAddress;

cxx::byte_t* allocation = nullptr;
void* allocation{nullptr};

if (m_length >= alignedPosition + size)
auto nextPosition = alignedPosition + size;
if (m_length >= nextPosition)
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) low-level memory management
allocation = m_startAddress + alignedPosition;
m_currentPosition = alignedPosition + size;
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : required for low level memory management
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast, performance-no-int-to-ptr)
allocation = reinterpret_cast<void*>(m_startAddress + alignedPosition);
m_currentPosition = nextPosition;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/primitives/include/iox/size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace iox
/// @param[in] The actual content of the array is not of interest. Its just the capacity of the array that matters.
/// @return Returns the capacity of the array at compile time.
template <typename T, uint64_t CapacityValue>
// AXIVION Next Construct AutosarC++19_03-A18.1.1:returning capacity of C array at compile time is safe, no
// possibility of out of bounds access
// AXIVION Next Construct AutosarC++19_03-A2.10.5, AutosarC++19_03-M17.0.3 : The function is in the 'iox' namespace which prevents easy misuse
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : returning capacity of C array at compile time is safe, no possibility of out of bounds access
// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
static constexpr uint64_t size(T const (&/*notInterested*/)[CapacityValue]) noexcept
{
Expand Down
66 changes: 54 additions & 12 deletions iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "test.hpp"
#include <ctime>
#include <iostream>
#include <limits>
#include <ostream>

namespace
Expand Down Expand Up @@ -2071,6 +2072,18 @@ TEST(Duration_test, MultiplyDurationMoreThanOneSecondWithFloatResultsInMoreThanO
multiply(duration, MULTIPLICATOR, EXPECTED_DURATION);
}

TEST(Duration_test, MultiplyDurationWithSelfAssignOperatorWorks)
{
::testing::Test::RecordProperty("TEST_ID", "ac7e2f7e-984b-4aca-a472-9dc1f1c1f30c");
constexpr int64_t MULTIPLICATOR{3};
constexpr Duration EXPECTED_DURATION{6_s + 36_ns};
auto duration = 2_s + 12_ns;

duration *= MULTIPLICATOR;

EXPECT_THAT(duration, Eq(EXPECTED_DURATION));
}

TEST(Duration_test, MultiplyDurationWithFractionalFloat)
{
::testing::Test::RecordProperty("TEST_ID", "3adcaec4-06fb-4ae5-a05b-70764fc00d64");
Expand Down Expand Up @@ -2138,40 +2151,69 @@ TEST(Duration_test, MultiplyDurationResultsInSaturationDueToNanoseconds)
EXPECT_THAT(DURATION * MULTIPLICATOR, Eq(DurationAccessor::max()));
}

TEST(Duration_test, MultiplyZeroDurationWithNaNDoubleResultsInZeroDuration)
TEST(Duration_test, MultiplyZeroDurationWithQuietNaNResultsInZeroDuration)
{
::testing::Test::RecordProperty("TEST_ID", "4639ac39-639f-4df9-b591-05714f1cbc30");
EXPECT_THAT(0_s * NAN, Eq(0_s));
EXPECT_THAT(0_s * std::numeric_limits<float>::quiet_NaN(), Eq(0_s));
EXPECT_THAT(0_s * std::numeric_limits<double>::quiet_NaN(), Eq(0_s));
EXPECT_THAT(0_s * std::numeric_limits<long double>::quiet_NaN(), Eq(0_s));
}

TEST(Duration_test, MultiplyMaxDurationWithNaNDoubleResultsInMaxDuration)
TEST(Duration_test, MultiplyMaxDurationWithQuietNaNResultsInMaxDuration)
{
::testing::Test::RecordProperty("TEST_ID", "e09e4248-284d-4ab7-993b-1474ac5e3b11");
EXPECT_THAT(DurationAccessor::max() * NAN, Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<float>::quiet_NaN(), Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<double>::quiet_NaN(), Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<long double>::quiet_NaN(), Eq(DurationAccessor::max()));
}

TEST(Duration_test, MultiplyZeroDurationWithSignalingNaNResultsInZeroDuration)
{
::testing::Test::RecordProperty("TEST_ID", "5007488d-43e8-456b-97b5-f00832a6b5cf");
EXPECT_THAT(0_s * std::numeric_limits<float>::signaling_NaN(), Eq(0_s));
EXPECT_THAT(0_s * std::numeric_limits<double>::signaling_NaN(), Eq(0_s));
EXPECT_THAT(0_s * std::numeric_limits<long double>::signaling_NaN(), Eq(0_s));
}

TEST(Duration_test, MultiplyMaxDurationWithSignalingNaNResultsInMaxDuration)
{
::testing::Test::RecordProperty("TEST_ID", "80e0e30c-6fc2-41d6-a46e-63f6d5ade869");
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<float>::signaling_NaN(), Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<double>::signaling_NaN(), Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<long double>::signaling_NaN(),
Eq(DurationAccessor::max()));
}

TEST(Duration_test, MultiplyZeroDurationWithPosInfDoubleResultsInZeroDuration)
TEST(Duration_test, MultiplyZeroDurationWithPosInfResultsInZeroDuration)
{
::testing::Test::RecordProperty("TEST_ID", "71dea32f-1200-4df2-8eff-ea607f1b6a01");
EXPECT_THAT(0_s * INFINITY, Eq(0_ns));
EXPECT_THAT(0_s * std::numeric_limits<float>::infinity(), Eq(0_ns));
EXPECT_THAT(0_s * std::numeric_limits<double>::infinity(), Eq(0_ns));
EXPECT_THAT(0_s * std::numeric_limits<long double>::infinity(), Eq(0_ns));
}

TEST(Duration_test, MultiplyMaxDurationWithPosInfDoubleResultsInMaxDuration)
TEST(Duration_test, MultiplyMaxDurationWithPosInfResultsInMaxDuration)
{
::testing::Test::RecordProperty("TEST_ID", "5f66a93a-2df1-4f7d-abbf-03d5424a1534");
EXPECT_THAT(DurationAccessor::max() * INFINITY, Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<float>::infinity(), Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<double>::infinity(), Eq(DurationAccessor::max()));
EXPECT_THAT(DurationAccessor::max() * std::numeric_limits<long double>::infinity(), Eq(DurationAccessor::max()));
}

TEST(Duration_test, MultiplyZeroDurationWithNegInfDoubleResultsInZeroDuration)
TEST(Duration_test, MultiplyZeroDurationWithNegInfResultsInZeroDuration)
{
::testing::Test::RecordProperty("TEST_ID", "3931a3df-e09f-414a-8a1e-64bcb1e010b7");
EXPECT_THAT(0_s * (INFINITY * -1.0), Eq(0_ns));
EXPECT_THAT(0_s * (std::numeric_limits<float>::infinity() * -1.0), Eq(0_ns));
EXPECT_THAT(0_s * (std::numeric_limits<double>::infinity() * -1.0), Eq(0_ns));
EXPECT_THAT(0_s * (std::numeric_limits<long double>::infinity() * -1.0), Eq(0_ns));
}

TEST(Duration_test, MultiplyMaxDurationWithNegInfDoubleResultsInZeroDuration)
TEST(Duration_test, MultiplyMaxDurationWithNegInfResultsInZeroDuration)
{
::testing::Test::RecordProperty("TEST_ID", "9f563db0-85fa-4558-8928-8fe730f3ff47");
EXPECT_THAT(DurationAccessor::max() * (INFINITY * -1.0), Eq(0_ns));
EXPECT_THAT(DurationAccessor::max() * (std::numeric_limits<float>::infinity() * -1.0), Eq(0_ns));
EXPECT_THAT(DurationAccessor::max() * (std::numeric_limits<double>::infinity() * -1.0), Eq(0_ns));
EXPECT_THAT(DurationAccessor::max() * (std::numeric_limits<long double>::infinity() * -1.0), Eq(0_ns));
}

TEST(Duration_test, MultiplyDurationWithMinimalFloatResultsInZero)
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/test/moduletests/test_utility_into.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum class B
namespace iox
{
template <>
constexpr B from<A, B>(A e)
constexpr B from<A, B>(A e) noexcept
{
switch (e)
{
Expand Down
Loading

0 comments on commit 697adc9

Please sign in to comment.