r275040 - [CodeGen] Treat imported static local variables as declarations

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 14 11:21:18 PDT 2016


On Tue, Jul 12, 2016 at 3:51 PM David Majnemer via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> On Tue, Jul 12, 2016 at 2:55 PM, Robinson, Paul <paul.robinson at sony.com>
> wrote:
>
>> A declaration that gets used within the CU generally does get a
>> debug-info description.
>>
>
> It does except if it is a static data member:
> $ cat t.cpp
> struct S {
>   static int i;
> };
> int &gv = &S::i;
> $ ~/llvm/Debug+Asserts/bin/clang t.cpp -target x86_64-gnu-linux -g -S
> -emit-llvm -o -
> ; ModuleID = 't.cpp'
> source_filename = "t.cpp"
> target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> target triple = "x86_64--linux-gnu"
>
> @_ZN1S1iE = external global i32, align 4
> @gv = global i32* @_ZN1S1iE, align 8
>
> !llvm.dbg.cu = !{!0}
> !llvm.module.flags = !{!7, !8}
> !llvm.ident = !{!9}
>
> !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1,
> producer: "clang version 3.9.0 (trunk 275169) (llvm/trunk 275188)",
> isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2,
> globals: !3)
> !1 = !DIFile(filename: "t.cpp", directory:
> "/usr/local/google/home/majnemer")
> !2 = !{}
> !3 = !{!4}
> !4 = distinct !DIGlobalVariable(name: "gv", scope: !0, file: !1, line: 4,
> type: !5, isLocal: false, isDefinition: true, variable: i32** @gv)
> !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64,
> align: 64)
> !6 = !DIBasicType(name: "int", size: 32, align: 32, encoding:
> DW_ATE_signed)
> !7 = !{i32 2, !"Dwarf Version", i32 4}
> !8 = !{i32 2, !"Debug Info Version", i32 3}
> !9 = !{!"clang version 3.9.0 (trunk 275169) (llvm/trunk 275188)"}
>
> Note that there is no DIGlobalVariable for S::i.  I agree that this is not
> great behavior.  I merely changed a dllimport'd template instantiation of a
> static data member to behave the same way, poor, way a declaration is
> treated.
>

