]> granicus.if.org Git - clang/commitdiff
Don't crash *or* insert a bogus autorelease when emitting a
authorJohn McCall <rjmccall@apple.com>
Tue, 31 Jul 2012 00:33:55 +0000 (00:33 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 31 Jul 2012 00:33:55 +0000 (00:33 +0000)
this-adjustment thunk in ARC++.

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

lib/CodeGen/CGCall.cpp
lib/CodeGen/CGVTables.cpp
test/CodeGenObjCXX/arc.mm

index 37a9a5eaff03319e31d54460699c964630505b63..9deec19bf80172b373bec473f9b956e9dab3429c 100644 (file)
@@ -1405,7 +1405,8 @@ static llvm::Value *tryEmitFusedAutoreleaseOfResult(CodeGenFunction &CGF,
 static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction &CGF,
                                           llvm::Value *result) {
   // This is only applicable to a method with an immutable 'self'.
-  const ObjCMethodDecl *method = dyn_cast<ObjCMethodDecl>(CGF.CurCodeDecl);
+  const ObjCMethodDecl *method =
+    dyn_cast_or_null<ObjCMethodDecl>(CGF.CurCodeDecl);
   if (!method) return 0;
   const VarDecl *self = method->getSelfDecl();
   if (!self->getType().isConstQualified()) return 0;
index 3c0dd5d56b5c665e40234f082c2a32dc03f7292b..cdaa26a2bad6568d6ddad1465458d29826293fd7 100644 (file)
@@ -387,6 +387,9 @@ void CodeGenFunction::GenerateThunk(llvm::Function *Fn,
   if (!ResultType->isVoidType() && Slot.isNull())
     CGM.getCXXABI().EmitReturnFromThunk(*this, RV, ResultType);
 
+  // Disable the final ARC autorelease.
+  AutoreleaseResult = false;
+
   FinishFunction();
 
   // Set the right linkage.
index 45211a2c19ab28c7cdddcced91fb04e4afeabd83..f31b993946e835a0fcd00004af6e70c88e206475 100644 (file)
@@ -252,3 +252,19 @@ template <class T> class Test38 {
 };
 // CHECK: define weak_odr void @_ZN6Test38IiE4testEi(
 template class Test38<int>;
+
+// rdar://problem/11964832
+class Test39_base1 {
+  virtual void foo();
+};
+class Test39_base2 {
+  virtual id bar();
+};
+class Test39 : Test39_base1, Test39_base2 { // base2 is at non-zero offset
+  virtual id bar();
+};
+id Test39::bar() { return 0; }
+// Note lack of autorelease.
+// CHECK:    define i8* @_ZThn8_N6Test393barEv(
+// CHECK:      call i8* @_ZN6Test393barEv(
+// CHECK-NEXT: ret i8*