Issue |
120129
|
Summary |
Optimization in clang frontend breaks `dynamic_cast` on Apple platforms.
|
Labels |
clang
|
Assignees |
|
Reporter |
ahatanak
|
This is caused by 9d525bf94b255df89587db955b5fa2d3c03c2c3e.
`dynamic_cast` in the following code fails unless the optimization is disabled by passing `-fno-assume-unique-vtables`.
% cat a.h
```
struct Foo {
virtual ~Foo();
};
struct Bar final : public Foo {
};
Foo* makeBar();
```
% cat a.cc
```
#include "a.h"
Foo::~Foo() {}
Foo* makeBar() {
return new Bar();
}
```
% cat b.cc
```
#include "a.h"
int main() {
Foo* f = makeBar();
Bar* b = dynamic_cast<Bar*>(f); // b will incorrectly be nullptr
return !!b;
}
```
% clang++ -std=c++11 -c a.cc -O1
% clang++ -std=c++11 -c b.cc -O1
% clang++ -shared -o liba.so a.o
% clang++ --std=c++11 -o a.out b.o -Wl,-rpath,$PWD liba.so
% ./a.out
% echo $?
0
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs