Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Miscompilation when devirtualization is aborted due to covariant return types #20115

Closed Quuxplusone closed 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20116
Status RESOLVED FIXED
Importance P normal
Reported by Alexey Izbyshev (izbyshev@ispras.ru)
Reported on 2014-06-24 09:32:22 -0700
Last modified on 2014-09-30 04:08:48 -0700
Version trunk
Hardware PC Linux
CC a.bataev@hotmail.com, david.majnemer@gmail.com, hfinkel@anl.gov, izbyshev@ispras.ru, llvm-bugs@lists.llvm.org, nlewycky@google.com, rafael@espindo.la, rnk@google.com, zinovy.nis@gmail.com
Fixed by commit(s)
Attachments test.cpp (367 bytes, text/x-c++src)
Blocks
Blocked by
See also
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.
Quuxplusone commented 10 years ago

Attached test.cpp (367 bytes, text/x-c++src): A failing test case