Skip to content
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

Compacted Structs and Assertion Macro Expressions #1977

Open
mattkoloski opened this issue Jul 6, 2020 · 0 comments
Open

Compacted Structs and Assertion Macro Expressions #1977

mattkoloski opened this issue Jul 6, 2020 · 0 comments

Comments

@mattkoloski
Copy link

Description
Catch2 assertion macros with compacted structs seem to expand the contents instead of just evaluating the truthiness of the overall statement. The statement needs to be wrapped with parentheses in order for the assertion macro to properly align the attributes of a compacted struct. This issue only occurs with the Xtensa compiler(clang++ and g++ compiled catch executable passed).

Example:

#include "catch.hpp"
TEST_CASE("Compacted Struct Example")
{
#pragma pack(push, 1)
    struct
    {
        uint8_t data1;
        uint16_t data2;
        uint32_t data3;
        uint16_t data4;
        uint8_t data5;
    } buffer;
#pragma pack(pop)

    buffer.data1 = 0x01;
    buffer.data2 = 0x2345;
    buffer.data3 = 0x6789ABCD;
    buffer.data4 = 0xEF01;
    buffer.data5 = 0x23;

    REQUIRE((buffer.data1 == 0x01));       // pass
    REQUIRE((buffer.data2 == 0x2345));     // pass
    REQUIRE((buffer.data3 == 0x6789ABCD)); // pass
    REQUIRE((buffer.data4 == 0xEF01));     // pass
    REQUIRE((buffer.data5 == 0x23));       // pass

    REQUIRE(buffer.data1 == 0x01);       // pass
    REQUIRE(buffer.data2 == 0x2345);     // fail 17665 == 9029 (0x2345)
    REQUIRE(buffer.data3 == 0x6789ABCD); // fail 3441640705 (0xcd234501) == 1737075661 (0x6789abcd)
    REQUIRE(buffer.data4 == 0xEF01);     // fail 359 == 61185 (0xef01)
    REQUIRE(buffer.data5 == 0x23);       // pass
}

Expected behavior
In the example above, I would expect this line to pass, but instead, it's misaligned.

REQUIRE(buffer.data2 == 0x2345);

Platform information:

  • Compiler+version: Xtensa 14.02 Lx7 Instruction Set Simulator(clang++ based)
  • Catch version: v2.9.2
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

No branches or pull requests

1 participant