[PATCH] D32187: [CodeGen][ObjC]
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 18 18:15:04 PDT 2017
ahatanak updated this revision to Diff 95667.
ahatanak added a comment.
Unconditionally ban jumping into body of ObjC fast enumeration loop.
https://reviews.llvm.org/D32187
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/JumpDiagnostics.cpp
lib/Sema/SemaStmt.cpp
test/SemaObjC/foreach.m
Index: test/SemaObjC/foreach.m
===================================================================
--- test/SemaObjC/foreach.m
+++ test/SemaObjC/foreach.m
@@ -55,3 +55,27 @@
for (obj.prop in collection) { /* expected-error {{selector element is not a valid lvalue}} */
}
}
+
+int cond();
+
+void test3(NSObject<NSFastEnumeration> *a0, NSObject<NSFastEnumeration> *a1) {
+ for (id i in a0) { /* expected-note 2 {{jump enters Objective-c fast enumeration loop body}} */
+ for (id j in a1) { /* expected-note 2 {{jump enters Objective-c fast enumeration loop body}} */
+ (void)i, (void)j;
+label0:
+ if (cond())
+ goto label1;
+ }
+label1:
+ if (cond())
+ goto label0; /* expected-error {{cannot jump from this goto statement to its label}} */
+ if (cond())
+ goto label2;
+ }
+
+label2:
+ if (cond())
+ goto label0; /* expected-error {{cannot jump from this goto statement to its label}} */
+ if (cond())
+ goto label1; /* expected-error{{cannot jump from this goto statement to its label}} */
+}
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1783,6 +1783,7 @@
Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
Stmt *First, Expr *collection,
SourceLocation RParenLoc) {
+ getCurFunction()->setHasBranchProtectedScope();
ExprResult CollectionExprResult =
CheckObjCForCollectionOperand(ForLoc, collection);
Index: lib/Sema/JumpDiagnostics.cpp
===================================================================
--- lib/Sema/JumpDiagnostics.cpp
+++ lib/Sema/JumpDiagnostics.cpp
@@ -287,6 +287,15 @@
IndirectJumpTargets.push_back(cast<AddrLabelExpr>(S)->getLabel());
break;
+ case Stmt::ObjCForCollectionStmtClass: {
+ auto *CS = cast<ObjCForCollectionStmt>(S);
+ unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
+ unsigned NewParentScope = Scopes.size();
+ Scopes.push_back(GotoScope(ParentScope, Diag, 0, S->getLocStart()));
+ BuildScopeInformation(CS->getBody(), NewParentScope);
+ return;
+ }
+
case Stmt::IndirectGotoStmtClass:
// "goto *&&lbl;" is a special case which we treat as equivalent
// to a normal goto. In addition, we don't calculate scope in the
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -4981,6 +4981,8 @@
"jump enters controlled statement of if available">;
def note_protected_by_vla : Note<
"jump bypasses initialization of variable length array">;
+def note_protected_by_objc_fast_enumeration : Note<
+ "jump enters Objective-c fast enumeration loop body">;
def note_protected_by_objc_try : Note<
"jump bypasses initialization of @try block">;
def note_protected_by_objc_catch : Note<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32187.95667.patch
Type: text/x-patch
Size: 2996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170419/120248e0/attachment.bin>
More information about the cfe-commits
mailing list