]> granicus.if.org Git - clang/commitdiff
Disable this-return optimizations when targeting iOS 5 and earlier.
authorBob Wilson <bob.wilson@apple.com>
Tue, 1 Apr 2014 01:38:16 +0000 (01:38 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 1 Apr 2014 01:38:16 +0000 (01:38 +0000)
Clang implements the part of the ARM ABI saying that certain functions
(e.g., constructors and destructors) return "this", but Apple's version of
gcc and llvm-gcc did not. The libstdc++ dylib on iOS 5 was built with
llvm-gcc, which means that clang cannot safely assume that code from the C++
runtime will correctly follow the ABI. It is also possible to run into this
problem when linking with other libraries built with gcc or llvm-gcc. Even
though there is no way to reliably detect that situation, it is most likely
to come up when targeting older versions of iOS. Disabling the optimization
for any code targeting iOS 5 solves the libstdc++ problem and has a reasonably
good chance of fixing the issue for other older libraries as well.
<rdar://problem/16377159>

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

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/arm.cpp
test/CodeGenCXX/constructor-destructor-return-this.cpp

index 89d177fdb0517005bda5f582c067696d7e4e410a..d997a79f5b23949c21567d683df1164d64af468a 100644 (file)
@@ -775,7 +775,12 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD,
   if (!IsIncompleteFunction)
     SetLLVMFunctionAttributes(FD, getTypes().arrangeGlobalDeclaration(GD), F);
 
-  if (getCXXABI().HasThisReturn(GD)) {
+  // Add the Returned attribute for "this", except for iOS 5 and earlier
+  // where substantial code, including the libstdc++ dylib, was compiled with
+  // GCC and does not actually return "this".
+  if (getCXXABI().HasThisReturn(GD) &&
+      !(getTarget().getTriple().isiOS() &&
+        getTarget().getTriple().isOSVersionLT(6))) {
     assert(!F->arg_empty() &&
            F->arg_begin()->getType()
              ->canLosslesslyBitCastTo(F->getReturnType()) &&
index 2fb9c49bb7079364f00bcbe42099a0a784c184a7..2790199446d7ec09bb8c5eab5da221dd23e6d17d 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple=thumbv7-apple-ios3.0 -fno-use-cxa-atexit -target-abi apcs-gnu -emit-llvm -o - -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=thumbv7-apple-ios6.0 -fno-use-cxa-atexit -target-abi apcs-gnu -emit-llvm -o - -fexceptions | FileCheck %s
 
 // CHECK: @_ZZN5test74testEvE1x = internal global i32 0, align 4
 // CHECK: @_ZGVZN5test74testEvE1x = internal global i32 0
index d93a0d184820fe4ab21966a0ab75427283ae0f78..ce6ddd29f6446470e63f0aff46f8f50136965da3 100644 (file)
@@ -1,5 +1,6 @@
 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-unknown-linux | FileCheck --check-prefix=CHECKGEN %s
-//RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios3.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKARM %s
+//RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios6.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKARM %s
+//RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios5.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKIOS5 %s
 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
 
@@ -37,6 +38,11 @@ B::~B() { }
 // CHECKARM-LABEL: define %class.B* @_ZN1BD2Ev(%class.B* returned %this)
 // CHECKARM-LABEL: define %class.B* @_ZN1BD1Ev(%class.B* returned %this)
 
+// CHECKIOS5-LABEL: define %class.B* @_ZN1BC2EPi(%class.B* %this, i32* %i)
+// CHECKIOS5-LABEL: define %class.B* @_ZN1BC1EPi(%class.B* %this, i32* %i)
+// CHECKIOS5-LABEL: define %class.B* @_ZN1BD2Ev(%class.B* %this)
+// CHECKIOS5-LABEL: define %class.B* @_ZN1BD1Ev(%class.B* %this)
+
 // CHECKMS-LABEL: define x86_thiscallcc %class.B* @"\01??0B@@QAE@PAH@Z"(%class.B* returned %this, i32* %i)
 // CHECKMS-LABEL: define x86_thiscallcc void @"\01??1B@@QAE@XZ"(%class.B* %this)
 
@@ -63,6 +69,12 @@ C::~C() { }
 // CHECKARM-LABEL: define %class.C* @_ZN1CD1Ev(%class.C* returned %this)
 // CHECKARM-LABEL: define void @_ZN1CD0Ev(%class.C* %this)
 
+// CHECKIOS5-LABEL: define %class.C* @_ZN1CC2EPiPc(%class.C* %this, i32* %i, i8* %c)
+// CHECKIOS5-LABEL: define %class.C* @_ZN1CC1EPiPc(%class.C* %this, i32* %i, i8* %c)
+// CHECKIOS5-LABEL: define %class.C* @_ZN1CD2Ev(%class.C* %this)
+// CHECKIOS5-LABEL: define %class.C* @_ZN1CD1Ev(%class.C* %this)
+// CHECKIOS5-LABEL: define void @_ZN1CD0Ev(%class.C* %this)
+
 // CHECKMS-LABEL: define x86_thiscallcc %class.C* @"\01??0C@@QAE@PAHPAD@Z"(%class.C* returned %this, i32* %i, i8* %c)
 // CHECKMS-LABEL: define x86_thiscallcc void @"\01??1C@@UAE@XZ"(%class.C* %this)
 
@@ -85,6 +97,10 @@ D::~D() { }
 // CHECKARM-LABEL: define %class.D* @_ZN1DD2Ev(%class.D* returned %this, i8** %vtt)
 // CHECKARM-LABEL: define %class.D* @_ZN1DD1Ev(%class.D* returned %this)
 
+// CHECKIOS5-LABEL: define %class.D* @_ZN1DC2Ev(%class.D* %this, i8** %vtt)
+// CHECKIOS5-LABEL: define %class.D* @_ZN1DC1Ev(%class.D* %this)
+// CHECKIOS5-LABEL: define %class.D* @_ZN1DD2Ev(%class.D* %this, i8** %vtt)
+// CHECKIOS5-LABEL: define %class.D* @_ZN1DD1Ev(%class.D* %this)
 
 // CHECKMS-LABEL: define x86_thiscallcc %class.D* @"\01??0D@@QAE@XZ"(%class.D* returned %this, i32 %is_most_derived)
 // CHECKMS-LABEL: define x86_thiscallcc void @"\01??1D@@QAE@XZ"(%class.D* %this)