Skip to content

Generated tests can contain cast to union of unnamed type #603

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

Closed
IDKWNTCMF opened this issue Jul 20, 2023 · 0 comments · Fixed by #604
Closed

Generated tests can contain cast to union of unnamed type #603

IDKWNTCMF opened this issue Jul 20, 2023 · 0 comments · Fixed by #604
Labels
bug Something isn't working

Comments

@IDKWNTCMF
Copy link
Collaborator

Description
If struct contains union of unnamed type, then in some cases generated tests can contain cast to union of unnamed type. Thus tests cannot be run.

Example

struct StructWithUnionOfUnnamedType {
    union {
        int x;
        struct {
            char c;
            double d;
        } ds;
        long long *ptr;
    } un;
};

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

To Reproduce
Steps to reproduce the behavior:

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

Expected behavior
Tests are supposed to be executed successfully.

Actual behavior
An error test is generated with information about errors.

Generated test

TEST(regression, struct_with_union_of_unnamed_type_as_return_type_test1)
{
    struct StructWithUnionOfUnnamedType actual = struct_with_union_of_unnamed_type_as_return_type(0, 0);
    struct StructWithUnionOfUnnamedType expected = {
        .un = from_bytes<StructWithUnionOfUnnamedType::StructWithUnionOfUnnamedType::(anonymous union at /home/utbot/UTBotCpp/integration-tests/c-example/lib/structures/structs/simple_structs.h:89:5)>({107, -85, -85, -85, -85, -85, -85, -85, -102, 8, 27, -98, 94, 41, -16, 63})
    };
}

Logs

/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/simple_structs_dot_c_test.cpp:17:86: error: expected unqualified-id
        .un = from_bytes<StructWithUnionOfUnnamedType::StructWithUnionOfUnnamedType::(anonymous union at /home/utbot/UTBotCpp/integration-tests/c-example/lib/structures/structs/simple_structs.h:89:5)>({107, -85, -85, -85, -85, -85, -85, -85, -102, 8, 27, -98, 94, 41, -16, 63})
                                                                                     ^
/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/simple_structs_dot_c_test.cpp:17:87: error: use of undeclared identifier 'anonymous'
        .un = from_bytes<StructWithUnionOfUnnamedType::StructWithUnionOfUnnamedType::(anonymous union at /home/utbot/UTBotCpp/integration-tests/c-example/lib/structures/structs/simple_structs.h:89:5)>({107, -85, -85, -85, -85, -85, -85, -85, -102, 8, 27, -98, 94, 41, -16, 63})
                                                                                      ^
2 errors generated.
@IDKWNTCMF IDKWNTCMF added the bug Something isn't working label Jul 20, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot C/C++ Jul 26, 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