Yep, in theory (if anyone's interested) we could add such types to the
retained types list (that's what it's there for - when a type not
referenced from the debug info graph (variables, parameters, etc) is still
used).

I'm not too fussed by this. Mostly it's going to hit traits classes (that
don't have other members) that are careful to have no odr uses, so they
don't have a real definition anywhere. (or uses of -fstandalone-debug,
where the TU containing the definition is compiled without debug info, etc)

- Dave


>
>
>> I think no DWARF-using target has dllimport (yet) so you are actually
>> handling a new situation here.  Being unable to find the entity in the
>> dllimport-using CU is not a friendly debugging experience.
>>
>> --paulr
>>
>>
>>
>> *From:* David Majnemer [mailto:david.majnemer at gmail.com]
>> *Sent:* Tuesday, July 12, 2016 2:07 PM
>>
>> *To:* Robinson, Paul
>> *Cc:* cfe-commits (cfe-commits at lists.llvm.org)
>> *Subject:* Re: r275040 - [CodeGen] Treat imported static local variables
>> as declarations
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Jul 12, 2016 at 2:02 PM, Robinson, Paul <paul.robinson at sony.com>
>> wrote:
>>
>> I was asking for the debug info to describe the entity as a declaration,
>> rather than a definition.
>>
>> Instead you eliminated the debug-info description entirely.  These are
>> pretty different things.
>>
>>
>>
>> I treated the dllimported entity the same way we currently treat
>> declarations: ignore them.
>>
>> I don't have the bandwidth to generically improve debug info beyond what
>> we can do for DWARF/GDB targets.
>>
>>
>>
>> --paulr
>>
>>
>>
>> *From:* David Majnemer [mailto:david.majnemer at gmail.com]
>> *Sent:* Monday, July 11, 2016 12:27 PM
>>
>>
>> *To:* Robinson, Paul
>> *Cc:* cfe-commits (cfe-commits at lists.llvm.org)
>> *Subject:* Re: r275040 - [CodeGen] Treat imported static local variables
>> as declarations
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Jul 11, 2016 at 11:45 AM, Robinson, Paul <paul.robinson at sony.com>
>> wrote:
>>
>> It was not particularly obvious that by "static local variables" you
>> actually meant "template static data members."
>>
>> Now I can tell that this is not addressing what I was asking about in the
>> comment on r274986.
>>
>>
>>
>> I'm not sure I understand.  How is this not addressing what you are
>> asking for?  We will no longer emit a DIGlobalVariable for the imported
>> static data member.
>>
>>
>>
>> --paulr
>>
>>
>>
>> *From:* David Majnemer [mailto:david.majnemer at gmail.com]
>> *Sent:* Monday, July 11, 2016 9:53 AM
>> *To:* Robinson, Paul
>> *Cc:* cfe-commits (cfe-commits at lists.llvm.org)
>> *Subject:* Re: r275040 - [CodeGen] Treat imported static local variables
>> as declarations
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Jul 11, 2016 at 9:48 AM, Robinson, Paul <paul.robinson at sony.com>
>> wrote:
>>
>> This changes the IR but not the debug-info metadata?
>> --paulr
>>
>>
>>
>> The net effect is that the debug-info metadata is not generated for such
>> static members.
>>
>>
>>
>>
>> > -----Original Message-----
>> > From: cfe-commits [mailto:cfe-commits-bounces at lists.llvm.org] On
>> Behalf Of
>> > David Majnemer via cfe-commits
>> > Sent: Sunday, July 10, 2016 9:28 PM
>> > To: cfe-commits at lists.llvm.org
>> > Subject: r275040 - [CodeGen] Treat imported static local variables as
>> > declarations
>> >
>> > Author: majnemer
>> > Date: Sun Jul 10 23:28:21 2016
>> > New Revision: 275040
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=275040&view=rev
>> > Log:
>> > [CodeGen] Treat imported static local variables as declarations
>> >
>> > Imported variables cannot really be definitions for the purposes of
>> > IR generation.
>> >
>> > Modified:
>> >     cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
>> >     cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>> >     cfe/trunk/test/CodeGenCXX/dllimport.cpp
>> >
>> > Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
>> > URL: http://llvm.org/viewvc/llvm-
>> >
>> project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=275040&r1=275039&r2=275040
>> > &view=diff
>> >
>> ==========================================================================
>> > ====
>> > --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
>> > +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Sun Jul 10 23:28:21 2016
>> > @@ -323,10 +323,6 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
>> >         D->hasAttr<CUDASharedAttr>()))
>> >      return;
>> >
>> > -  // DLL imported variables will be initialized by the export side.
>> > -  if (D->hasAttr<DLLImportAttr>())
>> > -    return;
>> > -
>> >    // Check if we've already initialized this decl.
>> >    auto I = DelayedCXXInitPosition.find(D);
>> >    if (I != DelayedCXXInitPosition.end() && I->second == ~0U)
>> >
>> > Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>> > URL: http://llvm.org/viewvc/llvm-
>> >
>> project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=275040&r1=275039&r2=27
>> > 5040&view=diff
>> >
>> ==========================================================================
>> > ====
>> > --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
>> > +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Jul 10 23:28:21 2016
>> > @@ -2851,6 +2851,10 @@ static void ReplaceUsesOfNonProtoTypeWit
>> >  }
>> >
>> >  void CodeGenModule::HandleCXXStaticMemberVarInstantiation(VarDecl *VD)
>> {
>> > +  auto DK = VD->isThisDeclarationADefinition();
>> > +  if (DK == VarDecl::Definition && VD->hasAttr<DLLImportAttr>())
>> > +    return;
>> > +
>> >    TemplateSpecializationKind TSK = VD->getTemplateSpecializationKind();
>> >    // If we have a definition, this might be a deferred decl. If the
>> >    // instantiation is explicit, make sure we emit it at the end.
>> >
>> > Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
>> > URL: http://llvm.org/viewvc/llvm-
>> >
>> project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=275040&r1=275039&r2=27
>> > 5040&view=diff
>> >
>> ==========================================================================
>> > ====
>> > --- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
>> > +++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Sun Jul 10 23:28:21 2016
>> > @@ -676,7 +676,7 @@ namespace ClassTemplateStaticDef {
>> >      static int x;
>> >    };
>> >    template <typename T> int S<T>::x;
>> > -  // MSC-DAG: @"\01?x@?$S at H@ClassTemplateStaticDef@@2HA" =
>> > available_externally dllimport global i32 0
>> > +  // MSC-DAG: @"\01?x@?$S at H@ClassTemplateStaticDef@@2HA" = external
>> > dllimport global i32
>> >    int f() { return S<int>::x; }
>> >
>> >    // Partial class template specialization static field:
>> > @@ -685,7 +685,7 @@ namespace ClassTemplateStaticDef {
>> >      static int x;
>> >    };
>> >    template <typename A> int T<A*>::x;
>> > -  // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE =
>> > available_externally dllimport global i32 0
>> > +  // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = external
>> dllimport
>> > global i32
>> >    int g() { return T<void*>::x; }
>> >  }
>> >
>> >
>> >
>> > _______________________________________________
>> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160714/c96dd813/attachment-0001.html>


More information about the cfe-commits mailing list