]> granicus.if.org Git - clang/commitdiff
fix rdar://9780211 - Clang crashes with an assertion failure building WKView.mm from...
authorChris Lattner <sabre@nondot.org>
Wed, 20 Jul 2011 06:29:00 +0000 (06:29 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 20 Jul 2011 06:29:00 +0000 (06:29 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135572 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGenObjCXX/copy.mm

index d2ad5dc887d9b3c4b8df52bfb0321a68bc3fb383..e3b93a3f4587645fcb4ce21da42af316740b412c 100644 (file)
@@ -954,9 +954,13 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
         if (Arg->getType().isRestrictQualified())
           AI->addAttr(llvm::Attribute::NoAlias);
 
+        // Ensure the argument is the correct type.
+        if (V->getType() != ArgI.getCoerceToType())
+          V = Builder.CreateBitCast(V, ArgI.getCoerceToType());
+
         if (isPromoted)
           V = emitArgumentDemotion(*this, Arg, V);
-
+        
         EmitParmDecl(*Arg, V, ArgNo);
         break;
       }
index 133910f25dcf6a8b24265463b399363049a919b7..e97ca79d3b92c2e8a27028ccc87a4063f2fee3ec 100644 (file)
@@ -24,3 +24,18 @@ namespace test0 {
   }
 }
 
+
+// rdar://9780211
+@protocol bork
+@end
+
+namespace test1 {
+template<typename T> struct RetainPtr {
+  RetainPtr() {}
+};
+
+
+RetainPtr<id<bork> > x;
+RetainPtr<id> y;
+
+}