[llvm] r202188 - Debug info: Support variadic functions.
Adrian Prantl
aprantl at apple.com
Tue Feb 25 14:33:59 PST 2014
On Feb 25, 2014, at 13:54, Eric Christopher <echristo at gmail.com> wrote:
Thanks, Eric! I addressed everything unless explicitly stated in r202199.
On Tue, Feb 25, 2014 at 11:57 AM, Adrian Prantl <aprantl at apple.com> wrote:
>> Author: adrian
>> Date: Tue Feb 25 13:57:42 2014
>> New Revision: 202188
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=202188&view=rev
>> Log:
>> Debug info: Support variadic functions.
>> Variadic functions have an unspecified parameter tag after the last
>> argument. In IR this is represented as an unspecified parameter in the
>> subroutine type.
>>
>> Paired commit with CFE r202185.
>>
>> rdar://problem/13690847
>>
>> This re-applies r202184 + a bugfix in DwarfDebug's argument handling.
>
> Would be nice to have more description what the bugfix is here. What
> was the difference? Did you add more to the testcase or a comment in
> some place?
With the refactoring in the follow-up commit the fix more or less became obsolete. All three places now use the canonical (and correct) implementation in DwarfUnit::constructSubprogramArguments().
>
>>
>> - /// createUnspecifiedParameter - Create unspeicified type descriptor
>> + /// createUnspecifiedParameter - Create unspecified type descriptor
>> /// for a subroutine type.
>> DIDescriptor createUnspecifiedParameter();
>>
>
> Could have been committed separately - especially since it's in a file
> by itself.
>
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=202188&r1=202187&r2=202188&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Feb 25 13:57:42 2014
>> @@ -403,15 +403,21 @@ DIE *DwarfDebug::updateSubprogramScopeDI
>> DIArray Args = SPTy.getTypeArray();
>> uint16_t SPTag = SPTy.getTag();
>> if (SPTag == dwarf::DW_TAG_subroutine_type)
>> + // FIXME: Use DwarfUnit::constructSubprogramArguments() here.
>
> What's the problem here?
Code duplication in three places.
>
>> for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
>> - DIE *Arg =
>> - SPCU->createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie);
>> DIType ATy(Args.getElement(i));
>> - SPCU->addType(Arg, ATy);
>> - if (ATy.isArtificial())
>> - SPCU->addFlag(Arg, dwarf::DW_AT_artificial);
>> - if (ATy.isObjectPointer())
>> - SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, Arg);
>> + if (ATy.isUnspecifiedParameter()) {
>> + assert(i == N-1 && "ellipsis must be the last argument");
>
> Reword this to avoid the use of ellipsis. Use unspecified parameter or
> something IR specific.
> The next line is over 80-columns as well.
>
>> // Collect arguments for current function.
>> - if (LScopes.isCurrentFunctionScope(Scope))
>> + if (LScopes.isCurrentFunctionScope(Scope)) {
>> for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i)
>> if (DbgVariable *ArgDV = CurrentFnArguments[i])
>> if (DIE *Arg =
>> @@ -592,6 +598,16 @@ DIE *DwarfDebug::createScopeChildrenDIE(
>> ObjectPointer = Arg;
>> }
>>
>> + // Create the unspecified parameter that marks a function as variadic.
>
> Might want to move this comment inside the conditional, or make it
> sound conditional.
>
>> + DISubprogram SP(Scope->getScopeNode());
>> + assert(SP.Verify());
>
> If this assert fires then something is really really wrong :) You
> might want to add some text here if it fails.
>
>> + DIArray FnArgs = SP.getType().getTypeArray();
>> + if (FnArgs.getElement(FnArgs.getNumElements()-1).isUnspecifiedParameter()) {
>> + DIE *Ellipsis = new DIE(dwarf::DW_TAG_unspecified_parameters);
>> + Children.push_back(Ellipsis);
>> + }
>> + }
>> +
>
> This feels awkward here. Thoughts?
We have to insert it immediately after the formal parameters and before the variables. There does not seem to be a more appropriate place than this one.
>
>> +/// constructSubprogramArguments - Construct function argument DIEs.
>> +void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DIArray Args) {
>> + for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
>> + DIDescriptor Ty = Args.getElement(i);
>> + if (Ty.isUnspecifiedParameter()) {
>> + assert(i == N-1 && "ellipsis must be the last argument");
>
> Same comment as above about the text here.
>
>> // Add arguments. Do not add arguments for subprogram definition. They will
>> // be handled while processing variables.
>> - for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
>> - DIE *Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie);
>> - DIType ATy(Args.getElement(i));
>> - addType(Arg, ATy);
>> - if (ATy.isArtificial())
>> - addFlag(Arg, dwarf::DW_AT_artificial);
>> - }
>> + constructSubprogramArguments(*SPDie, Args);
>
> The comment here seems like it should go onto the function or change somewhat.
>
>> }
>>
>> if (SP.isArtificial())
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=202188&r1=202187&r2=202188&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Tue Feb 25 13:57:42 2014
>> @@ -476,6 +476,9 @@ protected:
>> DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
>>
>> private:
>> + /// constructSubprogramArguments - Construct function argument DIEs.
>> + void constructSubprogramArguments(DIE &Buffer, DIArray Args);
>> +
>
> This refactoring could have been done in a separate patch.
>
>> /// constructTypeDIE - Construct basic type die from DIBasicType.
>> void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
>>
>>
>> Added: llvm/trunk/test/DebugInfo/X86/varargs.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/varargs.ll?rev=202188&view=auto
>> ==============================================================================
>> --- llvm/trunk/test/DebugInfo/X86/varargs.ll (added)
>> +++ llvm/trunk/test/DebugInfo/X86/varargs.ll Tue Feb 25 13:57:42 2014
>> @@ -0,0 +1,90 @@
>> +; RUN: llc -O0 -filetype=obj -o %t.o %s
>> +; RUN: llvm-dwarfdump -debug-dump=info %t.o | FileCheck %s
>> +;
>> +; Normal variadic function.
>> +;
>> +; CHECK: DW_TAG_subprogram
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_formal_parameter
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_unspecified_parameters
>> +;
>> +; Variadic C++ member function.
>> +;
>> +; CHECK: DW_TAG_subprogram
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_formal_parameter
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_formal_parameter
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_unspecified_parameters
>> +;
>> +; Variadic function pointer.
>> +;
>> +; CHECK: DW_TAG_subroutine_type
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_formal_parameter
>> +; CHECK-NOT: DW_TAG
>> +; CHECK: DW_TAG_unspecified_parameters
>
> Please add more details (CHECK lines with names perhaps?) to what
> you're testing here and comments. The check and check-not lines are
> inscrutable. Also is there any reason that this is X86 only? You don't
> appear to be checking addresses or sizes.
>
> -eric
More information about the llvm-commits
mailing list