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

Chris Lattner sabre at nondot.org
Tue Jul 19 23:29:00 PDT 2011


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.


Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGenObjCXX/copy.mm

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=135572&r1=135571&r2=135572&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Jul 20 01:29:00 2011
@@ -954,9 +954,13 @@
         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;
       }

Modified: cfe/trunk/test/CodeGenObjCXX/copy.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/copy.mm?rev=135572&r1=135571&r2=135572&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/copy.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/copy.mm Wed Jul 20 01:29:00 2011
@@ -24,3 +24,18 @@
   }
 }
 
+
+// rdar://9780211
+ at protocol bork
+ at end
+
+namespace test1 {
+template<typename T> struct RetainPtr {
+  RetainPtr() {}
+};
+
+
+RetainPtr<id<bork> > x;
+RetainPtr<id> y;
+
+}





More information about the cfe-commits mailing list