]> granicus.if.org Git - clang/commitdiff
Do not apply the ARC move optimization to 'const'-qualified xvalues.
authorJohn McCall <rjmccall@apple.com>
Sat, 25 Jun 2011 02:26:44 +0000 (02:26 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 25 Jun 2011 02:26:44 +0000 (02:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133861 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjC.cpp
test/CodeGenObjCXX/arc-move.mm

index 2782c2b3f75c4a94ad4171616dd0275507b7690b..4c59e6ae2916b8456a023c9bf0771af8d1655953 100644 (file)
@@ -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);
index 87011a622e9410d7b6503e657d7168950bb9162a..70469e6a858610de85454894ecd23a8f1ba07970 100644 (file)
@@ -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);
+}