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. <rdar://problem/16377159> llvm-svn: 205272
This commit is contained in:
@@ -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()) &&
|
||||
|
||||
Reference in New Issue
Block a user