summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/Scope.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2014-01-23 15:05:00 +0000
committerSerge Pavlov <sepavloff@gmail.com>2014-01-23 15:05:00 +0000
commit09f9924acf1a8644e9458833d3c8ea40d7ddbc46 (patch)
treeab81b6c65a12f96059f2bed913314d8f138c7925 /clang/lib/Sema/Scope.cpp
parent5a68c4b28747fc5da182916b801de9a34e59a0dd (diff)
downloadbcm5719-llvm-09f9924acf1a8644e9458833d3c8ea40d7ddbc46.tar.gz
bcm5719-llvm-09f9924acf1a8644e9458833d3c8ea40d7ddbc46.zip
Fix to PR8880 (clang dies processing a for loop)
Due to statement expressions supported as GCC extension, it is possible to put 'break' or 'continue' into a loop/switch statement but outside its body, for example: for ( ; ({ if (first) { first = 0; continue; } 0; }); ) This code is rejected by GCC if compiled in C mode but is accepted in C++ code. GCC bug 44715 tracks this discrepancy. Clang used code generation that differs from GCC in both modes: only statement of the third expression of 'for' behaves as if it was inside loop body. This change makes code generation more close to GCC, considering 'break' or 'continue' statement in condition and increment expressions of a loop as it was inside the loop body. It also adds error for the cases when 'break'/'continue' appear outside loop due to this syntax. If code generation differ from GCC, warning is issued. Differential Revision: http://llvm-reviews.chandlerc.com/D2518 llvm-svn: 199897
Diffstat (limited to 'clang/lib/Sema/Scope.cpp')
-rw-r--r--clang/lib/Sema/Scope.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp
index 10f12ce844f..eef55d31947 100644
--- a/clang/lib/Sema/Scope.cpp
+++ b/clang/lib/Sema/Scope.cpp
@@ -69,3 +69,18 @@ bool Scope::containedInPrototypeScope() const {
}
return false;
}
+
+void Scope::AddFlags(unsigned FlagsToSet) {
+ assert((FlagsToSet & ~(BreakScope | ContinueScope)) == 0 &&
+ "Unsupported scope flags");
+ if (FlagsToSet & BreakScope) {
+ assert((Flags & BreakScope) == 0 && "Already set");
+ BreakParent = this;
+ }
+ if (FlagsToSet & ContinueScope) {
+ assert((Flags & ContinueScope) == 0 && "Already set");
+ ContinueParent = this;
+ }
+ Flags |= FlagsToSet;
+}
+
OpenPOWER on IntegriCloud