Skip to content

ubsan has stopped identifying a mismatch between static and dynamic type of an argument to typeid() and dynamic_cast #143065

Open
@ojhunt

Description

@ojhunt

A post on C++'s std-proposals said some clearly UB code did not trigger a sanitizer failure, which was somewhat confusion, but after investigating it's a regression since clang 20.

#include <typeinfo>
struct Foo {
   virtual ~Foo(){}
};
struct Bar {
   virtual ~Bar(){}
};

struct Subclass : Bar {};

int main(int arc, char**) {
   Foo f;
   Bar *b = reinterpret_cast<Bar*>(&f);
   (void)typeid(*b);
   (void)dynamic_cast<Subclass*>(b);
   return 0;
}

Compiling with -fsanitize=undefined and running reports errors for the dynamic_cast and the typeid in 20, but is silent in trunk

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions