Skip to content

Incorrect DCE with fvirtual-function-elimination fvisibility=hidden  #113286

@Umesh-k26

Description

@Umesh-k26

Reproducer:

// RUN: clang++ -O1 -flto -fvirtual-function-elimination -fvisibility=hidden %s
#include <stdio.h>

class MyClass {
public:
    virtual int foo(int e) {
        return 42+e;
    }
};

int main() {
    MyClass c;
    using casted_foo_t = int (MyClass::*)(long);
    auto casted_foo = (casted_foo_t)&MyClass::foo;
    printf("%d\n", (c.*casted_foo)(2));
}

Output:
Segmentation fault (core dumped)

The type metadata node for foo ( !"_ZTSM7MyClassFiiE.virtual" ) and casted_foo_t ( !"_ZTSM7MyClassFilE.virtual" ) is different.
In GlobalDCE, these callsites are analyzed only with type metadata, and address taken here is not captured.

GlobalStatus might not help here, as the virtual-function's use-list only contains vtables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:optimizationsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions