From fc6297f31499b13f297ec909dd309a1e89096b26 Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Tue, 1 Apr 2014 01:38:16 +0000 Subject: Disable this-return optimizations when targeting iOS 5 and earlier. 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. llvm-svn: 205272 --- clang/lib/CodeGen/CodeGenModule.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 89d177fdb05..d997a79f5b2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -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()) && -- cgit v1.2.3