aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-06-17 06:42:21 +0000
committerJohn McCall <rjmccall@apple.com>2011-06-17 06:42:21 +0000
commit7acddacc921cd0b3f813443a8641eeddb82dfbd4 (patch)
treed5abc49c4f8c85ffeb9505ae60ef9e3f1f6f9231 /lib/Sema/SemaStmt.cpp
parent3724020559653f11d1327ff41676a06afe3a678f (diff)
Objective-C fast enumeration loop variables are not retained in ARC, but
they should still be officially __strong for the purposes of errors, block capture, etc. Make a new bit on variables, isARCPseudoStrong(), and set this for 'self' and these enumeration-loop variables. Change the code that was looking for the old patterns to look for this bit, and change IR generation to find this bit and treat the resulting variable as __unsafe_unretained for the purposes of init/destroy in the two places it can come up. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133243 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index a5ad0a5a2b..9af9c8de1b 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -71,22 +71,23 @@ void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) {
// suppress any potential 'unused variable' warning.
var->setUsed();
- // In ARC, we don't want to lifetime for the iteration
- // variable of a fast enumeration loop. Rather than actually
- // trying to catch that during declaration processing, we
- // remove the consequences here.
+ // foreach variables are never actually initialized in the way that
+ // the parser came up with.
+ var->setInit(0);
+
+ // In ARC, we don't need to retain the iteration variable of a fast
+ // enumeration loop. Rather than actually trying to catch that
+ // during declaration processing, we remove the consequences here.
if (getLangOptions().ObjCAutoRefCount) {
- SplitQualType split = var->getType().split();
-
- // Inferred lifetime will show up as a local qualifier because
- // explicit lifetime would have shown up as an AttributedType
- // instead.
- if (split.second.hasObjCLifetime()) {
- // Change the qualification to 'const __unsafe_unretained'.
- split.second.setObjCLifetime(Qualifiers::OCL_ExplicitNone);
- split.second.addConst();
- var->setType(Context.getQualifiedType(split.first, split.second));
- var->setInit(0);
+ QualType type = var->getType();
+
+ // Only do this if we inferred the lifetime. Inferred lifetime
+ // will show up as a local qualifier because explicit lifetime
+ // should have shown up as an AttributedType instead.
+ if (type.getLocalQualifiers().getObjCLifetime() == Qualifiers::OCL_Strong) {
+ // Add 'const' and mark the variable as pseudo-strong.
+ var->setType(type.withConst());
+ var->setARCPseudoStrong(true);
}
}
}