summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2018-01-22 12:56:41 +0000
committerHans Wennborg <hans@hanshq.net>2018-01-22 12:56:41 +0000
commit462588bf68d37f4b7687ced158d7e8824dd95501 (patch)
tree5968b628e796626c7e2da675ef44e66beec228ee
parent8231d6059b6a185649957dd044adffe98ae3524e (diff)
Merging r322813:
------------------------------------------------------------------------ r322813 | rtrieu | 2018-01-18 05:28:56 +0100 (Thu, 18 Jan 2018) | 7 lines Fix Scope::dump() The dump function for Scope only has 20 out of the 24 flags. Since it looped until no flags were left, having an unknown flag lead to an infinite loop. That loop has been changed to a single pass for each flag, plus an assert to alert if new flags are added. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_60@323109 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/Scope.cpp99
1 files changed, 35 insertions, 64 deletions
diff --git a/lib/Sema/Scope.cpp b/lib/Sema/Scope.cpp
index ae5b181c67..eae5a328bf 100644
--- a/lib/Sema/Scope.cpp
+++ b/lib/Sema/Scope.cpp
@@ -143,72 +143,43 @@ void Scope::dumpImpl(raw_ostream &OS) const {
if (HasFlags)
OS << "Flags: ";
- while (Flags) {
- if (Flags & FnScope) {
- OS << "FnScope";
- Flags &= ~FnScope;
- } else if (Flags & BreakScope) {
- OS << "BreakScope";
- Flags &= ~BreakScope;
- } else if (Flags & ContinueScope) {
- OS << "ContinueScope";
- Flags &= ~ContinueScope;
- } else if (Flags & DeclScope) {
- OS << "DeclScope";
- Flags &= ~DeclScope;
- } else if (Flags & ControlScope) {
- OS << "ControlScope";
- Flags &= ~ControlScope;
- } else if (Flags & ClassScope) {
- OS << "ClassScope";
- Flags &= ~ClassScope;
- } else if (Flags & BlockScope) {
- OS << "BlockScope";
- Flags &= ~BlockScope;
- } else if (Flags & TemplateParamScope) {
- OS << "TemplateParamScope";
- Flags &= ~TemplateParamScope;
- } else if (Flags & FunctionPrototypeScope) {
- OS << "FunctionPrototypeScope";
- Flags &= ~FunctionPrototypeScope;
- } else if (Flags & FunctionDeclarationScope) {
- OS << "FunctionDeclarationScope";
- Flags &= ~FunctionDeclarationScope;
- } else if (Flags & AtCatchScope) {
- OS << "AtCatchScope";
- Flags &= ~AtCatchScope;
- } else if (Flags & ObjCMethodScope) {
- OS << "ObjCMethodScope";
- Flags &= ~ObjCMethodScope;
- } else if (Flags & SwitchScope) {
- OS << "SwitchScope";
- Flags &= ~SwitchScope;
- } else if (Flags & TryScope) {
- OS << "TryScope";
- Flags &= ~TryScope;
- } else if (Flags & FnTryCatchScope) {
- OS << "FnTryCatchScope";
- Flags &= ~FnTryCatchScope;
- } else if (Flags & SEHTryScope) {
- OS << "SEHTryScope";
- Flags &= ~SEHTryScope;
- } else if (Flags & SEHExceptScope) {
- OS << "SEHExceptScope";
- Flags &= ~SEHExceptScope;
- } else if (Flags & OpenMPDirectiveScope) {
- OS << "OpenMPDirectiveScope";
- Flags &= ~OpenMPDirectiveScope;
- } else if (Flags & OpenMPLoopDirectiveScope) {
- OS << "OpenMPLoopDirectiveScope";
- Flags &= ~OpenMPLoopDirectiveScope;
- } else if (Flags & OpenMPSimdDirectiveScope) {
- OS << "OpenMPSimdDirectiveScope";
- Flags &= ~OpenMPSimdDirectiveScope;
+ std::pair<unsigned, const char *> FlagInfo[] = {
+ {FnScope, "FnScope"},
+ {BreakScope, "BreakScope"},
+ {ContinueScope, "ContinueScope"},
+ {DeclScope, "DeclScope"},
+ {ControlScope, "ControlScope"},
+ {ClassScope, "ClassScope"},
+ {BlockScope, "BlockScope"},
+ {TemplateParamScope, "TemplateParamScope"},
+ {FunctionPrototypeScope, "FunctionPrototypeScope"},
+ {FunctionDeclarationScope, "FunctionDeclarationScope"},
+ {AtCatchScope, "AtCatchScope"},
+ {ObjCMethodScope, "ObjCMethodScope"},
+ {SwitchScope, "SwitchScope"},
+ {TryScope, "TryScope"},
+ {FnTryCatchScope, "FnTryCatchScope"},
+ {OpenMPDirectiveScope, "OpenMPDirectiveScope"},
+ {OpenMPLoopDirectiveScope, "OpenMPLoopDirectiveScope"},
+ {OpenMPSimdDirectiveScope, "OpenMPSimdDirectiveScope"},
+ {EnumScope, "EnumScope"},
+ {SEHTryScope, "SEHTryScope"},
+ {SEHExceptScope, "SEHExceptScope"},
+ {SEHFilterScope, "SEHFilterScope"},
+ {CompoundStmtScope, "CompoundStmtScope"},
+ {ClassInheritanceScope, "ClassInheritanceScope"}};
+
+ for (auto Info : FlagInfo) {
+ if (Flags & Info.first) {
+ OS << Info.second;
+ Flags &= ~Info.first;
+ if (Flags)
+ OS << " | ";
}
-
- if (Flags)
- OS << " | ";
}
+
+ assert(Flags == 0 && "Unknown scope flags");
+
if (HasFlags)
OS << '\n';