[cfe-commits] r135572 - in /cfe/trunk: lib/CodeGen/CGCall.cpp test/CodeGenObjCXX/copy.mm

Douglas Gregor dgregor at apple.com
Wed Jul 20 07:23:55 PDT 2011


On Jul 19, 2011, at 11:29 PM, Chris Lattner wrote:

> Author: lattner
> Date: Wed Jul 20 01:29:00 2011
> New Revision: 135572
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=135572&view=rev
> Log:
> fix rdar://9780211 - Clang crashes with an assertion failure building WKView.mm from WebKit
> 
> This is something of a hack, the problem is as follows:
> 
> 1. we instantiate both copied of RetainPtr with the two different argument types
>   (an id and protocol-qualified id).
> 2. We refer to the ctor of one of the instantiations when introducing global "x",
>   this causes us to emit an llvm::Function for a prototype whose "this" has type
>   "RetainPtr<id<bork> >*".
> 3. We refer to the ctor of the other instantiation when introducing global "y",
>   however, because it *mangles to the same name as the other ctor* we just use
>   a bitcasted version of the llvm::Function we previously emitted.
> 4. We emit deferred declarations, causing us to emit the body of the ctor, however
>   the body we emit is for RetainPtr<id>, which expects its 'this' to have an IR
>   type of "RetainPtr<id>*".
> 
> Because of the mangling collision, we don't have this case, and explode.
> 
> This is really some sort of weird AST invariant violation or something, but hey
> a bitcast makes the pain go away.

It's fundamental brokenness in the ObjC++ ABI. Essentially, ObjC considers id and id<P> to be distinct types, but GCC gave them the same name mangling, which means that the language's notion of identity differs from the ABI's notion of identity, and a long string of bugs will inevitably follow. For example, we used to crash on code like this in Objective-C++:

	void f(id) { }
	void f(id<P>) { }

because those two function types are distinct, yet they mangle to the same thing, causing CodeGen to assert. Now we have special-case logic in Sema to call the second a redefinition of the first, but the only way to actually solve this problem in the long term is to change ObjC or change the ABI.

	- Doug



More information about the cfe-commits mailing list