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

Anonymous unions cannot be initialized with from_bytes function #623

Closed
IDKWNTCMF opened this issue Aug 17, 2023 · 0 comments · Fixed by #624
Closed

Anonymous unions cannot be initialized with from_bytes function #623

IDKWNTCMF opened this issue Aug 17, 2023 · 0 comments · Fixed by #624
Labels
bug Something isn't working

Comments

@IDKWNTCMF
Copy link
Collaborator

Description
In some cases UTBot tries to construct anonymous union from bytes returned by KLEE. But from_bytes function needs constructed type as a template parameter, so generated tests cannot be compiled.

Example

struct StructWithAnonymousUnion {
   union {
       int x;
       struct {
           char c;
           double d;
       };
       long long *ptr;
   };
};

struct StructWithAnonymousUnion struct_with_anonymous_union_as_return_type(int a, int b) {
   struct StructWithAnonymousUnion ans;
   if (a > b) {
       ans.ptr = 0;
   } else if (a < b) {
       ans.x = 153;
   } else {
       ans.c = 'k';
       ans.d = 1.0101;
   }
   return ans;
}

To Reproduce
Steps to reproduce the behavior:

  1. Copy the example above to your project
  2. Generate tests for function struct_with_anonymous_union_as_return_type
  3. Try to run generated tests

Expected behavior
Tests are supposed to be executed.

Actual behavior
Compilation error.

Generated test

TEST(regression, struct_with_anonymous_union_as_return_type_test1)
{
    // Construct input
    int a = 0;
    int b = 0;

    // Expected output
    struct StructWithAnonymousUnion expected = {
        from_bytes<StructWithAnonymousUnion::>({107, -85, -85, -85, -85, -85, -85, -85, -102, 8, 27, -98, 94, 41, -16, 63})
    };

    // Trigger the function
    struct StructWithAnonymousUnion actual = struct_with_anonymous_union_as_return_type(a, b);

    // Check results
    EXPECT_EQ(expected.x, actual.x);
    EXPECT_EQ(expected.c, actual.c);
    EXPECT_DOUBLE_EQ(expected.d, actual.d);
}

Logs

/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/complex_structs_dot_c_test.cpp:21:46: error: expected unqualified-id
        from_bytes<StructWithAnonymousUnion::>({107, -85, -85, -85, -85, -85, -85, -85, -102, 8, 27, -98, 94, 41, -16, 63})
                                             ^
1 error generated.
@IDKWNTCMF IDKWNTCMF added the bug Something isn't working label Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant