Created attachment 12699
A failing test case
When compiling the attached code, clang doesn't emit 'this' adjustment code for
'static_cast<A*>(z)' expression and ends up using a wrong vtable for the
virtual call. As a result, B.g() is called instead of Z.f().
Inspection of CodeGenFunction::EmitCXXMemberCallExpr() code shows that clang
can stop devirtualization in the middle if it finds out that return types are
covariant. At that moment, 'Base' expression that is later used for emission of
'this' pointer has already been assigned to 'Inner' expression (with casts
stripped), so no 'this' adjustment code is generated.
test.cpp
(367 bytes, text/x-c++src)