From: John McCall Date: Sat, 25 Jun 2011 02:26:44 +0000 (+0000) Subject: Do not apply the ARC move optimization to 'const'-qualified xvalues. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df7b091c58ccdb402a32bfbde9c506074dba5f3d;p=clang Do not apply the ARC move optimization to 'const'-qualified xvalues. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133861 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 2782c2b3f7..4c59e6ae29 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -2269,7 +2269,7 @@ tryEmitARCRetainScalarExpr(CodeGenFunction &CGF, const Expr *e) { // If we're loading retained from a __strong xvalue, we can avoid // an extra retain/release pair by zeroing out the source of this // "move" operation. - if (e->isXValue() && + if (e->isXValue() && !e->getType().isConstQualified() && e->getType().getObjCLifetime() == Qualifiers::OCL_Strong) { // Emit the lvalue LValue lv = CGF.EmitLValue(e); diff --git a/test/CodeGenObjCXX/arc-move.mm b/test/CodeGenObjCXX/arc-move.mm index 87011a622e..70469e6a85 100644 --- a/test/CodeGenObjCXX/arc-move.mm +++ b/test/CodeGenObjCXX/arc-move.mm @@ -61,3 +61,15 @@ void library_move(__strong id &y) { // CHECK-NEXT: call void @objc_release(i8* [[OBJ]]) // CHECK-NEXT: ret void } + +// CHECK: define void @_Z10const_moveRKU8__strongP11objc_object( +void const_move(const __strong id &x) { + // CHECK: [[Y:%.*]] = alloca i8*, + // CHECK: [[X:%.*]] = call i8** @_Z4moveIRKU8__strongP11objc_objectEON16remove_referenceIT_E4typeEOS5_( + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[Y]] + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + id y = move(x); +}