Codegen for typeid is incompatible with MS ABI
| Bugzilla Link | 47467 |
| Version | trunk |
| OS | Windows NT |
| CC | @dwblaikie,@DougGregor,@zmodem,@zygoloid |
Extended Description
Clang codegen for typeid generates calls to __RTtypeid sometimes when MSVC doesn't generates such call, https://godbolt.org/z/vzdn9Y
Yes. I'll give it a try.
Pasting the code here so we don't lose it:
namespace std {
struct type_info {};
} // namespace std
class B {
public:
virtual ~B() = default;
};
class D1 : public B {
public:
~D1() = default;
};
const std::type_info& f1(B& b) {
return typeid(b);
}
const std::type_info& f2(B* b) {
return typeid(*b);
}
const std::type_info& f3(B b) {
return typeid(b);
}
const std::type_info& f4(B b) {
return typeid(*&b);
}
const std::type_info& f5(B b) {
return typeid((B&)b);
}
Looking at your example, the difference seems to be for f3 and f5.
I don't think it's correct to say that the codegen is incompatible: I assume the code works, but it's a little bit inefficient.
If you look at the same code targeting Linux, the code for f3, f4, and f5 also seems inefficient since the type is known at compile-time. GCC handles this better and just returns the typeinfo directly.
It seems there is room for improvement here, both for Windows and non-Windows targets. I think it would be good to at least get better code for f3(). Want to give that a try?
@llvm/issue-subscribers-clang-codegen
Author: Zequan Wu (ZequanWu)
Extended Description
Clang codegen for typeid generates calls to __RTtypeid sometimes when MSVC doesn't generates such call, https://godbolt.org/z/vzdn9Y