LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 20116 - Miscompilation when devirtualization is aborted due to covariant return types
Summary: Miscompilation when devirtualization is aborted due to covariant return types
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: LLVM Codegen (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-24 09:32 PDT by Alexey Izbyshev
Modified: 2014-09-30 04:08 PDT (History)
9 users (show)

See Also:
Fixed By Commit(s):


Attachments
A failing test case (367 bytes, text/x-c++src)
2014-06-24 09:32 PDT, Alexey Izbyshev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Izbyshev 2014-06-24 09:32:22 PDT
Created attachment 12699 [details]
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.