Skip to content

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

Closed
@IDKWNTCMF

Description

@IDKWNTCMF

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions