[PATCH] DebugInfo: hoist definition into global context when needed

David Blaikie dblaikie at gmail.com
Fri Feb 27 13:15:53 PST 2015


Looks great, please commit.

Thanks!

- David

On Fri, Feb 27, 2015 at 12:24 PM, Saleem Abdulrasool <compnerd at compnerd.org>
wrote:

> Address comments from David Blakie.
>
>
> http://reviews.llvm.org/D7872
>
> Files:
>   lib/CodeGen/CGDebugInfo.cpp
>   test/CodeGenCXX/inline-dllexport-member.cpp
>
> Index: lib/CodeGen/CGDebugInfo.cpp
> ===================================================================
> --- lib/CodeGen/CGDebugInfo.cpp
> +++ lib/CodeGen/CGDebugInfo.cpp
> @@ -2376,9 +2376,17 @@
>    // FIXME: Generalize this for even non-member global variables where the
>    // declaration and definition may have different lexical decl contexts,
> once
>    // we have support for emitting declarations of (non-member) global
> variables.
> -  VDContext = getContextDescriptor(
> -      dyn_cast<Decl>(VD->isStaticDataMember() ?
> VD->getLexicalDeclContext()
> -                                              : VD->getDeclContext()));
> +  const DeclContext *DC = VD->isStaticDataMember() ?
> VD->getLexicalDeclContext()
> +                                                   : VD->getDeclContext();
> +  // When a record type contains an in-line initialization of a static
> data
> +  // member, and the record type is marked as __declspec(dllexport), an
> implicit
> +  // definition of the member will be created in the record context.
> DWARF
> +  // doesn't seem to have a nice way to describe this in a form that
> consumers
> +  // are likely to understand, so fake the "normal" situation of a
> definition
> +  // outside the class by putting it in the global scope.
> +  if (DC->isRecord())
> +    DC = CGM.getContext().getTranslationUnitDecl();
> +  VDContext = getContextDescriptor(dyn_cast<Decl>(DC));
>  }
>
>  llvm::DISubprogram
> @@ -3171,6 +3179,7 @@
>  CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl
> *D) {
>    if (!D->isStaticDataMember())
>      return llvm::DIDerivedType();
> +
>    auto MI = StaticDataMemberCache.find(D->getCanonicalDecl());
>    if (MI != StaticDataMemberCache.end()) {
>      assert(MI->second && "Static data member declaration should still
> exist");
> Index: test/CodeGenCXX/inline-dllexport-member.cpp
> ===================================================================
> --- /dev/null
> +++ test/CodeGenCXX/inline-dllexport-member.cpp
> @@ -0,0 +1,10 @@
> +// RUN: %clang_cc1 -triple i686-windows-gnu -fms-compatibility -g
> -emit-llvm %s -o - \
> +// RUN:    | FileCheck %s
> +
> +struct __declspec(dllexport) s {
> +  static const unsigned int ui = 0;
> +};
> +
> +// CHECK: , [[SCOPE:![^,]*]], {{.*}}, i32* @_ZN1s2uiE, {{.*}}} ; [
> DW_TAG_variable ] [ui] [line 5] [def]
> +// CHECK: [[SCOPE]] = {{.*}} ; [ DW_TAG_file_type ]
> +
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150227/899f0213/attachment.html>


More information about the cfe-commits mailing list