r322813 - Fix Scope::dump()

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 04:58:14 PST 2018


Thanks! r323109.

On Sat, Jan 20, 2018 at 12:53 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> Sounds like a good idea to me.
>
> On 19 Jan 2018 15:23, "Richard Trieu via cfe-commits"
> <cfe-commits at lists.llvm.org> wrote:
>>
>> Hans,
>>
>> I recommend merging this revision into the release.  It fixes an infinite
>> loop in Scope::dump()
>>
>> Richard
>>
>> On Wed, Jan 17, 2018 at 8:28 PM, Richard Trieu via cfe-commits
>> <cfe-commits at lists.llvm.org> wrote:
>>>
>>> Author: rtrieu
>>> Date: Wed Jan 17 20:28:56 2018
>>> New Revision: 322813
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=322813&view=rev
>>> Log:
>>> 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.
>>>
>>> Modified:
>>>     cfe/trunk/lib/Sema/Scope.cpp
>>>
>>> Modified: cfe/trunk/lib/Sema/Scope.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=322813&r1=322812&r2=322813&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/Scope.cpp (original)
>>> +++ cfe/trunk/lib/Sema/Scope.cpp Wed Jan 17 20:28:56 2018
>>> @@ -143,72 +143,43 @@ void Scope::dumpImpl(raw_ostream &OS) co
>>>    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"}};
>>>
>>> -    if (Flags)
>>> -      OS << " | ";
>>> +  for (auto Info : FlagInfo) {
>>> +    if (Flags & Info.first) {
>>> +      OS << Info.second;
>>> +      Flags &= ~Info.first;
>>> +      if (Flags)
>>> +        OS << " | ";
>>> +    }
>>>    }
>>> +
>>> +  assert(Flags == 0 && "Unknown scope flags");
>>> +
>>>    if (HasFlags)
>>>      OS << '\n';
>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>


More information about the cfe-commits mailing list