Skip to content

Add support for initializing vtable pointer of types without constructors #31

@PathogenDavid

Description

@PathogenDavid

For types without constructors, the C++ compiler may initialize the vtable pointer wherever the type is initialized.

This was encountered with PxDefaultAllocator.

Here's a simple example: (Godbolt)

class AbstractBase
{
public:
    virtual void* allocate(int size);
};

class DefaultImpl : public AbstractBase
{
public:
    void* allocate(int size)
    {
        return nullptr;
    }
};

void UseAllocator(AbstractBase* allocator)
{
    allocator->allocate(100);
}

void Test()
{
    DefaultImpl impl;
    UseAllocator(&impl);
}

With GCC x86-64 10.2, Test is generated as follows:

Test():
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     eax, OFFSET FLAT:vtable for DefaultImpl+16
        mov     QWORD PTR [rbp-8], rax
        lea     rax, [rbp-8]
        mov     rdi, rax
        call    UseAllocator(AbstractBase*)
        nop
        leave
        ret

The easiest solution here is probably to use C trampolines for object construction (when necessary?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-OutputGenerationIssues concerning the process of generating output from BiohazrdBlocks-PhysXConcept-CppFeaturesIssues concerning unsupported C++ featuresConcept-InlineExpectationIssues concerning problems around C++'s expectation for something to be inlined.Concept-OutputUsabilityIssues concerning whether or not the output from Biohazrd is actually usable

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions