r183597 - Debug info: An if condition now creates a lexical scope of its own.

Eric Christopher echristo at gmail.com
Mon Jun 10 16:05:28 PDT 2013


On Mon, Jun 10, 2013 at 3:56 PM, Adrian Prantl <aprantl at apple.com> wrote:
> (CC’ing John because he understands the intricacies of LexicalScope better than I do)
>
> On the first glimpse LexicalScope appears to be a subclass of RunCleanupsScope that additionally emits a (DebugInfo-)LexicalScope. But looking at the destructors it appears that they have slightly different semantics: ~LexicalScope runs ForceCleanup and ~RunCleanupsScope apparently doesn’t.
>
> I’m wary that switching to Lexicalscope in CodeGenFunction::EmitIfStmt() might lead to tricky ARC or EH-related problems because of that.
>
> Does anyone have an opinion on that?

That bit was added here:

commit 495cfa46300979642acde8d93a1f21c9291dac98
Author: Nadav Rotem <nrotem at apple.com>
Date:   Sat Mar 23 06:43:35 2013 +0000

    Make clang to mark static stack allocations with lifetime markers
to enable a more aggressive stack coloring.
    Patch by John McCall with help by Shuxin Yang.
    rdar://13115369


and oddly not to RunCleanupsScope.

Nadav?

-eric


> -- adrian
>
> On Jun 10, 2013, at 10:47 AM, Eric Christopher <echristo at gmail.com> wrote:
>
>
>> I think you can just use a LexicalScope here instead of the patch
>> you've got. I.e. the attached patch passes all of the tests you added
>> - I just did the quick manual replacement without thinking about the
>> else or then blocks, but figured you might want to run this on your
>> original test?
>>
>> -eric
>>
>>
>>
>> On Fri, Jun 7, 2013 at 5:16 PM, Adrian Prantl <aprantl at apple.com> wrote:
>>> Author: adrian
>>> Date: Fri Jun  7 19:16:55 2013
>>> New Revision: 183597
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=183597&view=rev
>>> Log:
>>> Debug info: An if condition now creates a lexical scope of its own.
>>> Two variables with the same name declared in two if conditions in the same
>>> scope are no longer coalesced into one.
>>>
>>> rdar://problem/14024005
>>>
>>> Added:
>>>    cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp
>>> Modified:
>>>    cfe/trunk/lib/CodeGen/CGStmt.cpp
>>>    cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
>>>
>>> Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=183597&r1=183596&r2=183597&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
>>> +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Jun  7 19:16:55 2013
>>> @@ -419,6 +419,11 @@ void CodeGenFunction::EmitIfStmt(const I
>>>   // unequal to 0.  The condition must be a scalar type.
>>>   RunCleanupsScope ConditionScope(*this);
>>>
>>> +  // Also open a debugger-visible lexical scope for the condition.
>>> +  CGDebugInfo *DI = getDebugInfo();
>>> +  if (DI)
>>> +    DI->EmitLexicalBlockStart(Builder, S.getSourceRange().getBegin());
>>> +
>>>   if (S.getConditionVariable())
>>>     EmitAutoVarDecl(*S.getConditionVariable());
>>>
>>> @@ -439,6 +444,8 @@ void CodeGenFunction::EmitIfStmt(const I
>>>         RunCleanupsScope ExecutedScope(*this);
>>>         EmitStmt(Executed);
>>>       }
>>> +      if (DI)
>>> +        DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
>>>       return;
>>>     }
>>>   }
>>> @@ -476,6 +483,9 @@ void CodeGenFunction::EmitIfStmt(const I
>>>     EmitBranch(ContBlock);
>>>   }
>>>
>>> +  if (DI)
>>> +    DI->EmitLexicalBlockEnd(Builder, S.getSourceRange().getEnd());
>>> +
>>>   // Emit the continuation block for code after the if.
>>>   EmitBlock(ContBlock, true);
>>> }
>>>
>>> Modified: cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp?rev=183597&r1=183596&r2=183597&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/debug-info-namespace.cpp Fri Jun  7 19:16:55 2013
>>> @@ -50,8 +50,9 @@ int func(bool b) {
>>> // CHECK: [[M1]] = metadata !{i32 {{[0-9]*}}, metadata [[CTXT]], metadata [[NS]], i32 9} ; [ DW_TAG_imported_module ]
>>> // CHECK: [[M2]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 12} ; [ DW_TAG_imported_module ]
>>> // CHECK: [[M3]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 13, metadata !"E"} ; [ DW_TAG_imported_module ]
>>> -// CHECK: [[M4]] = metadata !{i32 {{[0-9]*}}, metadata [[LEX:![0-9]*]], metadata [[NS]], i32 17} ; [ DW_TAG_imported_module ]
>>> -// CHECK: [[LEX]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[FUNC]], i32 16, i32 0, i32 0} ; [ DW_TAG_lexical_block ]
>>> +// CHECK: [[M4]] = metadata !{i32 {{[0-9]*}}, metadata [[LEX2:![0-9]*]], metadata [[NS]], i32 17} ; [ DW_TAG_imported_module ]
>>> +// CHECK: [[LEX2]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[LEX1:![0-9]+]], i32 16, i32 0, i32 {{.*}}} ; [ DW_TAG_lexical_block ]
>>> +// CHECK: [[LEX1]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[FUNC]], i32 16, i32 0, i32 {{.*}}} ; [ DW_TAG_lexical_block ]
>>> // CHECK: [[M5]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[CTXT]], i32 20} ; [ DW_TAG_imported_module ]
>>> // CHECK: [[M6]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[FOO:![0-9]*]], i32 21} ; [ DW_TAG_imported_declaration ]
>>> // CHECK: [[FOO]] {{.*}} ; [ DW_TAG_structure_type ] [foo] [line 5, size 0, align 0, offset 0] [fwd] [from ]
>>>
>>> Added: cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp?rev=183597&view=auto
>>> ==============================================================================
>>> --- cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp (added)
>>> +++ cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp Fri Jun  7 19:16:55 2013
>>> @@ -0,0 +1,32 @@
>>> +// RUN: %clang_cc1 -g -emit-llvm %s -o -| FileCheck %s
>>> +//
>>> +// Two variables with the same name in subsequent if staments need to be in separate scopes.
>>> +//
>>> +// rdar://problem/14024005
>>> +//
>>> +
>>> +int printf(const char*, ...);
>>> +
>>> +char *return_char (int input)
>>> +{
>>> +  if (input%2 == 0)
>>> +    return "I am even.\n";
>>> +  else
>>> +    return "I am odd.\n";
>>> +}
>>> +
>>> +int main2() {
>>> +// CHECK: [ DW_TAG_auto_variable ] [ptr] [line [[@LINE+2]]]
>>> +// CHECK metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ]
>>> +  if (char *ptr = return_char(1)) {
>>> +    printf ("%s", ptr);
>>> +  }
>>> +// CHECK: [ DW_TAG_auto_variable ] [ptr] [line [[@LINE+2]]]
>>> +// CHECK metadata !{i32 {{.*}}, metadata !{{.*}}, i32 [[@LINE+1]], {{.*}}} ; [ DW_TAG_lexical_block ]
>>> +  if (char *ptr = return_char(2)) {
>>> +    printf ("%s", ptr);
>>> +  }
>>> +  else printf ("%s", ptr);
>>> +
>>> +  return 0;
>>> +}
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> <z.diff.txt>
>
>




More information about the cfe-commits mailing list