summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2013-10-22 17:14:47 +0000
committerSerge Pavlov <sepavloff@gmail.com>2013-10-22 17:14:47 +0000
commit65d9468435f747fce913020210170c5d69d3c4dc (patch)
tree2eea62094ea6fa0dc0950424e84a6ea2e94e703a
parent517cb27c4382bfce35c512bd3c54cb74d6cca12c (diff)
downloadbcm5719-llvm-65d9468435f747fce913020210170c5d69d3c4dc.tar.gz
bcm5719-llvm-65d9468435f747fce913020210170c5d69d3c4dc.zip
Reenable 'break' in 'for' specifier to allow compilation of QT macro 'foreach'
This is a fix to PR17649, caused by fix in r193073. QT uses 'break' statement to implement their 'foreach' macro. To enable build of QT, this fix reenables break but only in 'for' statement specifier and only in the third expression. llvm-svn: 193170
-rw-r--r--clang/lib/Parse/ParseStmt.cpp4
-rw-r--r--clang/test/Parser/bad-control.c18
2 files changed, 17 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 395fb394dc4..fe884148ebe 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -1553,6 +1553,10 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
// Parse the third part of the for specifier.
if (Tok.isNot(tok::r_paren)) { // for (...;...;)
+ // This is needed to compile QT 4.8.4, which uses statement
+ // expression with 'break' in it.
+ ForScope.SetFlags(Scope::BreakScope);
+
ExprResult Third = ParseExpression();
// FIXME: The C++11 standard doesn't actually say that this is a
// discarded-value expression, but it clearly should be.
diff --git a/clang/test/Parser/bad-control.c b/clang/test/Parser/bad-control.c
index dc0ce11ce59..9560af32595 100644
--- a/clang/test/Parser/bad-control.c
+++ b/clang/test/Parser/bad-control.c
@@ -52,14 +52,15 @@ int pr8880_6 (int a) {
void pr8880_7() {
for (int i = 0 ; i != 10 ; i++ ) {
- for ( ; ; ({ ++i; break; })) { // expected-error {{'break' statement not in loop or switch statement}}
+ for ( ; ; ({ ++i; continue; })) { // expected-error {{'continue' statement not in loop statement}}
}
}
}
-void pr8880_8() {
+// Have to allow 'break' in the third part of 'for' specifier to enable compilation of QT 4.8 macro 'foreach'
+void pr17649() {
for (int i = 0 ; i != 10 ; i++ )
- for ( ; ; ({ ++i; break; })) { // expected-error {{'break' statement not in loop or switch statement}}
+ for ( ; ; ({ ++i; break; })) {
}
}
@@ -86,8 +87,15 @@ void pr8880_11() {
// Moved from Analysis/dead-stores.c
void rdar8014335() {
- for (int i = 0 ; i != 10 ; ({ break; })) { // expected-error {{'break' statement not in loop or switch statement}}
- for ( ; ; ({ ++i; break; })) ; // expected-error {{'break' statement not in loop or switch statement}}
+ for (int i = 0 ; i != 10 ; ({ break; })) {
+ for ( ; ; ({ ++i; break; })) ;
+ i = i * 3;
+ }
+}
+
+void pr17649_2() {
+ for (int i = 0 ; i != 10 ; ({ continue; })) { // expected-error {{'continue' statement not in loop statement}}
+ for ( ; ; ({ ++i; continue; })) ; // expected-error {{'continue' statement not in loop statement}}
i = i * 3;
}
}
OpenPOWER on IntegriCloud